layers have 'attribution' set.) git-svn-id: http://svn.openlayers.org/trunk/openlayers@4334 dc9f47b5-9b13-0410-9fdd-eb0c1a62fdaf
587 lines
25 KiB
HTML
587 lines
25 KiB
HTML
<html>
|
|
<head>
|
|
<script src="../lib/OpenLayers.js"></script>
|
|
<script type="text/javascript">
|
|
|
|
var isMozilla = (navigator.userAgent.indexOf("compatible") == -1);
|
|
var map;
|
|
|
|
function test_01_Map_constructor (t) {
|
|
t.plan( 10 );
|
|
|
|
map = new OpenLayers.Map('map');
|
|
var baseLayer = new OpenLayers.Layer.WMS("Test Layer",
|
|
"http://octo.metacarta.com/cgi-bin/mapserv?",
|
|
{map: "/mapdata/vmap_wms.map", layers: "basic"});
|
|
map.addLayer(baseLayer);
|
|
|
|
t.ok( map instanceof OpenLayers.Map, "new OpenLayers.Map returns object" );
|
|
if (!isMozilla) {
|
|
t.ok( true, "skipping element test outside of Mozilla");
|
|
t.ok( true, "skipping element test outside of Mozilla");
|
|
t.ok( true, "skipping element test outside of Mozilla");
|
|
} else {
|
|
t.ok( map.div instanceof HTMLDivElement, "map.div is an HTMLDivElement" );
|
|
t.ok( map.viewPortDiv instanceof HTMLDivElement, "map.viewPortDiv is an HTMLDivElement" );
|
|
t.ok( map.layerContainerDiv instanceof HTMLDivElement, "map.layerContainerDiv is an HTMLDivElement" );
|
|
}
|
|
t.ok( map.layers instanceof Array, "map.layers is an Array" );
|
|
t.ok( map.controls instanceof Array, "map.controls is an Array" );
|
|
t.eq( map.controls.length, 4, "Default map has 4 controls." );
|
|
t.ok( map.events instanceof OpenLayers.Events, "map.events is an OpenLayers.Events" );
|
|
t.ok( map.getMaxExtent() instanceof OpenLayers.Bounds, "map.maxExtent is an OpenLayers.Bounds" );
|
|
t.ok( map.getNumZoomLevels() > 0, "map has a default numZoomLevels" );
|
|
}
|
|
|
|
function test_02_Map_center(t) {
|
|
t.plan(3);
|
|
map = new OpenLayers.Map('map');
|
|
var baseLayer = new OpenLayers.Layer.WMS("Test Layer",
|
|
"http://octo.metacarta.com/cgi-bin/mapserv?",
|
|
{map: "/mapdata/vmap_wms.map", layers: "basic"});
|
|
map.addLayer(baseLayer);
|
|
var ll = new OpenLayers.LonLat(2,1);
|
|
map.setCenter(ll, 0);
|
|
t.ok( map.getCenter() instanceof OpenLayers.LonLat, "map.getCenter returns a LonLat");
|
|
t.eq( map.getZoom(), 0, "map.zoom is correct after calling setCenter");
|
|
t.ok( map.getCenter().equals(ll), "map center is correct after calling setCenter");
|
|
}
|
|
|
|
function test_03_Map_add_layers(t) {
|
|
t.plan(6);
|
|
map = new OpenLayers.Map('map');
|
|
var layer1 = new OpenLayers.Layer.WMS("Layer 1",
|
|
"http://octo.metacarta.com/cgi-bin/mapserv?",
|
|
{map: "/mapdata/vmap_wms.map", layers: "basic"});
|
|
var layer2 = new OpenLayers.Layer.WMS("Layer 2",
|
|
"http://wms.jpl.nasa.gov/wms.cgi", {layers: "modis,global_mosaic"});
|
|
// this uses map.addLayer internally
|
|
map.addLayers([layer1, layer2])
|
|
t.eq( map.layers.length, 2, "map has exactly two layers" );
|
|
t.ok( map.layers[0] === layer1, "1st layer is layer1" );
|
|
t.ok( map.layers[1] === layer2, "2nd layer is layer2" );
|
|
t.ok( layer1.map === map, "layer.map is map" );
|
|
t.eq( parseInt(layer1.div.style.zIndex), map.Z_INDEX_BASE['BaseLayer'],
|
|
"layer1 zIndex is set" );
|
|
t.eq( parseInt(layer2.div.style.zIndex), map.Z_INDEX_BASE['BaseLayer'] + 5,
|
|
"layer2 zIndex is set" );
|
|
}
|
|
|
|
function test_04_Map_options(t) {
|
|
t.plan(3);
|
|
map = new OpenLayers.Map('map', {numZoomLevels: 6, maxResolution: 3.14159, theme: 'foo'});
|
|
t.eq( map.numZoomLevels, 6, "map.numZoomLevels set correctly via options hashtable" );
|
|
t.eq( map.maxResolution, 3.14159, "map.maxResolution set correctly via options hashtable" );
|
|
t.eq( map.theme, 'foo', "map theme set correctly." );
|
|
}
|
|
|
|
function test_05_Map_center(t) {
|
|
t.plan(4);
|
|
map = new OpenLayers.Map('map');
|
|
var baseLayer = new OpenLayers.Layer.WMS("Test Layer",
|
|
"http://octo.metacarta.com/cgi-bin/mapserv?",
|
|
{map: "/mapdata/vmap_wms.map", layers: "basic"} );
|
|
map.addLayer(baseLayer);
|
|
var ll = new OpenLayers.LonLat(2,1);
|
|
map.setCenter(ll, 0);
|
|
map.zoomIn();
|
|
t.eq( map.getZoom(), 1, "map.zoom is correct after calling setCenter,zoom in");
|
|
t.ok( map.getCenter().equals(ll), "map center is correct after calling setCenter, zoom in");
|
|
map.zoomOut();
|
|
t.eq( map.getZoom(), 0, "map.zoom is correct after calling setCenter,zoom in, zoom out");
|
|
|
|
map.zoomTo(5);
|
|
t.eq( map.getZoom(), 5, "map.zoom is correct after calling zoomTo" );
|
|
|
|
/**
|
|
map.zoomToMaxExtent();
|
|
t.eq( map.getZoom(), 2, "map.zoom is correct after calling zoomToMaxExtent" );
|
|
var lonlat = map.getCenter();
|
|
var zero = new OpenLayers.LonLat(0, 0);
|
|
t.ok( lonlat.equals(zero), "map center is correct after calling zoomToFullExtent" );
|
|
*/
|
|
|
|
}
|
|
|
|
function test_06_Map_zoomend_event (t) {
|
|
t.plan(2);
|
|
|
|
map = new OpenLayers.Map('map');
|
|
var baseLayer = new OpenLayers.Layer.WMS("Test Layer",
|
|
"http://octo.metacarta.com/cgi-bin/mapserv?",
|
|
{map: "/mapdata/vmap_wms.map", layers: "basic"});
|
|
map.addLayer(baseLayer);
|
|
map.events.register("zoomend", {count: 0}, function() {
|
|
this.count++;
|
|
t.ok(true, "zoomend event was triggered " + this.count + " times");
|
|
});
|
|
map.setCenter(new OpenLayers.LonLat(2, 1), 0);
|
|
map.zoomIn();
|
|
map.zoomOut();
|
|
}
|
|
|
|
function test_07_Map_add_remove_popup (t) {
|
|
t.plan(4);
|
|
|
|
map = new OpenLayers.Map('map');
|
|
var baseLayer = new OpenLayers.Layer.WMS("Test Layer",
|
|
"http://octo.metacarta.com/cgi-bin/mapserv?",
|
|
{map: "/mapdata/vmap_wms.map", layers: "basic"});
|
|
map.addLayer(baseLayer);
|
|
|
|
var popup = new OpenLayers.Popup("chicken",
|
|
new OpenLayers.LonLat(0,0),
|
|
new OpenLayers.Size(200,200));
|
|
map.setCenter(new OpenLayers.LonLat(0, 0), 0);
|
|
|
|
map.addPopup(popup);
|
|
var pIndex = OpenLayers.Util.indexOf(map.popups, popup);
|
|
t.eq(pIndex, 0, "popup successfully added to Map's internal popups array");
|
|
|
|
var nodes = map.layerContainerDiv.childNodes;
|
|
|
|
var found = false;
|
|
for (var i=0; i < nodes.length; i++) {
|
|
if (nodes.item(i) == popup.div) {
|
|
found = true;
|
|
break;
|
|
}
|
|
}
|
|
t.ok(found, "popup.div successfully added to the map's viewPort");
|
|
|
|
|
|
map.removePopup(popup);
|
|
var pIndex = OpenLayers.Util.indexOf(map.popups, popup);
|
|
t.eq(pIndex, -1, "popup successfully removed from Map's internal popups array");
|
|
|
|
var found = false;
|
|
for (var i=0; i < nodes.length; i++) {
|
|
if (nodes.item(i) == popup.div) {
|
|
found = true;
|
|
break;
|
|
}
|
|
}
|
|
t.ok(!found, "popup.div successfully removed from the map's viewPort");
|
|
};
|
|
|
|
/*** THIS IS A GOOD TEST, BUT IT SHOULD BE MOVED TO WMS.
|
|
* Also, it won't work until we figure out the viewSize bug
|
|
|
|
function 08_Map_px_lonlat_translation (t) {
|
|
t.plan( 6 );
|
|
map = new OpenLayers.Map('map');
|
|
var baseLayer = new OpenLayers.Layer.WMS("Test Layer",
|
|
"http://octo.metacarta.com/cgi-bin/mapserv?",
|
|
{map: "/mapdata/vmap_wms.map", layers: "basic"});
|
|
map.addLayer(baseLayer);
|
|
map.setCenter(new OpenLayers.LonLat(0, 0), 0);
|
|
|
|
var pixel = new OpenLayers.Pixel(50,150);
|
|
var lonlat = map.getLonLatFromViewPortPx(pixel);
|
|
t.ok( lonlat instanceof OpenLayers.LonLat, "getLonLatFromViewPortPx returns valid OpenLayers.LonLat" );
|
|
|
|
var newPixel = map.getViewPortPxFromLonLat(lonlat);
|
|
t.ok( newPixel instanceof OpenLayers.Pixel, "getViewPortPxFromLonLat returns valid OpenLayers.Pixel" );
|
|
|
|
// WARNING!!! I'm faily sure that the following test's validity
|
|
// depends highly on rounding and the resolution. For now,
|
|
// in the default case, it seems to work. This may not
|
|
// always be so.
|
|
t.ok( newPixel.equals(pixel), "Translation to pixel and back to lonlat is consistent");
|
|
|
|
lonlat = map.getLonLatFromPixel(pixel);
|
|
t.ok( lonlat instanceof OpenLayers.LonLat, "getLonLatFromPixel returns valid OpenLayers.LonLat" );
|
|
|
|
newPixel = map.getPixelFromLonLat(lonlat);
|
|
t.ok( newPixel instanceof OpenLayers.Pixel, "getPixelFromLonLat returns valid OpenLayers.Pixel" );
|
|
|
|
t.ok( newPixel.equals(pixel), "2nd translation to pixel and back to lonlat is consistent");
|
|
}
|
|
*/
|
|
|
|
function test_09_Map_isValidLonLat(t) {
|
|
t.plan( 3 );
|
|
|
|
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'},
|
|
{maxExtent: new OpenLayers.Bounds(33861, 717605, 330846, 1019656), maxResolution: 296985/1024, projection:"EPSG:2805" } );
|
|
map.addLayer(layer);
|
|
|
|
t.ok( !map.isValidLonLat(null), "null lonlat is not valid" );
|
|
t.ok( map.isValidLonLat(new OpenLayers.LonLat(33862, 717606)), "lonlat outside max extent is valid" );
|
|
t.ok( !map.isValidLonLat(new OpenLayers.LonLat(10, 10)), "lonlat outside max extent is not valid" );
|
|
}
|
|
|
|
function test_10_Map_getLayer(t) {
|
|
t.plan( 2 );
|
|
|
|
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'},
|
|
{maxExtent: new OpenLayers.Bounds(33861, 717605, 330846, 1019656), maxResolution: 296985/1024, projection:"EPSG:2805" } );
|
|
|
|
map.addLayer(layer);
|
|
var gotLayer = map.getLayer(layer.id);
|
|
|
|
t.ok( layer == gotLayer, "getLayer correctly returns layer" );
|
|
|
|
gotLayer = map.getLayer("chicken");
|
|
|
|
t.ok( gotLayer == null, "getLayer correctly returns null when layer not found");
|
|
}
|
|
|
|
function test_11_Map_double_addLayer(t) {
|
|
t.plan( 1 );
|
|
|
|
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.addLayers([layer,layer]);
|
|
|
|
t.eq( map.layers.length, 1, "Map does not allow double adding of layers." );
|
|
|
|
}
|
|
|
|
function test_12_Map_setBaseLayer(t) {
|
|
t.plan( 4 );
|
|
|
|
map = new OpenLayers.Map('map');
|
|
|
|
var wmslayer = new OpenLayers.Layer.WMS('Test Layer',
|
|
"http://octo.metacarta.com/cgi-bin/mapserv",
|
|
{map: '/mapdata/vmap_wms.map', layers: 'basic', format: 'image/jpeg'},
|
|
{maxExtent: new OpenLayers.Bounds(33861, 717605, 330846, 1019656), maxResolution: 296985/1024, projection:"EPSG:2805" } );
|
|
|
|
var wmslayer2 = new OpenLayers.Layer.WMS('Test Layer2',
|
|
"http://octo.metacarta.com/cgi-bin/mapserv",
|
|
{map: '/mapdata/vmap_wms.map', layers: 'basic', format: 'image/jpeg'},
|
|
{maxExtent: new OpenLayers.Bounds(33861, 717605, 330846, 1019656), maxResolution: 296985/1024, projection:"EPSG:2805" } );
|
|
|
|
map.addLayers([wmslayer, wmslayer2]);
|
|
|
|
t.ok(map.baseLayer == wmslayer, "default base layer is first one added");
|
|
|
|
map.setBaseLayer(null);
|
|
t.ok(map.baseLayer == wmslayer, "setBaseLayer on null object does nothing (and does not break)");
|
|
|
|
map.setBaseLayer("chicken");
|
|
t.ok(map.baseLayer == wmslayer, "setBaseLayer on non-layer object does nothing (and does not break)");
|
|
|
|
map.setBaseLayer(wmslayer2);
|
|
t.ok(map.baseLayer == wmslayer2, "setbaselayer correctly sets 'baseLayer' property");
|
|
}
|
|
|
|
function test_13_Map_setBaseLayer_after_pan (t) {
|
|
t.plan(1);
|
|
|
|
map = new OpenLayers.Map('map');
|
|
var wmsLayer = new OpenLayers.Layer.WMS( "OpenLayers WMS",
|
|
"http://labs.metacarta.com/wms/vmap0", {layers: 'basic'} );
|
|
var tmsLayer = new OpenLayers.Layer.TMS("TMS",
|
|
"http://labs.metacarta.com/wms-c/Basic.py/",
|
|
{'layername':'basic', 'type':'png'});
|
|
map.addLayers([wmsLayer,tmsLayer]);
|
|
map.setBaseLayer(wmsLayer);
|
|
map.zoomToMaxExtent();
|
|
map.setBaseLayer(tmsLayer);
|
|
map.zoomIn();
|
|
map.pan(0, -200);
|
|
map.setBaseLayer(wmsLayer);
|
|
t.eq(map.layerContainerDiv.style.top, "0px", "layerContainer is recentered after setBaseLayer");
|
|
}
|
|
|
|
function test_14_Map_moveLayer (t) {
|
|
t.plan(10);
|
|
|
|
var ct = 0;
|
|
map = new OpenLayers.Map('map');
|
|
var wmslayer = new OpenLayers.Layer.WMS('Test Layer',
|
|
"http://octo.metacarta.com/cgi-bin/mapserv",
|
|
{map: '/mapdata/vmap_wms.map', layers: 'basic', format: 'image/jpeg'},
|
|
{maxExtent: new OpenLayers.Bounds(33861, 717605, 330846, 1019656), maxResolution: 296985/1024, projection:"EPSG:2805" } );
|
|
|
|
var wmslayer2 = new OpenLayers.Layer.WMS('Test Layer2',
|
|
"http://octo.metacarta.com/cgi-bin/mapserv",
|
|
{map: '/mapdata/vmap_wms.map', layers: 'basic', format: 'image/jpeg'},
|
|
{maxExtent: new OpenLayers.Bounds(33861, 717605, 330846, 1019656), maxResolution: 296985/1024, projection:"EPSG:2805" } );
|
|
|
|
var wmslayer3 = new OpenLayers.Layer.WMS('Test Layer2',
|
|
"http://octo.metacarta.com/cgi-bin/mapserv",
|
|
{map: '/mapdata/vmap_wms.map', layers: 'basic', format: 'image/jpeg'},
|
|
{maxExtent: new OpenLayers.Bounds(33861, 717605, 330846, 1019656), maxResolution: 296985/1024, projection:"EPSG:2805" } );
|
|
|
|
map.addLayers([wmslayer, wmslayer2, wmslayer3]);
|
|
map.events.register("changelayer", map, function (e) { ct++; });
|
|
t.eq( map.getNumLayers(), 3, "getNumLayers returns the number of layers" );
|
|
t.eq( map.getLayerIndex(wmslayer3), 2, "getLayerIndex returns the right index" );
|
|
map.raiseLayer(wmslayer3, 1);
|
|
t.eq( map.getLayerIndex(wmslayer3), 2, "can't moveLayer up past the top of the stack" );
|
|
map.raiseLayer(wmslayer, -1);
|
|
t.eq( map.getLayerIndex(wmslayer), 0, "can't moveLayer down past the bottom of the stack" );
|
|
map.raiseLayer(wmslayer3, -1);
|
|
t.eq( map.getLayerIndex(wmslayer3), 1, "can moveLayer down from the top" );
|
|
t.eq( parseInt(wmslayer3.div.style.zIndex), map.Z_INDEX_BASE['BaseLayer'] + 5,
|
|
"layer div has the right zIndex after moving down" );
|
|
map.raiseLayer(wmslayer, 2);
|
|
t.eq( map.getLayerIndex(wmslayer), 2, "can moveLayer up from the bottom" );
|
|
t.eq( parseInt(wmslayer.div.style.zIndex), map.Z_INDEX_BASE['BaseLayer'] + 2 * 5,
|
|
"layer div has the right zIndex after moving up" );
|
|
t.eq( map.getLayerIndex(wmslayer3), 0, "top layer is now on the bottom" );
|
|
t.eq( ct, 3, "raiseLayer triggered changelayer the right # of times" );
|
|
}
|
|
|
|
function test_15_Map_setCenter(t) {
|
|
t.plan(1);
|
|
|
|
map = new OpenLayers.Map('map');
|
|
var baseLayer = new OpenLayers.Layer.WMS("Test Layer",
|
|
"http://octo.metacarta.com/cgi-bin/mapserv?",
|
|
{map: "/mapdata/vmap_wms.map", layers: "basic"},
|
|
{maxResolution: 'auto', maxExtent: new OpenLayers.Bounds(-10,-10,10,10)});
|
|
map.addLayer(baseLayer);
|
|
var ll = new OpenLayers.LonLat(-100,-150);
|
|
map.setCenter(ll, 0);
|
|
t.ok(map.getCenter().equals(new OpenLayers.LonLat(0,0)), "safely sets out-of-bounds lonlat");
|
|
}
|
|
|
|
function test_16_Map_defaultTheme(t) {
|
|
t.plan(5);
|
|
|
|
var links = document.getElementsByTagName('link');
|
|
map = new OpenLayers.Map('map');
|
|
var gotNodes = 0;
|
|
var themeNode = null;
|
|
for(var i=0; i<links.length; ++i) {
|
|
if(OpenLayers.Util.isEquivalentUrl(map.theme, links.item(i).href)) {
|
|
gotNodes += 1;
|
|
themeNode = links.item(i);
|
|
}
|
|
}
|
|
t.eq(gotNodes, 1, "by default, a single link node is added to document");
|
|
t.ok(themeNode != null, "a link node with the theme href was added");
|
|
t.eq(themeNode.rel, "stylesheet", "node added has rel set to stylesheet");
|
|
t.eq(themeNode.type, "text/css", "node added has type set to text/css");
|
|
|
|
// reconstruct the map to prove that another link is not added
|
|
map = new OpenLayers.Map('map');
|
|
t.eq(links.length, document.getElementsByTagName('link').length,
|
|
"calling the map constructor twice with the same theme doesn't add duplicate link nodes");
|
|
}
|
|
|
|
function test_17_Map_customTheme(t) {
|
|
t.plan(5);
|
|
|
|
var customTheme = 'foo';
|
|
var options = {theme: customTheme};
|
|
map = new OpenLayers.Map('map', options);
|
|
|
|
var links = document.getElementsByTagName('link');
|
|
var gotNodes = 0;
|
|
var themeNode = null;
|
|
for(var i=0; i<links.length; ++i) {
|
|
if(OpenLayers.Util.isEquivalentUrl(map.theme, links.item(i).href)) {
|
|
gotNodes += 1;
|
|
themeNode = links.item(i);
|
|
}
|
|
}
|
|
|
|
t.eq(map.theme, customTheme, "map theme is properly set");
|
|
t.eq(gotNodes, 1, "with custom theme, a single link node is added to document");
|
|
t.ok(themeNode != null, "a link node with the theme href was added");
|
|
t.eq(themeNode.rel, "stylesheet", "node added has rel set to stylesheet");
|
|
t.eq(themeNode.type, "text/css", "node added has type set to text/css");
|
|
}
|
|
|
|
function test_18_Map_noTheme(t) {
|
|
t.plan(1);
|
|
|
|
var head = document.getElementsByTagName('head')[0];
|
|
var nodeCount = head.childNodes.length;
|
|
|
|
var options = {theme: null};
|
|
map = new OpenLayers.Map('map', options);
|
|
|
|
t.eq(nodeCount, head.childNodes.length, "with no theme, a node is not added to document head" );
|
|
}
|
|
|
|
function test_19_Map_getControl(t) {
|
|
t.plan(2);
|
|
|
|
var map1 = new OpenLayers.Map('map');
|
|
|
|
var control = new OpenLayers.Control();
|
|
map1.addControl(control);
|
|
|
|
var gotControl = map1.getControl(control.id);
|
|
t.ok(gotControl == control, "got right control");
|
|
|
|
gotControl = map1.getControl("bogus id");
|
|
t.ok(gotControl == null, "getControl() for bad id returns null");
|
|
}
|
|
|
|
function test_19_Map_removeControl(t) {
|
|
t.plan(6);
|
|
|
|
var oldNumControls, newNumControls;
|
|
|
|
var map1 = new OpenLayers.Map('map');
|
|
oldNumControls = map1.controls.length;
|
|
|
|
var control = new OpenLayers.Control();
|
|
map1.addControl(control);
|
|
|
|
//add control
|
|
newNumControls = map1.controls.length;
|
|
t.ok( newNumControls = oldNumControls + 1, "adding a control increases control count")
|
|
|
|
var foundDiv = false;
|
|
for(var i=0; i < map1.viewPortDiv.childNodes.length; i++) {
|
|
var childNode = map1.viewPortDiv.childNodes[i];
|
|
if (childNode == control.div) {
|
|
foundDiv = true;
|
|
}
|
|
}
|
|
t.ok(foundDiv, "new control's div correctly added to viewPort");
|
|
|
|
//remove control
|
|
map1.removeControl(control)
|
|
newNumControls = map1.controls.length;
|
|
t.ok( newNumControls == oldNumControls, "removing the control decreases control count")
|
|
|
|
var gotControl = map1.getControl(control.id);
|
|
t.ok( gotControl == null, "control no longer in map's controls array");
|
|
|
|
var foundDiv = false;
|
|
for(var i=0; i < map1.viewPortDiv.childNodes.length; i++) {
|
|
var childNode = map1.viewPortDiv.childNodes[i];
|
|
if (childNode == control.div) {
|
|
foundDiv = true;
|
|
}
|
|
}
|
|
t.ok(!foundDiv, "control no longer child of viewPort");
|
|
|
|
//remove bogus
|
|
control = { id: "bogus id" };
|
|
map1.removeControl(control);
|
|
newNumControls = map1.controls.length;
|
|
t.ok( newNumControls == oldNumControls, "removing bad controlid doesnt crash or decrease control count")
|
|
}
|
|
|
|
function test_Map_restrictedExtent(t) {
|
|
t.plan(24);
|
|
var extent = new OpenLayers.Bounds(-180, -90, 180, 90);
|
|
var options = {
|
|
maxResolution: "auto"
|
|
};
|
|
var map = new OpenLayers.Map("map", options);
|
|
var layer = new OpenLayers.Layer.WMS(
|
|
"test",
|
|
"http://octo.metacarta.com/cgi-bin/mapserv?",
|
|
{map: "/mapdata/vmap_wms.map", layers: "basic"}
|
|
);
|
|
map.addLayer(layer);
|
|
map.zoomToMaxExtent();
|
|
var nw = new OpenLayers.LonLat(extent.left, extent.top);
|
|
var ne = new OpenLayers.LonLat(extent.right, extent.top);
|
|
var sw = new OpenLayers.LonLat(extent.left, extent.bottom);
|
|
var se = new OpenLayers.LonLat(extent.right, extent.bottom);
|
|
|
|
// try panning to northwest corner
|
|
map.setOptions({restrictedExtent: extent});
|
|
map.setCenter(nw, 0);
|
|
t.eq(map.getExtent().getCenterLonLat().toString(),
|
|
extent.getCenterLonLat().toString(),
|
|
"map extent properly restricted to northwest at zoom 0");
|
|
t.eq(map.zoom, 0, "zoom not restricted for nw, 0");
|
|
map.setCenter(nw, 5);
|
|
t.eq(map.getExtent().top, extent.top,
|
|
"map extent top properly restricted to northwest at zoom 5");
|
|
t.eq(map.getExtent().left, extent.left,
|
|
"map extent left properly restricted to northwest at zoom 5");
|
|
t.eq(map.zoom, 5, "zoom not restricted for nw, 5");
|
|
map.setOptions({restrictedExtent: null});
|
|
map.setCenter(nw, 0);
|
|
t.eq(map.getExtent().getCenterLonLat().toString(),
|
|
nw.toString(),
|
|
"map extent not restricted with null restrictedExtent for nw");
|
|
|
|
// try panning to northeast corner
|
|
map.setOptions({restrictedExtent: extent});
|
|
map.setCenter(ne, 0);
|
|
t.eq(map.getExtent().getCenterLonLat().toString(),
|
|
extent.getCenterLonLat().toString(),
|
|
"map extent properly restricted to northeast at zoom 0");
|
|
t.eq(map.zoom, 0, "zoom not restricted for ne, 0");
|
|
map.setCenter(ne, 5);
|
|
t.eq(map.getExtent().top, extent.top,
|
|
"map extent top properly restricted to northeast at zoom 5");
|
|
t.eq(map.getExtent().right, extent.right,
|
|
"map extent right properly restricted to northeast at zoom 5");
|
|
t.eq(map.zoom, 5, "zoom not restricted for ne, 5");
|
|
map.setOptions({restrictedExtent: null});
|
|
map.setCenter(ne, 0);
|
|
t.eq(map.getExtent().getCenterLonLat().toString(),
|
|
ne.toString(),
|
|
"map extent not restricted with null restrictedExtent for ne");
|
|
|
|
// try panning to southwest corner
|
|
map.setOptions({restrictedExtent: extent});
|
|
map.setCenter(sw, 0);
|
|
t.eq(map.getExtent().getCenterLonLat().toString(),
|
|
extent.getCenterLonLat().toString(),
|
|
"map extent properly restricted to southwest at zoom 0");
|
|
t.eq(map.zoom, 0, "zoom not restricted for sw, 0");
|
|
map.setCenter(sw, 5);
|
|
t.eq(map.getExtent().bottom, extent.bottom,
|
|
"map extent bottom properly restricted to southwest at zoom 5");
|
|
t.eq(map.getExtent().left, extent.left,
|
|
"map extent left properly restricted to southwest at zoom 5");
|
|
t.eq(map.zoom, 5, "zoom not restricted for sw, 5");
|
|
map.setOptions({restrictedExtent: null});
|
|
map.setCenter(sw, 0);
|
|
t.eq(map.getExtent().getCenterLonLat().toString(),
|
|
sw.toString(),
|
|
"map extent not restricted with null restrictedExtent for sw");
|
|
|
|
// try panning to southeast corner
|
|
map.setOptions({restrictedExtent: extent});
|
|
map.setCenter(se, 0);
|
|
t.eq(map.getExtent().getCenterLonLat().toString(),
|
|
extent.getCenterLonLat().toString(),
|
|
"map extent properly restricted to southeast at zoom 0");
|
|
t.eq(map.zoom, 0, "zoom not restricted for se, 0");
|
|
map.setCenter(se, 5);
|
|
t.eq(map.getExtent().bottom, extent.bottom,
|
|
"map extent bottom properly restricted to southeast at zoom 5");
|
|
t.eq(map.getExtent().right, extent.right,
|
|
"map extent right properly restricted to southeast at zoom 5");
|
|
t.eq(map.zoom, 5, "zoom not restricted for se, 5");
|
|
map.setOptions({restrictedExtent: null});
|
|
map.setCenter(se, 0);
|
|
t.eq(map.getExtent().getCenterLonLat().toString(),
|
|
se.toString(),
|
|
"map extent not restricted with null restrictedExtent for se");
|
|
}
|
|
|
|
function test_99_Map_destroy (t) {
|
|
t.plan( 3 );
|
|
map = new OpenLayers.Map('map');
|
|
map.destroy();
|
|
t.eq( map.layers, null, "map.layers is null after destroy" );
|
|
t.eq( map.controls, null, "map.controls is null after destroy" );
|
|
t.eq( map.viewPortDiv, null, "map's viewportDiv nullified");
|
|
}
|
|
|
|
</script>
|
|
</head>
|
|
<body>
|
|
<div id="map" style="width: 600px; height: 300px;"/>
|
|
</body>
|
|
</html>
|