add map zoom permalink

This commit is contained in:
Dominik Heidler 2015-12-10 23:44:52 +01:00
parent 166e72b072
commit 431b4a62dd
2 changed files with 20 additions and 1 deletions

View File

@ -22,6 +22,18 @@ var router_pointer_radius = 7.5; // actually 7 but let's add some rounding toler
var popup;
function update_mappos_permalink() {
if (typeof mapurl != 'undefined') {
var pos = map.getCenter();
var zoom = map.getZoom();
window.history.replaceState({}, document.title, mapurl + '?mapcenter='+pos.lat.toFixed(5)+','+pos.lng.toFixed(5)+','+zoom);
}
}
map.on('moveend', update_mappos_permalink);
map.on('zoomend', update_mappos_permalink);
map.on('click', function(pos) {
// height = width of world in px
var size_of_world_in_px = map.options.crs.scale(map.getZoom());

View File

@ -28,9 +28,16 @@
var url_get_nearest_router = "{{ url_for('api.get_nearest_router') }}";
var url_router_info = "{{ url_for('router_info', dbid='') }}";
var tileurls = {{ tileurls|tojson|safe }};
var mapurl = "{{ url_for('router_map') }}";
</script>
<script src="{{ url_for('static', filename='js/map.js') }}"></script>
<script type="text/javascript">
map.setView([49.45, 11.1], 10);
if (window.location.search.match("^\\?mapcenter")) {
var maploc = window.location.search.replace("?mapcenter=", "").split(",");
map.setView([maploc[0], maploc[1]], maploc[2]);
}
else {
map.setView([49.45, 11.1], 10);
}
</script>
{% endblock %}