add support for anchor-based permalink, p=sbrunner, r=me (closes #2785)

git-svn-id: http://svn.openlayers.org/trunk/openlayers@11170 dc9f47b5-9b13-0410-9fdd-eb0c1a62fdaf
This commit is contained in:
Éric Lemoine
2011-02-21 11:53:08 +00:00
parent 3fce968f2a
commit 7e18475a0b
7 changed files with 220 additions and 14 deletions

View File

@@ -4,11 +4,67 @@
<script type="text/javascript">
var map;
function test_Control_Permalink_constructor (t) {
t.plan( 2 );
t.plan(42);
control = new OpenLayers.Control.Permalink();
t.ok( control instanceof OpenLayers.Control.Permalink, "new OpenLayers.Control returns object" );
t.eq( control.displayClass, "olControlPermalink", "displayClass is correct" );
t.ok(control instanceof OpenLayers.Control.Permalink, "new OpenLayers.Control returns object");
t.eq(control.displayClass, "olControlPermalink", "displayClass is correct");
t.eq(control.base, document.location.href, "base is correct");
t.ok(!control.anchor, "anchor is correct");
control = new OpenLayers.Control.Permalink('permalink', 'test.html');
t.ok(control instanceof OpenLayers.Control.Permalink, "new OpenLayers.Control returns object");
t.eq(control.displayClass, "olControlPermalink", "displayClass is correct");
t.eq(control.base, 'test.html', "base is correct");
t.ok(OpenLayers.Util.isElement(control.element), "element is a dom object");
t.ok(!control.anchor, "anchor is correct");
control = new OpenLayers.Control.Permalink('permalink');
t.ok(control instanceof OpenLayers.Control.Permalink, "new OpenLayers.Control returns object");
t.eq(control.displayClass, "olControlPermalink", "displayClass is correct");
t.eq(control.base, document.location.href, "base is correct");
t.ok(OpenLayers.Util.isElement(control.element), "element is a dom object");
t.ok(!control.anchor, "anchor is correct");
control = new OpenLayers.Control.Permalink(OpenLayers.Util.getElement('permalink'));
t.ok(control instanceof OpenLayers.Control.Permalink, "new OpenLayers.Control returns object");
t.eq(control.displayClass, "olControlPermalink", "displayClass is correct");
t.eq(control.base, document.location.href, "base is correct");
t.ok(OpenLayers.Util.isElement(control.element), "element is a dom object");
t.ok(!control.anchor, "anchor is correct");
control = new OpenLayers.Control.Permalink({anchor: true});
t.ok(control instanceof OpenLayers.Control.Permalink, "new OpenLayers.Control returns object");
t.eq(control.displayClass, "olControlPermalink", "displayClass is correct");
t.eq(control.base, document.location.href, "base is correct");
t.ok(control.element == null, "element is null");
t.ok(control.anchor, "anchor is correct");
control = new OpenLayers.Control.Permalink({anchor: false});
t.ok(control instanceof OpenLayers.Control.Permalink, "new OpenLayers.Control returns object");
t.eq(control.displayClass, "olControlPermalink", "displayClass is correct");
t.eq(control.base, document.location.href, "base is correct");
t.ok(!control.anchor, "anchor is correct");
control = new OpenLayers.Control.Permalink({});
t.ok(control instanceof OpenLayers.Control.Permalink, "new OpenLayers.Control returns object");
t.eq(control.displayClass, "olControlPermalink", "displayClass is correct");
t.eq(control.base, document.location.href, "base is correct");
t.ok(!control.anchor, "anchor is correct");
control = new OpenLayers.Control.Permalink({element: 'permalink', base: 'test.html'});
t.ok(control instanceof OpenLayers.Control.Permalink, "new OpenLayers.Control returns object");
t.eq(control.displayClass, "olControlPermalink", "displayClass is correct");
t.eq(control.base, 'test.html', "base is correct");
t.ok(OpenLayers.Util.isElement(control.element), "element is a dom object");
t.ok(!control.anchor, "anchor is correct");
control = new OpenLayers.Control.Permalink({element: 'permalink', base: 'test.html', anchor: true});
t.ok(control instanceof OpenLayers.Control.Permalink, "new OpenLayers.Control returns object");
t.eq(control.displayClass, "olControlPermalink", "displayClass is correct");
t.eq(control.base, 'test.html', "base is correct");
t.ok(OpenLayers.Util.isElement(control.element), "element is a dom object");
t.ok(control.anchor, "anchor is correct");
}
function test_Control_Permalink_uncentered (t) {
t.plan( 1 );
@@ -226,7 +282,45 @@
OpenLayers.Util.getParameters = old_getParameters;
OpenLayers.Projection.transform = old_transform;
}
function test_Control_Permalink_Anchor (t) {
t.plan(3);
control = new OpenLayers.Control.Permalink({anchor: true});
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, {animate:false});
t.ok(OpenLayers.Util.isEquivalentUrl(OpenLayers.Util.getParameterString(control.createParams()), "zoom=2&lat=0&lon=1.75781&layers=BT"), 'pan sets permalink');
map.layers[1].setVisibility(false);
t.ok(OpenLayers.Util.isEquivalentUrl(OpenLayers.Util.getParameterString(control.createParams()), "zoom=2&lat=0&lon=1.75781&layers=BF"), 'setVisibility sets permalink');
}
function test_Control_Permalink_AnchorBaseElement (t) {
t.plan(3);
control = new OpenLayers.Control.Permalink('permalink', document.location.href, {anchor: true});
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, {animate:false});
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);
t.ok(OpenLayers.Util.isEquivalentUrl(OpenLayers.Util.getElement('permalink').href, location+"#zoom=2&lat=0&lon=1.75781&layers=BF"), 'setVisibility sets permalink');
}
</script>
</head>
<body>