summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMarkus Koch <markus@notsyncing.net>2020-04-18 12:35:36 +0200
committerMarkus Koch <markus@notsyncing.net>2020-04-18 12:35:36 +0200
commit6284c9d8b45b4df112326c23037a5c7c2e0b89d0 (patch)
tree3992a2c1828f25ac2ecc3c878b4863129a217210
parent828e1edf2891b9858cca509040fe73696ff72a46 (diff)
downloadlifomapserver-6284c9d8b45b4df112326c23037a5c7c2e0b89d0.tar.gz
lifomapserver-6284c9d8b45b4df112326c23037a5c7c2e0b89d0.tar.bz2
lifomapserver-6284c9d8b45b4df112326c23037a5c7c2e0b89d0.zip
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.
-rw-r--r--htdocs/mapscript.js26
1 files changed, 25 insertions, 1 deletions
diff --git a/htdocs/mapscript.js b/htdocs/mapscript.js
index e3689c6..83967ba 100644
--- a/htdocs/mapscript.js
+++ b/htdocs/mapscript.js
@@ -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