preserve bounds while switching map apis
This commit is contained in:
parent
458f1449cb
commit
fcd96c74ca
17
api_gmaps.js
17
api_gmaps.js
@ -171,3 +171,20 @@ function addChartEvent(chart) {
|
||||
}
|
||||
});
|
||||
}
|
||||
//((52.20105108685229, 20.789387865580238), (52.292069558807135, 21.172192736185707))
|
||||
function getBounds() {
|
||||
var b = map.getBounds().toString();
|
||||
var bounds = b.split(',',4);
|
||||
var lat_sw = bounds[0].replace(/\(/g,'');
|
||||
var lon_sw = bounds[1].replace(/[ )]/g,'');
|
||||
var lat_ne = bounds[2].replace(/[ (]/g,'');
|
||||
var lon_ne = bounds[3].replace(/[ )]/g,'');
|
||||
return [lon_sw,lat_sw,lon_ne,lat_ne];
|
||||
}
|
||||
|
||||
function zoomToBounds(b) {
|
||||
var sw = new google.maps.LatLng(b[1],b[0]);
|
||||
var ne = new google.maps.LatLng(b[3],b[2]);
|
||||
var bounds = new google.maps.LatLngBounds(sw,ne);
|
||||
map.fitBounds(bounds);
|
||||
}
|
||||
|
@ -167,3 +167,18 @@ function addChartEvent(chart) {
|
||||
}
|
||||
});
|
||||
}
|
||||
//20.597985430276808,52.15547181298076,21.363595171488573,52.33750879522563
|
||||
function getBounds() {
|
||||
var b = map.getExtent().transform(mercator,wgs84).toString();
|
||||
var bounds = b.split(',',4);
|
||||
var lon_sw = bounds[0];
|
||||
var lat_sw = bounds[1];
|
||||
var lon_ne = bounds[2];
|
||||
var lat_ne = bounds[3];
|
||||
return [lon_sw,lat_sw,lon_ne,lat_ne];
|
||||
}
|
||||
|
||||
function zoomToBounds(b) {
|
||||
var bounds = new OpenLayers.Bounds(b).transform(wgs84,mercator);
|
||||
map.zoomToExtent(bounds);
|
||||
}
|
||||
|
5
main.js
5
main.js
@ -282,7 +282,9 @@ function setTime() {
|
||||
}
|
||||
|
||||
// dynamic change of map api
|
||||
var savedBounds;
|
||||
function loadMapAPI(api) {
|
||||
savedBounds = getBounds();
|
||||
document.getElementById("map-canvas").innerHTML = '';
|
||||
var url = new Array();
|
||||
if (api=='gmaps') {
|
||||
@ -322,7 +324,8 @@ function waitAndInit(api) {
|
||||
return;
|
||||
}
|
||||
loadTime = 0;
|
||||
loadTrack(userid,trackid,1);
|
||||
zoomToBounds(savedBounds);
|
||||
loadTrack(userid,trackid,0);
|
||||
}
|
||||
|
||||
function addScript(url) {
|
||||
|
Loading…
x
Reference in New Issue
Block a user