Compare commits

..

4 Commits

Author SHA1 Message Date
c10f229f49 Remove debug print 2020-04-18 12:35:49 +02:00
6284c9d8b4 Center markers etc. on block
Before, markers were set to the bottom left corner of a block.
Now, it is nicely centered even on high zoom levels.
2020-04-18 12:35:36 +02:00
828e1edf28 Add streets Geojson 2020-04-17 22:00:50 +02:00
3d0e8ae95d Fail Geojson load silently 2020-04-17 22:00:36 +02:00
2 changed files with 27 additions and 3 deletions

View File

@ -83,6 +83,29 @@ function load_svg(name, url, active=1) {
xhttp_ps.send(); xhttp_ps.send();
} }
function json_center_on_block(json) {
for (var i = 0; i < json.length; i++) {
if (json[i].geometry && json[i].geometry.coordinates) {
switch (json[i].geometry.type) {
case "Point":
json[i].geometry.coordinates[0] += 0.5;
json[i].geometry.coordinates[1] += 0.5;
break;
case "LineString":
for (var j = 0; j < json[i].geometry.coordinates.length; j++) {
json[i].geometry.coordinates[j][0] += 0.5;
json[i].geometry.coordinates[j][1] += 0.5;
}
break;
default:
console.log("centering: Type " + json[i].geometry.type + " not yet implemented.");
break;
}
}
}
return json;
}
function load_tiles(name, id) { function load_tiles(name, id) {
var satellite = L.tileLayer('https://notsyncing.net/maps.linux-forks.de/tiles/?id={id}&z={z}&x={x}&y={y}', { var satellite = L.tileLayer('https://notsyncing.net/maps.linux-forks.de/tiles/?id={id}&z={z}&x={x}&y={y}', {
maxZoom: 14 /*8*/, maxZoom: 14 /*8*/,
@ -136,7 +159,8 @@ function load_geojson(name, url, iconname, iconcolor, active=1, style={}) {
}; };
break; break;
} }
var geojson = L.geoJSON(JSON.parse(xhttp_ps.responseText), { var json = json_center_on_block(JSON.parse(xhttp_ps.responseText));
var geojson = L.geoJSON(json, {
style: style, style: style,
onEachFeature: onEachFeature, onEachFeature: onEachFeature,
pointToLayer: pointToLayer pointToLayer: pointToLayer
@ -146,7 +170,7 @@ function load_geojson(name, url, iconname, iconcolor, active=1, style={}) {
geojson.addTo(mymap); geojson.addTo(mymap);
return geojson; return geojson;
} else { } else {
alert("Error: Could not load geojson map layer (" + name + ")."); console.log("Error: Could not load geojson map layer (" + name + ").");
} }
} }
} }
@ -168,6 +192,7 @@ load_geojson("CW Complexes", "./geojson/cw_complexes.json", "border-all", "black
load_geojson("Courts", "./geojson/courts.json", "balance-scale", "black"); load_geojson("Courts", "./geojson/courts.json", "balance-scale", "black");
load_geojson("Waterway", "./geojson/waterway.json", "water", "darkblue"); load_geojson("Waterway", "./geojson/waterway.json", "water", "darkblue");
load_geojson("Train Depots", "./geojson/depots.json", "wrench", "violet"); load_geojson("Train Depots", "./geojson/depots.json", "wrench", "violet");
load_geojson("Streets", "./geojson/streets.json", "street", "blue", 0);
L.control.scale().addTo(mymap); L.control.scale().addTo(mymap);

View File

@ -28,7 +28,6 @@ if (urlParams.has('editor')) {
function strToPoints(str) { function strToPoints(str) {
var temp = JSON.parse("[" + str + "]"); // TODO: add .5 everwhere var temp = JSON.parse("[" + str + "]"); // TODO: add .5 everwhere
console.log(temp);
return temp; return temp;
} }