diff --git a/modules/save-and-load.js b/modules/save-and-load.js index a70ad617..b6c4f9ce 100644 --- a/modules/save-and-load.js +++ b/modules/save-and-load.js @@ -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"); @@ -332,11 +369,11 @@ function getMapData() { const dateString = date.getFullYear() + "-" + (date.getMonth() + 1) + "-" + date.getDate(); const license = "File can be loaded in azgaar.github.io/Fantasy-Map-Generator"; 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, - barSize.value, barLabel.value, barBackOpacity.value, barBackColor.value, + barSize.value, barLabel.value, barBackOpacity.value, barBackColor.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), mapName.value].join("|"); const coords = JSON.stringify(mapCoordinates); @@ -410,6 +447,7 @@ function saveGeoJSON() { Cells: saveGeoJSON_Cells, Routes: saveGeoJSON_Roads, Rivers: saveGeoJSON_Rivers, + Markers: saveGeoJSON_Markers, Close: function() {$(this).dialog("close");} } }); @@ -992,4 +1030,4 @@ function parseLoadedData(data) { }); } -} \ No newline at end of file +}