From 657867309e110e842d36b960e7d6b8158eddccc9 Mon Sep 17 00:00:00 2001 From: Markus Koch Date: Sun, 19 Apr 2020 07:38:41 +0200 Subject: Improve center-on-block feature 6284c9d8b45b4df112326c23037a5c7c2e0b89d0 introduced a feature to center coordinate data on blocks by shifting the actual waypoints. The problem with that approach is that it actually changes the coordinates returned by any subsequent query to that geojson entry, leading to coordinates like [0.5, 0.5] instead of [0, 0]. This commit removes the old translation code and instead shifts the entire map. This means waypoints are still correct, and only the visuals are affected. The correctness of new coordinate mapping has been verified in-game and using the origin marker. --- htdocs/mapscript.js | 29 +++-------------------------- htdocs/streeteditor.js | 11 +++-------- 2 files changed, 6 insertions(+), 34 deletions(-) diff --git a/htdocs/mapscript.js b/htdocs/mapscript.js index 83967ba..d7ca17b 100644 --- a/htdocs/mapscript.js +++ b/htdocs/mapscript.js @@ -18,8 +18,8 @@ var streetLabelsRenderer = new L.StreetLabels({ // Projection fix from: https://gis.stackexchange.com/questions/200865/leaflet-crs-simple-custom-scale var factorx = 1 / 256 * 4; var factory = factorx; -var originx = 7000; -var originy = 7000; +var originx = 7000 + 8 + 0.5; +var originy = 7000 + 8 - 0.5; var zoom_level_real = 6; L.CRS.pr = L.extend({}, L.CRS.Simple, { @@ -83,29 +83,6 @@ 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*/, @@ -159,7 +136,7 @@ function load_geojson(name, url, iconname, iconcolor, active=1, style={}) { }; break; } - var json = json_center_on_block(JSON.parse(xhttp_ps.responseText)); + var json = JSON.parse(xhttp_ps.responseText); var geojson = L.geoJSON(json, { style: style, onEachFeature: onEachFeature, diff --git a/htdocs/streeteditor.js b/htdocs/streeteditor.js index 392bc22..7109b0e 100644 --- a/htdocs/streeteditor.js +++ b/htdocs/streeteditor.js @@ -7,13 +7,8 @@ if (urlParams.has('editor')) { var edit_active = 0; function resolve_latlng(latlng, recenter = 0) { - var corr; - if (recenter) - corr = 0.5; - else - corr = 0; - latlng.lng = Math.round(latlng.lng - 0.5) + corr; - latlng.lat = Math.round(latlng.lat - 0.5) + corr; + latlng.lng = Math.round(latlng.lng); + latlng.lat = Math.round(latlng.lat); return latlng; } @@ -91,7 +86,7 @@ if (urlParams.has('editor')) { latlng = resolve_latlng(latlngs[i], 1); if (i != 0) str += ","; - str += "[" + (latlng.lng - 0.5) + "," + (latlng.lat - 0.5) + "]"; + str += "[" + (latlng.lng) + "," + (latlng.lat) + "]"; } return str; -- cgit v1.2.3