allow permalink to store layer information. update tests so they pass
git-svn-id: http://svn.openlayers.org/trunk/openlayers@1621 dc9f47b5-9b13-0410-9fdd-eb0c1a62fdaf
This commit is contained in:
@@ -17,6 +17,15 @@ OpenLayers.Control.Permalink.prototype =
|
|||||||
/** @type String */
|
/** @type String */
|
||||||
base: '',
|
base: '',
|
||||||
|
|
||||||
|
/** @type OpenLayers.LonLat */
|
||||||
|
center: null,
|
||||||
|
|
||||||
|
/** @type int */
|
||||||
|
zoom: null,
|
||||||
|
|
||||||
|
/** @type Array */
|
||||||
|
layers: null,
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @constructor
|
* @constructor
|
||||||
*
|
*
|
||||||
@@ -26,7 +35,9 @@ OpenLayers.Control.Permalink.prototype =
|
|||||||
initialize: function(element, base) {
|
initialize: function(element, base) {
|
||||||
OpenLayers.Control.prototype.initialize.apply(this, arguments);
|
OpenLayers.Control.prototype.initialize.apply(this, arguments);
|
||||||
this.element = element;
|
this.element = element;
|
||||||
if (base) this.base = base;
|
if (base) {
|
||||||
|
this.base = base;
|
||||||
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -35,25 +46,27 @@ OpenLayers.Control.Permalink.prototype =
|
|||||||
draw: function() {
|
draw: function() {
|
||||||
OpenLayers.Control.prototype.draw.apply(this, arguments);
|
OpenLayers.Control.prototype.draw.apply(this, arguments);
|
||||||
var args = OpenLayers.Util.getArgs();
|
var args = OpenLayers.Util.getArgs();
|
||||||
|
|
||||||
if (args.lat && args.lon) {
|
if (args.lat && args.lon) {
|
||||||
if (this.map.baseLayer) {
|
this.center = new OpenLayers.LonLat(parseFloat(args.lon),
|
||||||
this.map.setCenter(
|
parseFloat(args.lat));
|
||||||
new OpenLayers.LonLat(parseFloat(args.lon), parseFloat(args.lat))
|
if (args.zoom) {
|
||||||
);
|
this.zoom = parseInt(args.zoom);
|
||||||
} else {
|
|
||||||
this.centerData = new OpenLayers.LonLat(
|
|
||||||
parseFloat(args.lon),
|
|
||||||
parseFloat(args.lat));
|
|
||||||
this.map.events.register( 'changebaselayer', this, this.setCenter);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// when we add a new baselayer to see when we can set the center
|
||||||
|
this.map.events.register('changebaselayer', this, this.setCenter);
|
||||||
|
this.setCenter();
|
||||||
}
|
}
|
||||||
if (args.zoom) {
|
|
||||||
if (this.map.baseLayer) {
|
if (args.layers) {
|
||||||
this.map.zoomTo(parseInt(args.zoom));
|
this.layers = args.layers;
|
||||||
} else {
|
|
||||||
this.zoomData = parseInt(args.zoom);
|
// when we add a new layer, set its visibility
|
||||||
}
|
this.map.events.register('addlayer', this, this.configureLayers);
|
||||||
|
this.configureLayers();
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!this.element) {
|
if (!this.element) {
|
||||||
this.element = document.createElement("a");
|
this.element = document.createElement("a");
|
||||||
this.div.style.right = "3px";
|
this.div.style.right = "3px";
|
||||||
@@ -67,7 +80,7 @@ OpenLayers.Control.Permalink.prototype =
|
|||||||
this.element.href="";
|
this.element.href="";
|
||||||
this.div.appendChild(this.element);
|
this.div.appendChild(this.element);
|
||||||
}
|
}
|
||||||
this.map.events.register( 'moveend', this, this.updateLink);
|
this.map.events.register('moveend', this, this.updateLink);
|
||||||
return this.div;
|
return this.div;
|
||||||
},
|
},
|
||||||
|
|
||||||
@@ -79,34 +92,58 @@ OpenLayers.Control.Permalink.prototype =
|
|||||||
var zoom = "zoom=" + this.map.getZoom();
|
var zoom = "zoom=" + this.map.getZoom();
|
||||||
var lat = "lat=" + Math.round(center.lat*100000)/100000;
|
var lat = "lat=" + Math.round(center.lat*100000)/100000;
|
||||||
var lon = "lon=" + Math.round(center.lon*100000)/100000;
|
var lon = "lon=" + Math.round(center.lon*100000)/100000;
|
||||||
|
|
||||||
var layers = "layers=";
|
var layers = "layers=";
|
||||||
var first = true;
|
|
||||||
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.getVisibility()) {
|
|
||||||
if (!first) {
|
if (layer.isBaseLayer) {
|
||||||
layers += ",";
|
layers += (layer == this.map.baseLayer) ? "B" : "0";
|
||||||
}
|
} else {
|
||||||
layers += i;
|
layers += (layer.getVisibility()) ? "T" : "F";
|
||||||
first = false;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
var href = this.base + "?" + lat + "&" + lon + "&" +
|
var href = this.base + "?" + lat + "&" + lon + "&" + zoom +
|
||||||
zoom + "&" + layers;
|
"&" + layers;
|
||||||
this.element.href = href;
|
this.element.href = href;
|
||||||
},
|
},
|
||||||
|
|
||||||
|
/** As soon as a baseLayer has been loaded, we center and zoom
|
||||||
|
* ...and remove the handler.
|
||||||
|
*/
|
||||||
setCenter: function() {
|
setCenter: function() {
|
||||||
if (this.map.baseLayer && this.centerData) {
|
|
||||||
this.map.setCenter(this.centerData, this.zoomData ? this.zoomData : null);
|
if (this.map.baseLayer) {
|
||||||
this.centerData = null;
|
//dont need to listen for this one anymore
|
||||||
|
this.map.events.unregister('changebaselayer', this,
|
||||||
|
this.setCenter);
|
||||||
|
|
||||||
|
this.map.setCenter(this.center, this.zoom);
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
|
/** As soon as all the layers are loaded, cycle through them and
|
||||||
|
* hide or show them.
|
||||||
|
*/
|
||||||
|
configureLayers: function() {
|
||||||
|
|
||||||
|
if (this.layers.length == this.map.layers.length) {
|
||||||
|
this.map.events.unregister('addlayer', this, this.configureLayers);
|
||||||
|
|
||||||
|
for(var i=0; i < this.layers.length; i++) {
|
||||||
|
|
||||||
|
var layer = this.map.layers[i];
|
||||||
|
var c = this.layers.charAt(i);
|
||||||
|
|
||||||
|
if (c == "B") {
|
||||||
|
this.map.setBaseLayer(layer);
|
||||||
|
} else if ( (c == "T") || (c == "F") ) {
|
||||||
|
layer.setVisibility(c == "T");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
|
||||||
/** @final @type String */
|
/** @final @type String */
|
||||||
CLASS_NAME: "OpenLayers.Control.Permalink"
|
CLASS_NAME: "OpenLayers.Control.Permalink"
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
@@ -21,9 +21,9 @@
|
|||||||
map.addControl(control);
|
map.addControl(control);
|
||||||
map.pan(5, 0);
|
map.pan(5, 0);
|
||||||
if (/MSIE/.test(navigator.userAgent)) {
|
if (/MSIE/.test(navigator.userAgent)) {
|
||||||
t.eq($('permalink').href, "?lat=0&lon=1.75781&zoom=2&layers=0", "Panning sets permalink");
|
t.eq($('permalink').href, "?lat=0&lon=1.75781&zoom=2&layers=B", "Panning sets permalink");
|
||||||
} else {
|
} else {
|
||||||
t.eq($('permalink').href, location+"?lat=0&lon=1.75781&zoom=2&layers=0", "Panning sets permalink");
|
t.eq($('permalink').href, location+"?lat=0&lon=1.75781&zoom=2&layers=B", "Panning sets permalink");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
function test_03_Control_Permalink_updateLinksBase (t) {
|
function test_03_Control_Permalink_updateLinksBase (t) {
|
||||||
@@ -37,7 +37,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);
|
||||||
$('edit_permalink').href = './edit.html?lat=0&lon=1.75781&zoom=2&layers=0';
|
$('edit_permalink').href = './edit.html?lat=0&lon=1.75781&zoom=2&layers=B';
|
||||||
t.eq($('permalink').href, $('edit_permalink').href, "Panning sets permalink with base");
|
t.eq($('permalink').href, $('edit_permalink').href, "Panning sets permalink with base");
|
||||||
}
|
}
|
||||||
function test_04_Control_Permalink_noElement (t) {
|
function test_04_Control_Permalink_noElement (t) {
|
||||||
|
|||||||
Reference in New Issue
Block a user