"New permalink code maintains existing parameters ... including the
lat/lon/zoom/layers." Reported by bobkare (thx, bobkare!) with a patch by same, rewritten by Schuyler, reviewed by me -- and I'm committing because Schuyler's whitespace was bad. (RC1, here we come!) git-svn-id: http://svn.openlayers.org/trunk/openlayers@4345 dc9f47b5-9b13-0410-9fdd-eb0c1a62fdaf
This commit is contained in:
@@ -110,36 +110,29 @@ OpenLayers.Control.Permalink = OpenLayers.Class(OpenLayers.Control, {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
var zoom = "zoom=" + this.map.getZoom();
|
var params = OpenLayers.Util.getParameters(this.base);
|
||||||
var lat = "lat=" + Math.round(center.lat*100000)/100000;
|
|
||||||
var lon = "lon=" + Math.round(center.lon*100000)/100000;
|
|
||||||
|
|
||||||
var layers = "layers=";
|
params.zoom = this.map.getZoom();
|
||||||
|
params.lat = Math.round(center.lat*100000)/100000;
|
||||||
|
params.lon = Math.round(center.lon*100000)/100000;
|
||||||
|
|
||||||
|
params.layers = '';
|
||||||
for(var i=0; i< this.map.layers.length; i++) {
|
for(var i=0; i< this.map.layers.length; i++) {
|
||||||
var layer = this.map.layers[i];
|
var layer = this.map.layers[i];
|
||||||
|
|
||||||
if (layer.isBaseLayer) {
|
if (layer.isBaseLayer) {
|
||||||
layers += (layer == this.map.baseLayer) ? "B" : "0";
|
params.layers += (layer == this.map.baseLayer) ? "B" : "0";
|
||||||
} else {
|
} else {
|
||||||
layers += (layer.getVisibility()) ? "T" : "F";
|
params.layers += (layer.getVisibility()) ? "T" : "F";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
var href = this.base;
|
var href = this.base;
|
||||||
var paramsString = lat + "&" + lon + "&" + zoom + "&" + layers;
|
if( href.indexOf('?') != -1 ){
|
||||||
|
href = href.substring( 0, href.indexOf('?') );
|
||||||
|
}
|
||||||
|
|
||||||
var lastServerChar = href.charAt(href.length - 1);
|
href += '?' + OpenLayers.Util.getParameterString(params);
|
||||||
if ((lastServerChar == "&") || (lastServerChar == "?")) {
|
|
||||||
href += paramsString;
|
|
||||||
} else {
|
|
||||||
if (href.indexOf('?') == -1) {
|
|
||||||
//serverPath has no ? -- add one
|
|
||||||
href += '?' + paramsString;
|
|
||||||
} else {
|
|
||||||
//serverPath contains ?, so must already have paramsString at the end
|
|
||||||
href += '&' + paramsString;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
this.element.href = href;
|
this.element.href = href;
|
||||||
},
|
},
|
||||||
|
|
||||||
|
|||||||
@@ -39,11 +39,11 @@
|
|||||||
if (!map.getCenter()) map.zoomToMaxExtent();
|
if (!map.getCenter()) map.zoomToMaxExtent();
|
||||||
map.addControl(control);
|
map.addControl(control);
|
||||||
map.pan(5, 0);
|
map.pan(5, 0);
|
||||||
t.ok(OpenLayers.Util.isEquivalentUrl(OpenLayers.Util.getElement('permalink').href, location+"?lat=0&lon=1.75781&zoom=2&layers=BT"), 'pan sets permalink');
|
t.ok(OpenLayers.Util.isEquivalentUrl(OpenLayers.Util.getElement('permalink').href, location+"?zoom=2&lat=0&lon=1.75781&layers=BT"), 'pan sets permalink');
|
||||||
|
|
||||||
map.layers[1].setVisibility(false);
|
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');
|
t.ok(OpenLayers.Util.isEquivalentUrl(OpenLayers.Util.getElement('permalink').href, location+"?zoom=2&lat=0&lon=1.75781&layers=BF"), 'setVisibility sets permalink');
|
||||||
}
|
}
|
||||||
function test_03_Control_Permalink_updateLinksBase (t) {
|
function test_03_Control_Permalink_updateLinksBase (t) {
|
||||||
t.plan( 2 );
|
t.plan( 2 );
|
||||||
@@ -56,7 +56,7 @@
|
|||||||
if (!map.getCenter()) map.zoomToMaxExtent();
|
if (!map.getCenter()) map.zoomToMaxExtent();
|
||||||
map.addControl(control);
|
map.addControl(control);
|
||||||
map.pan(5, 0);
|
map.pan(5, 0);
|
||||||
OpenLayers.Util.getElement('edit_permalink').href = './edit.html?lat=0&lon=1.75781&zoom=2&layers=B';
|
OpenLayers.Util.getElement('edit_permalink').href = './edit.html?zoom=2&lat=0&lon=1.75781&layers=B';
|
||||||
t.eq(OpenLayers.Util.getElement('permalink').href, OpenLayers.Util.getElement('edit_permalink').href, "Panning sets permalink with base");
|
t.eq(OpenLayers.Util.getElement('permalink').href, OpenLayers.Util.getElement('edit_permalink').href, "Panning sets permalink with base");
|
||||||
}
|
}
|
||||||
function test_04_Control_Permalink_noElement (t) {
|
function test_04_Control_Permalink_noElement (t) {
|
||||||
@@ -77,7 +77,7 @@
|
|||||||
if (!map.getCenter()) map.zoomToMaxExtent();
|
if (!map.getCenter()) map.zoomToMaxExtent();
|
||||||
map.addControl(control);
|
map.addControl(control);
|
||||||
map.pan(5, 0);
|
map.pan(5, 0);
|
||||||
OpenLayers.Util.getElement('edit_permalink').href = './edit.html?foo=bar&lat=0&lon=1.75781&zoom=2&layers=B';
|
OpenLayers.Util.getElement('edit_permalink').href = './edit.html?foo=bar&zoom=2&lat=0&lon=1.75781&layers=B';
|
||||||
t.eq(OpenLayers.Util.getElement('permalink').href, OpenLayers.Util.getElement('edit_permalink').href, "Panning sets permalink with base and querystring");
|
t.eq(OpenLayers.Util.getElement('permalink').href, OpenLayers.Util.getElement('edit_permalink').href, "Panning sets permalink with base and querystring");
|
||||||
|
|
||||||
control = new OpenLayers.Control.Permalink('permalink', "./edit.html?foo=bar&" );
|
control = new OpenLayers.Control.Permalink('permalink', "./edit.html?foo=bar&" );
|
||||||
@@ -86,7 +86,7 @@
|
|||||||
t.eq(OpenLayers.Util.getElement('permalink').href, OpenLayers.Util.getElement('edit_permalink').href, "Panning sets permalink with base and querystring ending with '&'");
|
t.eq(OpenLayers.Util.getElement('permalink').href, OpenLayers.Util.getElement('edit_permalink').href, "Panning sets permalink with base and querystring ending with '&'");
|
||||||
|
|
||||||
control = new OpenLayers.Control.Permalink('permalink', "./edit.html?" );
|
control = new OpenLayers.Control.Permalink('permalink', "./edit.html?" );
|
||||||
OpenLayers.Util.getElement('edit_permalink').href = './edit.html?lat=0&lon=1.75781&zoom=2&layers=B';
|
OpenLayers.Util.getElement('edit_permalink').href = './edit.html?zoom=2&lat=0&lon=1.75781&layers=B';
|
||||||
map.addControl(control);
|
map.addControl(control);
|
||||||
map.pan(5, 0);
|
map.pan(5, 0);
|
||||||
map.pan(-5, 0);
|
map.pan(-5, 0);
|
||||||
@@ -94,6 +94,20 @@
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function test_06_Control_Permalink_nonRepeating (t) {
|
||||||
|
t.plan( 2 );
|
||||||
|
|
||||||
|
control = new OpenLayers.Control.Permalink('permalink', "./edit.html?zoom=3" );
|
||||||
|
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);
|
||||||
|
if (!map.getCenter()) map.zoomToMaxExtent();
|
||||||
|
map.addControl(control);
|
||||||
|
map.pan(5, 0);
|
||||||
|
OpenLayers.Util.getElement('edit_permalink').href = './edit.html?zoom=2&lat=0&lon=1.75781&layers=B';
|
||||||
|
t.eq(OpenLayers.Util.getElement('permalink').href, OpenLayers.Util.getElement('edit_permalink').href, "Panning sets permalink with existing zoom in base");
|
||||||
|
}
|
||||||
</script>
|
</script>
|
||||||
</head>
|
</head>
|
||||||
<body>
|
<body>
|
||||||
|
|||||||
Reference in New Issue
Block a user