Testing that the permalink works with map options.
The permalink/argparser combo doesn't properly handle map configurations where layers and a map location are provided (see #270).
This commit is contained in:
@@ -322,8 +322,12 @@
|
||||
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_arrayCenter(t) {
|
||||
t.plan(1);
|
||||
function test_center_from_map(t) {
|
||||
t.plan(7);
|
||||
|
||||
var previous = window.location.hash;
|
||||
window.location.hash = "";
|
||||
|
||||
var err;
|
||||
try {
|
||||
var map = new OpenLayers.Map({
|
||||
@@ -331,8 +335,8 @@
|
||||
controls: [
|
||||
new OpenLayers.Control.Permalink({anchor: true})
|
||||
],
|
||||
center: [0, 0],
|
||||
zoom: 1
|
||||
center: [1, 2],
|
||||
zoom: 3
|
||||
});
|
||||
} catch (e) {
|
||||
err = e;
|
||||
@@ -342,6 +346,51 @@
|
||||
} else {
|
||||
t.ok(true, "Map construction works");
|
||||
}
|
||||
|
||||
// confirm that map center is correctly set
|
||||
var center = map.getCenter();
|
||||
t.eq(center.lon, 1, "map x");
|
||||
t.eq(center.lat, 2, "map y")
|
||||
t.eq(map.getZoom(), 3, "map z");
|
||||
|
||||
// confirm that location from map options has been added to url
|
||||
var params = OpenLayers.Util.getParameters(window.location.hash.replace("#", "?"));
|
||||
t.eq(params.lon, "1", "url x");
|
||||
t.eq(params.lat, "2", "url y");
|
||||
t.eq(params.zoom, "3", "url z");
|
||||
|
||||
// map.destroy();
|
||||
window.location.hash = previous;
|
||||
}
|
||||
|
||||
function test_center_from_url(t) {
|
||||
t.plan(6);
|
||||
|
||||
// In cases where the location is specified in the URL and given in
|
||||
// the map options, we respect the location in the URL.
|
||||
var previous = window.location.hash;
|
||||
window.location.hash = "#zoom=6&lat=5&lon=4&layers=B"
|
||||
|
||||
var map = new OpenLayers.Map({
|
||||
layers: [new OpenLayers.Layer(null, {isBaseLayer: true})],
|
||||
controls: [new OpenLayers.Control.Permalink({anchor: true})],
|
||||
center: [0, 0],
|
||||
zoom: 0
|
||||
});
|
||||
|
||||
// confirm that map center is correctly set
|
||||
var center = map.getCenter();
|
||||
t.eq(center.lon, 4, "map x");
|
||||
t.eq(center.lat, 5, "map y")
|
||||
t.eq(map.getZoom(), 6, "map z");
|
||||
|
||||
var params = OpenLayers.Util.getParameters(window.location.hash.replace("#", "?"));
|
||||
t.eq(params.lon, "4", "x set");
|
||||
t.eq(params.lat, "5", "y set");
|
||||
t.eq(params.zoom, "6", "z set");
|
||||
|
||||
// map.destroy();
|
||||
window.location.hash = previous;
|
||||
}
|
||||
|
||||
</script>
|
||||
|
||||
Reference in New Issue
Block a user