[OpenLayers-Commits] r4228 - in trunk/openlayers: lib/OpenLayers/Control tests/Control
commits at openlayers.org
commits at openlayers.org
Tue Sep 11 23:26:37 EDT 2007
Author: euzuro
Date: 2007-09-11 23:26:35 -0400 (Tue, 11 Sep 2007)
New Revision: 4228
Modified:
trunk/openlayers/lib/OpenLayers/Control/Permalink.js
trunk/openlayers/tests/Control/test_Permalink.html
Log:
make sure permalink updates itself when layers change name/visibility or when a baselayer switch is made. (Closes #359)
Modified: trunk/openlayers/lib/OpenLayers/Control/Permalink.js
===================================================================
--- trunk/openlayers/lib/OpenLayers/Control/Permalink.js 2007-09-12 02:37:09 UTC (rev 4227)
+++ trunk/openlayers/lib/OpenLayers/Control/Permalink.js 2007-09-12 03:26:35 UTC (rev 4228)
@@ -93,6 +93,8 @@
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 @@
*/
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;
Modified: trunk/openlayers/tests/Control/test_Permalink.html
===================================================================
--- trunk/openlayers/tests/Control/test_Permalink.html 2007-09-12 02:37:09 UTC (rev 4227)
+++ trunk/openlayers/tests/Control/test_Permalink.html 2007-09-12 03:26:35 UTC (rev 4228)
@@ -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 );
More information about the Commits
mailing list