From 93b6b60f0c73c38d052e764042dd0e53c1bc08f5 Mon Sep 17 00:00:00 2001 From: Tom Date: Tue, 17 Sep 2019 09:25:49 +0200 Subject: [PATCH] export of marker data (#305) * export of marker data fixed elevation in burgs and cells export fixed population in cells export * exporting type (island, lake, etc.) as well now * bugfix in burgs export --- modules/save-and-load.js | 42 ++++++++++++++++++++++++++++++++------ modules/ui/burgs-editor.js | 8 ++++---- 2 files changed, 40 insertions(+), 10 deletions(-) diff --git a/modules/save-and-load.js b/modules/save-and-load.js index a7d0f4f6..6c4741f3 100644 --- a/modules/save-and-load.js +++ b/modules/save-and-load.js @@ -162,11 +162,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); @@ -240,6 +240,7 @@ function saveGeoJSON() { Cells: saveGeoJSON_Cells, Routes: saveGeoJSON_Roads, Rivers: saveGeoJSON_Rivers, + Markers: saveGeoJSON_Markers, Close: function() {$(this).dialog("close");} } }); @@ -430,12 +431,13 @@ function saveGeoJSON_Cells() { data += "["+x+","+y+"]"; data += "]] },\n \"properties\": {\n"; - let height = parseInt(getFriendlyHeight(cells.h[i])); + let height = parseInt(getFriendlyHeight([cells.p[i][0],cells.p[i][1]])); data += " \"id\": \""+i+"\",\n"; data += " \"height\": \""+height+"\",\n"; data += " \"biome\": \""+cells.biome[i]+"\",\n"; - data += " \"population\": \""+cells.pop[i]+"\",\n"; + data += " \"type\": \""+pack.features[cells.f[i]].type+"\",\n"; + data += " \"population\": \""+getFriendlyPopulation(i)+"\",\n"; data += " \"state\": \""+cells.state[i]+"\",\n"; data += " \"province\": \""+cells.province[i]+"\",\n"; data += " \"culture\": \""+cells.culture[i]+"\",\n"; @@ -456,6 +458,34 @@ function saveGeoJSON_Cells() { window.setTimeout(function() {window.URL.revokeObjectURL(url);}, 2000); } +function saveGeoJSON_Markers() { + + let data = "{ \"type\": \"FeatureCollection\", \"features\": [\n"; + + markers._groups[0][0].childNodes.forEach(n => { + 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 = getFileName("Markers") + ".geojson"; + link.href = url; + link.click(); + window.setTimeout(function() {window.URL.revokeObjectURL(url);}, 2000); +} + function uploadFile(file, callback) { uploadFile.timeStart = performance.now(); @@ -822,4 +852,4 @@ function parseLoadedData(data) { }); } -} \ No newline at end of file +} diff --git a/modules/ui/burgs-editor.js b/modules/ui/burgs-editor.js index 22c3bf37..e23a69a5 100644 --- a/modules/ui/burgs-editor.js +++ b/modules/ui/burgs-editor.js @@ -259,7 +259,7 @@ function editBurgs() { data += b.name + ","; const province = pack.cells.province[b.cell]; data += province ? pack.provinces[province].fullName + "," : ","; - data += b.state ? pack.states[b.state].fullName : pack.states[b.state].name + ","; + data += b.state ? pack.states[b.state].fullName +"," : pack.states[b.state].name + ","; data += pack.cultures[b.culture].name + ","; data += pack.religions[pack.cells.religion[b.cell]].name + ","; data += rn(b.population * populationRate.value * urbanization.value) + ","; @@ -267,11 +267,11 @@ function editBurgs() { // add geography data data += mapCoordinates.lonW + (b.x / graphWidth) * mapCoordinates.lonT + ","; data += mapCoordinates.latN - (b.y / graphHeight) * mapCoordinates.latT + ","; // this is inverted in QGIS otherwise - data += parseInt(getHeight(pack.cells.h[b.cell])) + ","; + data += parseInt(getFriendlyHeight([b.x,b.y])) + ","; // add status data - data += b.capital ? "capital," : ","; - data += b.port ? "port\n" : "\n"; + data += b.capital ? "true," : "false,"; + data += b.port ? "true\n" : "false\n"; }); const dataBlob = new Blob([data], {type: "text/plain"});