mirror of
https://github.com/Azgaar/Fantasy-Map-Generator.git
synced 2025-12-21 19:41:23 +01:00
added GeoJSON export for markers (POIs)
This commit is contained in:
parent
0dc7d622ce
commit
9bdc8a3094
1 changed files with 43 additions and 5 deletions
|
|
@ -3,13 +3,50 @@
|
|||
|
||||
// download map data as GeoJSON
|
||||
function saveGeoJSON() {
|
||||
/*
|
||||
saveGeoJSON_Cells();
|
||||
saveGeoJSON_Roads();
|
||||
saveGeoJSON_Rivers();
|
||||
*/
|
||||
saveGeoJSON_Markers();
|
||||
}
|
||||
|
||||
function saveGeoJSON_Markers() {
|
||||
|
||||
let data = "{ \"type\": \"FeatureCollection\", \"features\": [\n";
|
||||
|
||||
markers._groups[0][0].childNodes.forEach(n => {
|
||||
console.log(n);
|
||||
console.log("id = "+n.id);
|
||||
console.log("type = "+n.dataset.id.substring(8));
|
||||
console.log("x = "+n.dataset.x);
|
||||
console.log("y = "+n.dataset.y);
|
||||
|
||||
let x = mapCoordinates.lonW + (n.dataset.x / graphWidth) * mapCoordinates.lonT;
|
||||
let y = mapCoordinates.latN - (n.dataset.y / graphHeight) * mapCoordinates.latT; // this is inverted in QGIS otherwise
|
||||
|
||||
data += "{\n \"type\": \"Feature\",\n \"geometry\": { \"type\": \"Point\", \"coordinates\": ["+x+", "+y+"]";
|
||||
data += " },\n \"properties\": {\n";
|
||||
data += " \"id\": \""+n.id+"\",\n";
|
||||
data += " \"type\": \""+n.dataset.id.substring(8)+"\"\n";
|
||||
data +=" }\n},\n";
|
||||
|
||||
});
|
||||
data = data.substring(0, data.length - 2)+"\n"; // remove trailing comma
|
||||
data += "]}";
|
||||
|
||||
const dataBlob = new Blob([data], {type: "application/json"});
|
||||
const url = window.URL.createObjectURL(dataBlob);
|
||||
const link = document.createElement("a");
|
||||
document.body.appendChild(link);
|
||||
link.download = "fmg_markers_" + Date.now() + ".geojson";
|
||||
link.href = url;
|
||||
link.click();
|
||||
window.setTimeout(function() {window.URL.revokeObjectURL(url);}, 2000);
|
||||
}
|
||||
|
||||
|
||||
function saveGeoJSON_Roads() {
|
||||
// this is work-in-progress
|
||||
roads = routes.select("#roads");
|
||||
trails = routes.select("#trails");
|
||||
searoutes = routes.select("#searoutes");
|
||||
|
|
@ -410,6 +447,7 @@ function saveGeoJSON() {
|
|||
Cells: saveGeoJSON_Cells,
|
||||
Routes: saveGeoJSON_Roads,
|
||||
Rivers: saveGeoJSON_Rivers,
|
||||
Markers: saveGeoJSON_Markers,
|
||||
Close: function() {$(this).dialog("close");}
|
||||
}
|
||||
});
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue