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
|
// download map data as GeoJSON
|
||||||
function saveGeoJSON() {
|
function saveGeoJSON() {
|
||||||
|
/*
|
||||||
saveGeoJSON_Cells();
|
saveGeoJSON_Cells();
|
||||||
saveGeoJSON_Roads();
|
saveGeoJSON_Roads();
|
||||||
saveGeoJSON_Rivers();
|
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() {
|
function saveGeoJSON_Roads() {
|
||||||
// this is work-in-progress
|
|
||||||
roads = routes.select("#roads");
|
roads = routes.select("#roads");
|
||||||
trails = routes.select("#trails");
|
trails = routes.select("#trails");
|
||||||
searoutes = routes.select("#searoutes");
|
searoutes = routes.select("#searoutes");
|
||||||
|
|
@ -332,11 +369,11 @@ function getMapData() {
|
||||||
const dateString = date.getFullYear() + "-" + (date.getMonth() + 1) + "-" + date.getDate();
|
const dateString = date.getFullYear() + "-" + (date.getMonth() + 1) + "-" + date.getDate();
|
||||||
const license = "File can be loaded in azgaar.github.io/Fantasy-Map-Generator";
|
const license = "File can be loaded in azgaar.github.io/Fantasy-Map-Generator";
|
||||||
const params = [version, license, dateString, seed, graphWidth, graphHeight].join("|");
|
const params = [version, license, dateString, seed, graphWidth, graphHeight].join("|");
|
||||||
const options = [distanceUnitInput.value, distanceScaleInput.value, areaUnit.value,
|
const options = [distanceUnitInput.value, distanceScaleInput.value, areaUnit.value,
|
||||||
heightUnit.value, heightExponentInput.value, temperatureScale.value,
|
heightUnit.value, heightExponentInput.value, temperatureScale.value,
|
||||||
barSize.value, barLabel.value, barBackOpacity.value, barBackColor.value,
|
barSize.value, barLabel.value, barBackOpacity.value, barBackColor.value,
|
||||||
barPosX.value, barPosY.value, populationRate.value, urbanization.value,
|
barPosX.value, barPosY.value, populationRate.value, urbanization.value,
|
||||||
mapSizeOutput.value, latitudeOutput.value, temperatureEquatorOutput.value,
|
mapSizeOutput.value, latitudeOutput.value, temperatureEquatorOutput.value,
|
||||||
temperaturePoleOutput.value, precOutput.value, JSON.stringify(winds),
|
temperaturePoleOutput.value, precOutput.value, JSON.stringify(winds),
|
||||||
mapName.value].join("|");
|
mapName.value].join("|");
|
||||||
const coords = JSON.stringify(mapCoordinates);
|
const coords = JSON.stringify(mapCoordinates);
|
||||||
|
|
@ -410,6 +447,7 @@ function saveGeoJSON() {
|
||||||
Cells: saveGeoJSON_Cells,
|
Cells: saveGeoJSON_Cells,
|
||||||
Routes: saveGeoJSON_Roads,
|
Routes: saveGeoJSON_Roads,
|
||||||
Rivers: saveGeoJSON_Rivers,
|
Rivers: saveGeoJSON_Rivers,
|
||||||
|
Markers: saveGeoJSON_Markers,
|
||||||
Close: function() {$(this).dialog("close");}
|
Close: function() {$(this).dialog("close");}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
@ -992,4 +1030,4 @@ function parseLoadedData(data) {
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue