git-svn-id: http://svn.openlayers.org/trunk/openlayers@1585 dc9f47b5-9b13-0410-9fdd-eb0c1a62fdaf
278 lines
12 KiB
HTML
278 lines
12 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( 9 );
|
|
|
|
map = new OpenLayers.Map('map'); // no longer need to call $(), constructor does it
|
|
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.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(2);
|
|
map = new OpenLayers.Map($('map'), {numZoomLevels: 6, maxResolution: 3.14159});
|
|
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" );
|
|
}
|
|
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);
|
|
t.eq(map.popups.indexOf(popup), 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);
|
|
t.eq(map.popups.indexOf(popup), -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_10_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_088_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_99_Map_destroy (t) {
|
|
t.plan( 2 );
|
|
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" );
|
|
}
|
|
// -->
|
|
</script>
|
|
</head>
|
|
<body>
|
|
<div id="map" style="width: 1080px; height: 600px;"/>
|
|
</body>
|
|
</html>
|