From 13d247019ce0878cc714bb5af4490e719f06f5ee Mon Sep 17 00:00:00 2001 From: Jon Atkins Date: Fri, 30 Aug 2013 06:54:22 +0100 Subject: [PATCH] re-write map initial position setting. before, if the initial zoom was invalid for the selected layer, things would get stuck in an odd way --- code/boot.js | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/code/boot.js b/code/boot.js index 850787fb..82fbf94b 100644 --- a/code/boot.js +++ b/code/boot.js @@ -127,10 +127,8 @@ window.setupMap = function() { /*5*/ new L.Google('TERRAIN',{maxZoom:15}) ]; - - window.map = new L.Map('map', $.extend(getPosition(), - {zoomControl: window.showZoom, minZoom: 1} - )); + // proper initial position is now delayed until all plugins are loaded and the base layer is set + window.map = new L.Map('map', {center: [0,0], zoom: 1, zoomControl: window.showZoom, minZoom: 1}); // add empty div to leaflet control areas - to force other leaflet controls to move around IITC UI elements // TODO? move the actual IITC DOM into the leaflet control areas, so dummy
s aren't needed @@ -221,9 +219,10 @@ window.setMapBaseLayer = function() { var baseLayer = nameToLayer[localStorage['iitc-base-map']] || firstLayer; map.addLayer(baseLayer); - //after choosing a base layer, ensure the zoom is valid for this layer - //(needs to be done here - as we don't know the base layer zoom limit before this) - map.setZoom(map.getZoom()); + // now we have a base layer we can set the map position + // (setting an initial position, before a base layer is added, causes issues with leaflet) + var pos = getPosition(); + map.setView (pos.center, pos.zoom, {reset:true}); //event to track layer changes and store the name