Improve center-on-block feature
6284c9d8b4
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.
This commit is contained in:
parent
c10f229f49
commit
657867309e
@ -18,8 +18,8 @@ var streetLabelsRenderer = new L.StreetLabels({
|
|||||||
// Projection fix from: https://gis.stackexchange.com/questions/200865/leaflet-crs-simple-custom-scale
|
// Projection fix from: https://gis.stackexchange.com/questions/200865/leaflet-crs-simple-custom-scale
|
||||||
var factorx = 1 / 256 * 4;
|
var factorx = 1 / 256 * 4;
|
||||||
var factory = factorx;
|
var factory = factorx;
|
||||||
var originx = 7000;
|
var originx = 7000 + 8 + 0.5;
|
||||||
var originy = 7000;
|
var originy = 7000 + 8 - 0.5;
|
||||||
var zoom_level_real = 6;
|
var zoom_level_real = 6;
|
||||||
|
|
||||||
L.CRS.pr = L.extend({}, L.CRS.Simple, {
|
L.CRS.pr = L.extend({}, L.CRS.Simple, {
|
||||||
@ -83,29 +83,6 @@ 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*/,
|
||||||
@ -159,7 +136,7 @@ function load_geojson(name, url, iconname, iconcolor, active=1, style={}) {
|
|||||||
};
|
};
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
var json = json_center_on_block(JSON.parse(xhttp_ps.responseText));
|
var json = JSON.parse(xhttp_ps.responseText);
|
||||||
var geojson = L.geoJSON(json, {
|
var geojson = L.geoJSON(json, {
|
||||||
style: style,
|
style: style,
|
||||||
onEachFeature: onEachFeature,
|
onEachFeature: onEachFeature,
|
||||||
|
@ -7,13 +7,8 @@ if (urlParams.has('editor')) {
|
|||||||
var edit_active = 0;
|
var edit_active = 0;
|
||||||
|
|
||||||
function resolve_latlng(latlng, recenter = 0) {
|
function resolve_latlng(latlng, recenter = 0) {
|
||||||
var corr;
|
latlng.lng = Math.round(latlng.lng);
|
||||||
if (recenter)
|
latlng.lat = Math.round(latlng.lat);
|
||||||
corr = 0.5;
|
|
||||||
else
|
|
||||||
corr = 0;
|
|
||||||
latlng.lng = Math.round(latlng.lng - 0.5) + corr;
|
|
||||||
latlng.lat = Math.round(latlng.lat - 0.5) + corr;
|
|
||||||
return latlng;
|
return latlng;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -91,7 +86,7 @@ if (urlParams.has('editor')) {
|
|||||||
latlng = resolve_latlng(latlngs[i], 1);
|
latlng = resolve_latlng(latlngs[i], 1);
|
||||||
if (i != 0)
|
if (i != 0)
|
||||||
str += ",";
|
str += ",";
|
||||||
str += "[" + (latlng.lng - 0.5) + "," + (latlng.lat - 0.5) + "]";
|
str += "[" + (latlng.lng) + "," + (latlng.lat) + "]";
|
||||||
}
|
}
|
||||||
|
|
||||||
return str;
|
return str;
|
||||||
|
Loading…
Reference in New Issue
Block a user