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.
This commit is contained in:
Markus Koch 2020-04-18 12:35:36 +02:00
parent 828e1edf28
commit 6284c9d8b4

View File

@ -83,6 +83,29 @@ function load_svg(name, url, active=1) {
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) {
var satellite = L.tileLayer('https://notsyncing.net/maps.linux-forks.de/tiles/?id={id}&z={z}&x={x}&y={y}', {
maxZoom: 14 /*8*/,
@ -136,7 +159,8 @@ function load_geojson(name, url, iconname, iconcolor, active=1, style={}) {
};
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,
onEachFeature: onEachFeature,
pointToLayer: pointToLayer