mirror of
https://github.com/webbukkit/dynmap.git
synced 2024-12-29 12:07:41 +01:00
Fix map center consistency on map changes
This commit is contained in:
parent
1d0b28c069
commit
64bd846115
@ -4,6 +4,9 @@ var DynmapProjection = L.Class.extend({
|
|||||||
},
|
},
|
||||||
fromLocationToLatLng: function(location) {
|
fromLocationToLatLng: function(location) {
|
||||||
throw "fromLocationToLatLng not implemented";
|
throw "fromLocationToLatLng not implemented";
|
||||||
|
},
|
||||||
|
fromLatLngToLocation: function(location) {
|
||||||
|
return null;
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -4,7 +4,13 @@ var FlatProjection = DynmapProjection.extend({
|
|||||||
-location.z / (1 << this.options.mapzoomout),
|
-location.z / (1 << this.options.mapzoomout),
|
||||||
location.x / (1 << this.options.mapzoomout),
|
location.x / (1 << this.options.mapzoomout),
|
||||||
true);
|
true);
|
||||||
|
},
|
||||||
|
fromLatLngToLocation: function(latlon, y) {
|
||||||
|
var z = -latlon.lat * (1 << this.options.mapzoomout);
|
||||||
|
var x = latlon.lng * (1 << this.options.mapzoomout);
|
||||||
|
return { x: x, y: y, z: z };
|
||||||
}
|
}
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|
||||||
var FlatMapType = DynmapTileLayer.extend({
|
var FlatMapType = DynmapTileLayer.extend({
|
||||||
|
@ -7,7 +7,16 @@ var HDProjection = DynmapProjection.extend({
|
|||||||
xx / (1 << this.options.mapzoomout)
|
xx / (1 << this.options.mapzoomout)
|
||||||
, (128-yy) / (1 << this.options.mapzoomout)
|
, (128-yy) / (1 << this.options.mapzoomout)
|
||||||
, true);
|
, true);
|
||||||
|
},
|
||||||
|
fromLatLngToLocation: function(latlon, y) {
|
||||||
|
var ptw = this.options.maptoworld;
|
||||||
|
var lat = latlon.lat * (1 << this.options.mapzoomout);
|
||||||
|
var lon = 128 - latlon.lng * (1 << this.options.mapzoomout);
|
||||||
|
var x = ptw[0]*lat + ptw[1]*lon + ptw[2]*y;
|
||||||
|
var z = ptw[6]*lat + ptw[7]*lon + ptw[8]*y;
|
||||||
|
return { x: x, y: y, z: z };
|
||||||
}
|
}
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|
||||||
var HDMapType = DynmapTileLayer.extend({
|
var HDMapType = DynmapTileLayer.extend({
|
||||||
|
@ -10,7 +10,16 @@ var KzedProjection = DynmapProjection.extend({
|
|||||||
var xx = (128 - px) / scale;
|
var xx = (128 - px) / scale;
|
||||||
var yy = py / scale;
|
var yy = py / scale;
|
||||||
return new L.LatLng(xx, yy, true);
|
return new L.LatLng(xx, yy, true);
|
||||||
|
},
|
||||||
|
fromLatLngToLocation: function(latlon, y) {
|
||||||
|
var scale = 1 << this.options.mapzoomout;
|
||||||
|
var px = 128 - (latlon.lat * scale);
|
||||||
|
var py = latlon.lng * scale;
|
||||||
|
var x = (px + py + (y-127))/2;
|
||||||
|
var z = (px - x);
|
||||||
|
return { x: x, y: y, z: z };
|
||||||
}
|
}
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|
||||||
var KzedMapType = DynmapTileLayer.extend({
|
var KzedMapType = DynmapTileLayer.extend({
|
||||||
|
@ -323,6 +323,8 @@ DynMap.prototype = {
|
|||||||
me.map.removeLayer(me.maptype);
|
me.map.removeLayer(me.maptype);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var prevmap = me.maptype;
|
||||||
|
|
||||||
me.world = mapWorld;
|
me.world = mapWorld;
|
||||||
me.maptype = map;
|
me.maptype = map;
|
||||||
|
|
||||||
@ -338,6 +340,12 @@ DynMap.prototype = {
|
|||||||
centerPoint = me.getProjection().fromLocationToLatLng(centerLocation);
|
centerPoint = me.getProjection().fromLocationToLatLng(centerLocation);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
|
var prevloc = null;
|
||||||
|
if(prevmap != null)
|
||||||
|
prevloc = prevmap.getProjection().fromLatLngToLocation(me.map.getCenter(), 64);
|
||||||
|
if(prevloc != null)
|
||||||
|
centerPoint = me.getProjection().fromLocationToLatLng(prevloc);
|
||||||
|
else
|
||||||
centerPoint = me.map.getCenter();
|
centerPoint = me.map.getCenter();
|
||||||
}
|
}
|
||||||
me.map.setView(centerPoint, prevzoom, true);
|
me.map.setView(centerPoint, prevzoom, true);
|
||||||
|
Loading…
Reference in New Issue
Block a user