mirror of
https://github.com/Azgaar/Fantasy-Map-Generator.git
synced 2025-12-22 03:51:23 +01:00
improved export, now everything working!
This commit is contained in:
parent
629b6d7c7c
commit
9cd63b6fec
2 changed files with 38 additions and 24 deletions
|
|
@ -76,6 +76,6 @@ for ($i=0; $i<$iterations; $i++) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
echo json_encode($cells);
|
echo json_encode($cells, JSON_PRETTY_PRINT);
|
||||||
|
|
||||||
?>
|
?>
|
||||||
|
|
|
||||||
|
|
@ -3,9 +3,9 @@
|
||||||
|
|
||||||
// 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();
|
||||||
}
|
}
|
||||||
|
|
||||||
function saveGeoJSON_Roads() {
|
function saveGeoJSON_Roads() {
|
||||||
|
|
@ -14,30 +14,30 @@ function saveGeoJSON_Roads() {
|
||||||
trails = routes.select("#trails");
|
trails = routes.select("#trails");
|
||||||
searoutes = routes.select("#searoutes");
|
searoutes = routes.select("#searoutes");
|
||||||
|
|
||||||
console.log(rivers._groups[0][0].childNodes);
|
|
||||||
|
|
||||||
console.log(typeof(roads));
|
|
||||||
console.log(roads);
|
|
||||||
|
|
||||||
console.log(routes._groups);
|
|
||||||
console.log(routes._groups[0]);
|
|
||||||
console.log(routes._groups[0][0]);
|
|
||||||
console.log(routes._groups[0][0].childNodes);
|
|
||||||
|
|
||||||
|
|
||||||
let data = "{ \"type\": \"FeatureCollection\", \"features\": [\n";
|
let data = "{ \"type\": \"FeatureCollection\", \"features\": [\n";
|
||||||
let id = 0;
|
|
||||||
|
|
||||||
// roads
|
|
||||||
routes._groups[0][0].childNodes.forEach(n => {
|
routes._groups[0][0].childNodes.forEach(n => {
|
||||||
id++;
|
//console.log(n.id);
|
||||||
n.forEach(x => {
|
n.childNodes.forEach(r => {
|
||||||
console.log(x);
|
data += "{\n \"type\": \"Feature\",\n \"geometry\": { \"type\": \"LineString\", \"coordinates\": ";
|
||||||
|
data += JSON.stringify(getRoadPoints(r));
|
||||||
|
data += " },\n \"properties\": {\n";
|
||||||
|
data += " \"id\": \""+r.id+"\",\n";
|
||||||
|
data += " \"type\": \""+n.id+"\"\n";
|
||||||
|
data +=" }\n},\n";
|
||||||
});
|
});
|
||||||
data += JSON.stringify(getRiverPoints(n));
|
|
||||||
|
|
||||||
});
|
});
|
||||||
console.log(data);
|
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_routes_" + Date.now() + ".geojson";
|
||||||
|
link.href = url;
|
||||||
|
link.click();
|
||||||
|
window.setTimeout(function() {window.URL.revokeObjectURL(url);}, 2000);
|
||||||
}
|
}
|
||||||
|
|
||||||
function saveGeoJSON_Rivers() {
|
function saveGeoJSON_Rivers() {
|
||||||
|
|
@ -65,7 +65,22 @@ function saveGeoJSON_Rivers() {
|
||||||
window.setTimeout(function() {window.URL.revokeObjectURL(url);}, 2000);
|
window.setTimeout(function() {window.URL.revokeObjectURL(url);}, 2000);
|
||||||
}
|
}
|
||||||
|
|
||||||
function getRiverPoints(node) {
|
function getRoadPoints(node) {
|
||||||
|
let points = [];
|
||||||
|
const l = node.getTotalLength();
|
||||||
|
const increment = l / Math.ceil(l / 2);
|
||||||
|
for (let i=0; i <= l; i += increment) {
|
||||||
|
const p = node.getPointAtLength(i);
|
||||||
|
|
||||||
|
let x = mapCoordinates.lonW + (p.x / graphWidth) * mapCoordinates.lonT;
|
||||||
|
let y = mapCoordinates.latN - (p.y / graphHeight) * mapCoordinates.latT; // this is inverted in QGIS otherwise
|
||||||
|
|
||||||
|
points.push([x,y]);
|
||||||
|
}
|
||||||
|
return points;
|
||||||
|
}
|
||||||
|
|
||||||
|
function getPathPoints(node, increment) {
|
||||||
let points = [];
|
let points = [];
|
||||||
const l = node.getTotalLength() / 2; // half-length
|
const l = node.getTotalLength() / 2; // half-length
|
||||||
const increment = 0.25; // defines density of points
|
const increment = 0.25; // defines density of points
|
||||||
|
|
@ -82,7 +97,6 @@ function getRiverPoints(node) {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
function saveGeoJSON_Cells() {
|
function saveGeoJSON_Cells() {
|
||||||
let data = "{ \"type\": \"FeatureCollection\", \"features\": [\n";
|
let data = "{ \"type\": \"FeatureCollection\", \"features\": [\n";
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue