make sure permalink updates itself when layers change name/visibility or when a baselayer switch is made. (Closes #359)
git-svn-id: http://svn.openlayers.org/trunk/openlayers@4228 dc9f47b5-9b13-0410-9fdd-eb0c1a62fdaf
This commit is contained in:
@@ -93,6 +93,8 @@ OpenLayers.Control.Permalink = OpenLayers.Class(OpenLayers.Control, {
|
||||
this.div.appendChild(this.element);
|
||||
}
|
||||
this.map.events.register('moveend', this, this.updateLink);
|
||||
this.map.events.register('changelayer', this, this.updateLink);
|
||||
this.map.events.register('changebaselayer', this, this.updateLink);
|
||||
return this.div;
|
||||
},
|
||||
|
||||
@@ -101,6 +103,12 @@ OpenLayers.Control.Permalink = OpenLayers.Class(OpenLayers.Control, {
|
||||
*/
|
||||
updateLink: function() {
|
||||
var center = this.map.getCenter();
|
||||
|
||||
// Map not initialized yet. Break out of this function.
|
||||
if (!center) {
|
||||
return;
|
||||
}
|
||||
|
||||
var zoom = "zoom=" + this.map.getZoom();
|
||||
var lat = "lat=" + Math.round(center.lat*100000)/100000;
|
||||
var lon = "lon=" + Math.round(center.lon*100000)/100000;
|
||||
|
||||
@@ -10,18 +10,34 @@
|
||||
t.ok( control instanceof OpenLayers.Control.Permalink, "new OpenLayers.Control returns object" );
|
||||
t.eq( control.displayClass, "olControlPermalink", "displayClass is correct" );
|
||||
}
|
||||
function test_Control_Permalink_uncentered (t) {
|
||||
t.plan( 1 );
|
||||
|
||||
control = new OpenLayers.Control.Permalink('permalink');
|
||||
map = new OpenLayers.Map('map');
|
||||
map.addControl(control);
|
||||
map.events.triggerEvent("changelayer", {});
|
||||
t.ok(true, "permalink didn't bomb out.");
|
||||
}
|
||||
function test_02_Control_Permalink_updateLinks (t) {
|
||||
t.plan( 2 );
|
||||
t.plan( 3 );
|
||||
|
||||
control = new OpenLayers.Control.Permalink('permalink');
|
||||
t.ok( control instanceof OpenLayers.Control.Permalink, "new OpenLayers.Control returns object" );
|
||||
map = new OpenLayers.Map('map');
|
||||
layer = new OpenLayers.Layer.WMS('Test Layer', "http://octo.metacarta.com/cgi-bin/mapserv", {map: '/mapdata/vmap_wms.map', layers: 'basic', format: 'image/jpeg'});
|
||||
map.addLayer(layer);
|
||||
layer = new OpenLayers.Layer.WMS('Test Layer', "http://octo.metacarta.com/cgi-bin/mapserv", {map: '/mapdata/vmap_wms.map', layers: 'basic', format: 'image/jpeg'}, {'isBaseLayer': false});
|
||||
map.addLayer(layer);
|
||||
layer.setVisibility(true);
|
||||
if (!map.getCenter()) map.zoomToMaxExtent();
|
||||
map.addControl(control);
|
||||
map.pan(5, 0);
|
||||
t.eq(OpenLayers.Util.getElement('permalink').href, location+"?lat=0&lon=1.75781&zoom=2&layers=B", "Panning sets permalink");
|
||||
t.ok(OpenLayers.Util.isEquivalentUrl(OpenLayers.Util.getElement('permalink').href, location+"?lat=0&lon=1.75781&zoom=2&layers=BT"), 'pan sets permalink');
|
||||
|
||||
map.layers[1].setVisibility(false);
|
||||
|
||||
t.ok(OpenLayers.Util.isEquivalentUrl(OpenLayers.Util.getElement('permalink').href, location+"?lat=0&lon=1.75781&zoom=2&layers=BF"), 'setVisibility sets permalink');
|
||||
}
|
||||
function test_03_Control_Permalink_updateLinksBase (t) {
|
||||
t.plan( 2 );
|
||||
|
||||
Reference in New Issue
Block a user