Files
openlayers/tests/Control/test_Permalink.html
crschmidt c79f1a56c8 (Closes #730) These changes make the permalink smarter in the case where we
already have some URL args in the URL. Thanks to penyaskito for the bug 
report.


git-svn-id: http://svn.openlayers.org/trunk/openlayers@4047 dc9f47b5-9b13-0410-9fdd-eb0c1a62fdaf
2007-08-27 12:46:29 +00:00

87 lines
4.3 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_02_Control_Permalink_updateLinks (t) {
t.plan( 2 );
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);
if (!map.getCenter()) map.zoomToMaxExtent();
map.addControl(control);
map.pan(5, 0);
if (/MSIE/.test(navigator.userAgent)) {
t.eq(OpenLayers.Util.getElement('permalink').href, "?lat=0&lon=1.75781&zoom=2&layers=B", "Panning sets permalink");
} else {
t.eq(OpenLayers.Util.getElement('permalink').href, location+"?lat=0&lon=1.75781&zoom=2&layers=B", "Panning 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>