Files
openlayers/tests/Control/test_Permalink.html
crschmidt f505542fbe "The Permalink control passes an element as the first parameter, however, the
initialize.apply is called with the arguments object, which causes an error if
an element is passed into the control." Also applied to Scale. Now fixed
with review from e-dog. (Closes #978) Fixes the only problem I found with 
migrating the Boston freemap to 2.5.


git-svn-id: http://svn.openlayers.org/trunk/openlayers@4333 dc9f47b5-9b13-0410-9fdd-eb0c1a62fdaf
2007-09-16 15:59:11 +00:00

105 lines
5.2 KiB
HTML

<html>
<head>
<script src="../../lib/OpenLayers.js"></script>
<script type="text/javascript">
var map;
function test_01_Control_Permalink_constructor (t) {
t.plan( 2 );
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" );
}
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_initwithelem (t) {
t.plan( 1 );
control = new OpenLayers.Control.Permalink(OpenLayers.Util.getElement('permalink'));
t.ok(true, "If the above line doesn't throw an error, we're safe.");
}
function test_02_Control_Permalink_updateLinks (t) {
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.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 );
control = new OpenLayers.Control.Permalink('permalink', "./edit.html" );
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?lat=0&lon=1.75781&zoom=2&layers=B';
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) {
t.plan( 2 );
control = new OpenLayers.Control.Permalink( );
t.ok( control instanceof OpenLayers.Control.Permalink, "new OpenLayers.Control returns object" );
map = new OpenLayers.Map('map');
map.addControl(control);
t.eq(map.controls[3].div.firstChild.nodeName, "A", "Permalink control creates div with 'a' inside." );
}
function test_05_Control_Permalink_base_with_query (t) {
t.plan( 3 );
control = new OpenLayers.Control.Permalink('permalink', "./edit.html?foo=bar" );
map = new OpenLayers.Map('map');
layer = new OpenLayers.Layer.WMS('Test Layer', "http://example.com" );
map.addLayer(layer);
if (!map.getCenter()) map.zoomToMaxExtent();
map.addControl(control);
map.pan(5, 0);
OpenLayers.Util.getElement('edit_permalink').href = './edit.html?foo=bar&lat=0&lon=1.75781&zoom=2&layers=B';
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&" );
map.addControl(control);
map.pan(0, 0);
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?" );
OpenLayers.Util.getElement('edit_permalink').href = './edit.html?lat=0&lon=1.75781&zoom=2&layers=B';
map.addControl(control);
map.pan(5, 0);
map.pan(-5, 0);
t.eq(OpenLayers.Util.getElement('permalink').href, OpenLayers.Util.getElement('edit_permalink').href, "Panning sets permalink with base and querystring ending with '?'");
}
</script>
</head>
<body>
<a id="permalink" href="">Permalink</a> <br />
<a id="edit_permalink" href="">Edit</a> <br />
<div id="map" style="width: 1024px; height: 512px;"/>
</body>
</html>