mapserver/server/static/js/Hashroute.js

61 lines
1.2 KiB
JavaScript
Raw Normal View History

2019-04-04 11:19:29 +03:00
/* exported Hashroute */
2019-02-15 17:51:11 +03:00
var Hashroute = {
setup: function(map, layerMgr){
function updateHash(){
var center = map.getCenter();
2019-04-04 11:19:29 +03:00
window.location.hash =
2019-02-15 17:51:11 +03:00
layerMgr.getCurrentLayer().id + "/" +
center.lng + "/" + center.lat + "/" + map.getZoom();
}
2019-04-04 11:19:29 +03:00
map.on('zoomend', updateHash);
map.on('moveend', updateHash);
map.on('baselayerchange', updateHash);
2019-02-15 17:51:11 +03:00
updateHash();
},
getLayerId: function(){
2019-04-04 11:19:29 +03:00
var hashParts = window.location.hash.substring(1).split("/");
2019-02-15 17:51:11 +03:00
if (hashParts.length == 4){
//new format
2019-04-04 11:19:29 +03:00
return +hashParts[0];
2019-02-15 17:51:11 +03:00
}
return 0;
},
getZoom: function(){
2019-04-04 11:19:29 +03:00
var hashParts = window.location.hash.substring(1).split("/");
2019-02-15 17:51:11 +03:00
if (hashParts.length == 3){
//old format
2019-04-04 11:19:29 +03:00
return +hashParts[2];
2019-02-15 17:51:11 +03:00
} else if (hashParts.length == 4){
//new format
2019-04-04 11:19:29 +03:00
return +hashParts[3];
2019-02-15 17:51:11 +03:00
}
return 11;
},
getCenter: function(){
2019-04-04 11:19:29 +03:00
var hashParts = window.location.hash.substring(1).split("/");
2019-02-15 17:51:11 +03:00
if (hashParts.length == 3){
//old format
return [+hashParts[1], +hashParts[0]];
} else if (hashParts.length == 4){
//new format
return [+hashParts[2], +hashParts[1]];
}
return [0, 0];
}
};