Merge vector-2.4 branch back to trunk.

svn merge sandbox/vector-2.4/@2307 sandbox/vector-2.4/@HEAD trunk/openlayers/


git-svn-id: http://svn.openlayers.org/trunk/openlayers@2803 dc9f47b5-9b13-0410-9fdd-eb0c1a62fdaf
This commit is contained in:
crschmidt
2007-03-16 13:23:56 +00:00
parent 8b9d974dc2
commit 3ca974acec
159 changed files with 10193 additions and 343 deletions
+114
View File
@@ -0,0 +1,114 @@
<html>
<head>
<script src="../../lib/OpenLayers.js"></script>
<script type="text/javascript"><!--
var isMozilla = (navigator.userAgent.indexOf("compatible") == -1);
var isOpera = (navigator.userAgent.indexOf("Opera") != -1);
var layer;
function test_01_Layer_EventPane_constructor (t) {
t.plan( 5 );
var layer = new OpenLayers.Layer.EventPane('Test Layer');
t.ok( layer instanceof OpenLayers.Layer.EventPane, "new OpenLayers.Layer.EventPane returns object" );
t.eq( layer.CLASS_NAME, "OpenLayers.Layer.EventPane", "CLASS_NAME variable set correctly");
t.eq( layer.name, "Test Layer", "layer.name is correct" );
t.eq( layer.isBaseLayer, true, "EventPane layer is always base layer" );
if (!isMozilla) {
t.ok( true, "skipping element test outside of Mozilla");
} else {
t.ok( layer.pane instanceof HTMLDivElement, "layer.pane is an HTMLDivElement" );
}
}
function test_02_Layer_EventPane_clone (t) {
t.plan( 1 );
t.ok( true, "need to actually write some tests here" );
return;
/// FIX ME FIX ME: fix this later
var map = new OpenLayers.Map('map');
var options = { chicken: 151, foo: "bar" };
var layer = new OpenLayers.Layer('Test Layer', options);
map.addLayer(layer);
// randomly assigned property
layer.chocolate = 5;
var clone = layer.clone();
t.ok( clone instanceof OpenLayers.Layer, "new OpenLayers.Layer returns object" );
t.eq( clone.name, "Test Layer", "default clone.name is correct" );
t.ok( ((clone.options["chicken"] == 151) && (clone.options["foo"] == "bar")), "clone.options correctly set" );
t.eq(clone.chocolate, 5, "correctly copied randomly assigned property");
layer.addOptions({chicken:152});
t.eq(clone.options["chicken"], 151, "made a clean copy of options");
t.ok( clone.map == null, "cloned layer has map property set to null")
}
function test_10_Layer_EventPane_setMap (t) {
// MOUSEMOVE test does not seem to work...
// t.plan( 2 );
if (!isMozilla || isOpera) {
t.plan(4);
} else {
t.plan(3);
}
var map = new OpenLayers.Map('map');
layer = new OpenLayers.Layer.EventPane('Test Layer');
//give dummy function so test wont bomb on layer.setMap()
layer.loadMapObject = function() { };
layer.getWarningHTML = function() { this.warning = true; return ""; };
map.addLayer(layer);
t.eq( parseInt(layer.pane.style.zIndex) - parseInt(layer.div.style.zIndex),
1, "layer pane is 1 z-level above its div" );
t.ok( layer.warning, "warning correctly registered on no mapObject load" );
layer2 = new OpenLayers.Layer.EventPane('Test Layer');
//give dummy function so test wont bomb on layer.setMap()
layer2.loadMapObject = function() { this.mapObject = new Object(); };
layer2.getWarningHTML = function() { this.warning = true; return ""; }
map.addLayer(layer2);
t.ok( !layer2.warning, "warning not registered on mapObject load" );
map.events.register("mousemove", map, function () {
t.ok(true, "got mouse move");
});
if( document.createEvent ) { // Mozilla
var evObj = document.createEvent('MouseEvents');
evObj.initEvent( 'mousemove', true, false );
layer.pane.dispatchEvent(evObj);
} else if( document.createEventObject ) { // IE
layer.pane.fireEvent('onmousemove');
}
}
function test_20_Layer_EventPane_setVisibility (t) {
t.plan( 2 );
layer = new OpenLayers.Layer.EventPane('Test Layer');
layer.setVisibility(false);
t.eq(layer.visibility, false, "layer pane is now invisible");
layer.setVisibility(true);
t.eq(layer.visibility, true, "layer pane is now visible");
}
// -->
</script>
</head>
<body>
<div id="map" style="height:500px;width:500px"></div>
</body>
</html>
+97
View File
@@ -0,0 +1,97 @@
<html>
<head>
<script src="../../lib/OpenLayers.js"></script>
<script type="text/javascript"><!--
var layer;
function test_01_Layer_FixedZoomLevels (t) {
t.plan( 36 );
var layer = { 'MIN_ZOOM_LEVEL': 5,
'MAX_ZOOM_LEVEL': 10 };
//defaults
layer = p_createLayer(layer);
p_minMaxNum(t, layer, layer.MIN_ZOOM_LEVEL, layer.MAX_ZOOM_LEVEL, "nothing specified");
//layer.options
// min,num
layer = p_createLayer(layer, {}, { minZoomLevel: 3, numZoomLevels: 12});
p_minMaxNum(t, layer, layer.MIN_ZOOM_LEVEL, layer.MAX_ZOOM_LEVEL, "min too low num too high(layer.options)");
layer = p_createLayer(layer, {}, { minZoomLevel: 6, numZoomLevels: 3 });
p_minMaxNum(t, layer, 6, 8, "valid min,num(layer.options)");
// max
layer = p_createLayer(layer, {}, { maxZoomLevel: 9 });
p_minMaxNum(t, layer, layer.MIN_ZOOM_LEVEL, 9, "valid max(layer.options)");
layer = p_createLayer(layer, {}, { maxZoomLevel: 12 });
p_minMaxNum(t, layer, layer.MIN_ZOOM_LEVEL, layer.MAX_ZOOM_LEVEL, "invalid max(layer.options)");
//map
// min,num
layer = p_createLayer(layer, { minZoomLevel: 3, numZoomLevels: 12});
p_minMaxNum(t, layer, layer.MIN_ZOOM_LEVEL, layer.MAX_ZOOM_LEVEL, "min too low num too high(map)");
layer = p_createLayer(layer, { minZoomLevel: 6, numZoomLevels: 3 });
p_minMaxNum(t, layer, 6, 8, "valid min,num(map)");
// max
layer = p_createLayer(layer, { maxZoomLevel: 9 });
p_minMaxNum(t, layer, layer.MIN_ZOOM_LEVEL, 9, "valid max(map)");
layer = p_createLayer(layer, { maxZoomLevel: 12 });
p_minMaxNum(t, layer, layer.MIN_ZOOM_LEVEL, layer.MAX_ZOOM_LEVEL, "invalid max(map)");
//map vs. options
layer = p_createLayer(layer, {minZoomLevel: 6, numZoomLevels: 2}, { minZoomLevel: 7, numZoomLevels: 3});
p_minMaxNum(t, layer, 7, 9, "min,num(layer.options) wins over (map)");
layer = p_createLayer(layer, {minZoomLevel: 6, maxZoomLevel: 8}, { minZoomLevel: 7, maxZoomLevel: 9});
p_minMaxNum(t, layer, 7, 9, "min,max(layer.options) wins over (map)");
// numZoomLevels vs. maxZoomLevel
layer = p_createLayer(layer, {maxZoomLevel: 8, numZoomLevels: 6});
p_minMaxNum(t, layer, layer.MIN_ZOOM_LEVEL, 10, "min,max(layer.options) wins over (map)");
}
function p_createLayer(layer, mapOptions, layerOptions) {
layer.map = mapOptions || {};
layer.options = layerOptions || {};
OpenLayers.Layer.FixedZoomLevels.prototype.initResolutions.apply(layer);
return layer;
}
function p_minMaxNum(t, layer, min, max, msg) {
t.eq( layer.minZoomLevel, min, "min zoom level inherited from layer constant: " + msg);
t.eq( layer.maxZoomLevel, max, "max zoom level inherited from layer constant: " + msg);
t.eq( layer.numZoomLevels, max - min + 1, "num zoom levels correctly calcuated: " + msg);
}
// -->
</script>
</head>
<body>
<div id="map"></div>
</body>
</html>
+23
View File
@@ -0,0 +1,23 @@
<html>
<head>
<script src="../../lib/OpenLayers.js"></script>
<script type="text/javascript"><!--
var name = "GML Layer";
function test_01_Layer_GML_constructor(t) {
t.plan(3);
var layer = new OpenLayers.Layer.GML(name);
t.ok(layer instanceof OpenLayers.Layer.GML, "new OpenLayers.Layer.GML returns correct object" );
t.eq(layer.name, name, "layer name is correctly set");
t.ok(layer.renderer.CLASS_NAME, "layer has a renderer");
}
</script>
</head>
<body>
<div id="map" style="width:500px;height:550px"></div>
</body>
</html>
+89
View File
@@ -0,0 +1,89 @@
<html>
<head>
<script src="../../lib/OpenLayers.js"></script>
<script type="text/javascript"><!--
var isMozilla = (navigator.userAgent.indexOf("compatible") == -1);
var layer;
function test_01_Layer_GeoRSS_constructor (t) {
t.plan( 5 );
layer = new OpenLayers.Layer.GeoRSS('Test Layer', "./georss.txt" );
t.ok( layer instanceof OpenLayers.Layer.GeoRSS, "new OpenLayers.Layer.GeoRSS returns object" );
t.eq( layer.location, "./georss.txt", "layer.location is correct" );
var markers;
t.delay_call( 1, function() {
t.eq( layer.markers.length, 40, "marker length is correct" );
var ll = new OpenLayers.LonLat(-71.142197, 42.405696);
t.ok( layer.markers[0].lonlat.equals(ll), "lonlat on first marker is correct" );
t.eq( layer.name, "Crschmidt's Places At Platial", "Layer name is correct." );
} );
}
function test_01_Layer_GeoRSS_AtomParsing (t) {
t.plan( 6 );
layer = new OpenLayers.Layer.GeoRSS('Test Layer', "./atom-1.0.xml" );
t.ok( layer instanceof OpenLayers.Layer.GeoRSS, "new OpenLayers.Layer.GeoRSS returns object" );
t.eq( layer.location, "./atom-1.0.xml", "layer.location is correct" );
var markers;
t.delay_call( 1, function() {
t.eq( layer.markers.length, 2, "marker length is correct" );
var ll = new OpenLayers.LonLat(29.9805, 36.7702);
t.ok( layer.markers[0].lonlat.equals(ll), "lonlat on first marker is correct" );
t.like( layer.features[0].data['popupContentHTML'], '<a class="link" href="http://pleiades.stoa.org/places/638896" target="_blank">Unnamed Tumulus</a>', "Link is correct.");
t.eq( layer.name, "tumulus", "Layer name is correct." );
} );
}
function test_02_Layer_GeoRSS_draw (t) {
// t.plan(5);
t.plan( 2 );
layer = new OpenLayers.Layer.GeoRSS('Test Layer', './georss.txt');
t.ok( layer instanceof OpenLayers.Layer.GeoRSS, "new OpenLayers.Layer.GeoRSS returns object" );
var 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.addLayer(layer);
t.delay_call( 1, function() {
map.setCenter(new OpenLayers.LonLat(0,0),0);
t.eq( map.layers[1].name, layer.name, "Layer name is correct" );
});;
}
function test_03_Layer_GeoRSS_events (t) {
t.plan( 4 );
layer = new OpenLayers.Layer.GeoRSS('Test Layer', './georss.txt');
var 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.addLayer(layer);
map.setCenter(new OpenLayers.LonLat(0,0),0);
var event = {};
t.delay_call( 1, function() {
t.ok(layer.markers[0].events, "First marker has an events object");
t.eq(layer.markers[0].events.listeners['click'].length, 1, "Marker events has one object");
layer.markers[0].events.triggerEvent('click', event);
t.eq(map.popups.length, 1, "Popup opened correctly");
layer.markers[1].events.triggerEvent('click', event);
t.eq(map.popups.length, 1, "1st popup gone, 2nd Popup opened correctly");
});
}
function test_99_Layer_GeoRSS_destroy (t) {
t.plan( 1 );
layer = new OpenLayers.Layer.GeoRSS('Test Layer', './georss.txt');
var map = new OpenLayers.Map('map');
map.addLayer(layer);
layer.destroy();
t.eq( layer.map, null, "layer.map is null after destroy" );
}
// -->
</script>
</head>
<body>
<div id="map" style="width:500px; height:500px"></div>
</body>
</html>
+105
View File
@@ -0,0 +1,105 @@
<html>
<head>
<!-- this gmaps key generated for http://openlayers.org/dev/ -->
<script src='http://maps.google.com/maps?file=api&amp;v=2&amp;key=ABQIAAAA9XNhd8q0UdwNC7YSO4YZghSPUCi5aRYVveCcVYxzezM4iaj_gxQ9t-UajFL70jfcpquH5l1IJ-Zyyw'></script>
<script src="../../lib/OpenLayers.js"></script>
<script type="text/javascript"><!--
var layer;
function test_01_Layer_Google_constructor (t) {
t.plan( 4 );
var map = new OpenLayers.Map('map');
var layer = new OpenLayers.Layer.Google('Goog Layer');
map.addLayer(layer);
t.ok( layer instanceof OpenLayers.Layer.Google, "new OpenLayers.Layer.Google returns object" );
t.eq( layer.CLASS_NAME, "OpenLayers.Layer.Google", "CLASS_NAME variable set correctly");
t.eq( layer.name, "Goog Layer", "layer.name is correct" );
t.ok ( layer.mapObject != null, "GMap2 Object correctly loaded");
}
function test_02_Layer_Google_isBaseLayer (t) {
t.plan(1);
var layer = new OpenLayers.Layer.Google('Goog Layer');
t.ok(layer.isBaseLayer, "a default load of google layer responds as a base layer");
}
function test_03_Layer_Google_Translation_lonlat (t) {
t.plan( 4 );
var map = new OpenLayers.Map('map');
var layer = new OpenLayers.Layer.Google('Goog Layer');
map.addLayer(layer);
// these two lines specify an appropriate translation.
// the code afterwards works by itself to test that translation
// works correctly both ways.
var gLatLng = new GLatLng(50,100);
var correspondingOLLonLat = new OpenLayers.LonLat(100,50);
olLonLat = layer.getOLLonLatFromMapObjectLonLat(gLatLng);
t.ok(olLonLat.equals(correspondingOLLonLat), "Translation from GLatLng to OpenLayers.LonLat works");
var transGLatLng = layer.getMapObjectLonLatFromOLLonLat(olLonLat);
t.ok( transGLatLng.equals(gLatLng), "Translation from OpenLayers.LonLat to GLatLng works");
t.ok( layer.getMapObjectLonLatFromOLLonLat(null) == null, "getGLatLngFromOLLonLat(null) returns null");
t.ok( layer.getOLLonLatFromMapObjectLonLat(null) == null, "getOLLonLatFromGLatLng(null) returns null");
}
function test_04_Layer_Google_Translation_pixel (t) {
t.plan( 4 );
var map = new OpenLayers.Map('map');
var layer = new OpenLayers.Layer.Google('Goog Layer');
map.addLayer(layer);
// these two lines specify an appropriate translation.
// the code afterwards works by itself to test that translation
// works correctly both ways.
var gPoint = new GPoint(50,100);
var correspondingOLPixel = new OpenLayers.Pixel(50, 100);
olPixel = layer.getOLPixelFromMapObjectPixel(gPoint);
t.ok( olPixel.equals(correspondingOLPixel), "Translation from GPoint to OpenLayers.Pixel works");
var transGPoint = layer.getMapObjectPixelFromOLPixel(olPixel);
t.ok( transGPoint.equals(gPoint), "Translation from OpenLayers.Pixel to GPoint works");
t.ok( layer.getMapObjectPixelFromOLPixel(null) == null, "getGPointFromOLPixel(null) returns null");
t.ok( layer.getOLPixelFromMapObjectPixel(null) == null, "getOLPixelFromGPoint(null) returns null");
}
function test_99_Layer_destroy (t) {
t.plan( 5 );
var map = new OpenLayers.Map('map');
layer = new OpenLayers.Layer.Google('Test Layer');
map.addLayer(layer);
layer.destroy();
t.eq( layer.name, null, "layer.name is null after destroy" );
t.eq( layer.div, null, "layer.div is null after destroy" );
t.eq( layer.map, null, "layer.map is null after destroy" );
t.eq( layer.options, null, "layer.options is null after destroy" );
t.eq( layer.gmap, null, "layer.gmap is null after destroy" );
}
// -->
</script>
</head>
<body>
<div id="map"></div>
</body>
</html>
+206
View File
@@ -0,0 +1,206 @@
<html>
<head>
<script src="../../lib/OpenLayers.js"></script>
<script type="text/javascript"><!--
var isMozilla = (navigator.userAgent.indexOf("compatible") == -1);
var layer;
var name = 'Test Layer';
var url = "http://octo.metacarta.com/cgi-bin/mapserv";
var params = { map: '/mapdata/vmap_wms.map',
layers: 'basic',
format: 'image/png'};
/**
* NOTE TO READER:
*
* Some of the tests on the Grid class actually use the WMS class.
* This is because WMS is a subclass of Grid and it implements the
* core functions which are necessary to test the tile-generation
* mechanism.
*
*/
function test_01_Layer_Grid_constructor (t) {
t.plan( 1 );
layer = new OpenLayers.Layer.Grid(name, url, params, null);
t.ok( layer instanceof OpenLayers.Layer.Grid, "returns OpenLayers.Layer.Grid object" );
}
function test_02_Layer_Grid_inittiles (t) {
t.plan( 2 );
var map = new OpenLayers.Map('map');
layer = new OpenLayers.Layer.WMS(name, url, params);
map.addLayer(layer);
map.setCenter(new OpenLayers.LonLat(0,0),5);
t.eq( layer.grid.length, 7, "Grid rows is correct." );
t.eq( layer.grid[0].length, 6, "Grid cols is correct." );
}
function test_03_Layer_Grid_clearTiles (t) {
t.plan(1);
var map = new OpenLayers.Map('map');
layer = new OpenLayers.Layer.WMS(name, url, params);
map.addLayer(layer);
map.setCenter(new OpenLayers.LonLat(0,0));
//grab a reference to one of the tiles
var tile = layer.grid[0][0];
layer.clearGrid();
t.ok( layer.grid != null, "layer.grid does not get nullified" );
}
function test_04_Layer_Grid_getGridBounds(t) {
t.plan( 1 );
layer = new OpenLayers.Layer.WMS(name, url, params);
var bl = { bounds: new OpenLayers.Bounds(1,2,0,0)};
var tr = { bounds: new OpenLayers.Bounds(0,0,3,4)};
layer.grid = [ [6, tr],
[bl, 7]];
var bounds = layer.getGridBounds();
var testBounds = new OpenLayers.Bounds(1,2,3,4);
t.ok( bounds.equals(testBounds), "getGridBounds() returns correct bounds")
layer.grid = null;
}
function test_05_Layer_Grid_getResolution(t) {
t.plan( 1 );
var map = new OpenLayers.Map('map');
layer = new OpenLayers.Layer.WMS(name, url, params);
map.addLayer(layer);
map.zoom = 5;
t.eq( layer.getResolution(), 0.0439453125, "getResolution() returns correct value");
}
function test_06_Layer_Grid_getZoomForExtent(t) {
t.plan( 2 );
var bounds, zoom;
var map = new OpenLayers.Map('map');
layer = new OpenLayers.Layer.WMS(name, url, params);
map.addLayer(layer);
bounds = new OpenLayers.Bounds(10,10,12,12);
zoom = layer.getZoomForExtent(bounds);
t.eq( zoom, 8, "getZoomForExtent() returns correct value");
bounds = new OpenLayers.Bounds(10,10,100,100);
zoom = layer.getZoomForExtent(bounds);
t.eq( zoom, 2, "getZoomForExtent() returns correct value");
}
/** THIS WOULD BE WHERE THE TESTS WOULD GO FOR
*
* -moveTo
* -insertColumn
* -insertRow
function 07_Layer_Grid_moveTo(t) {
}
function 08_Layer_Grid_insertColumn(t) {
}
function 09_Layer_Grid_insertRow(t) {
}
*
*/
function test_10_Layer_Grid_clone(t) {
t.plan(5);
var options = {tileSize: new OpenLayers.Size(500,50)};
var map = new OpenLayers.Map('map', options);
layer = new OpenLayers.Layer.Grid(name, url, params);
map.addLayer(layer);
layer.grid = [ [6, 7],
[8, 9]];
var clone = layer.clone();
t.ok( clone.grid != layer.grid, "clone does not copy grid");
t.ok( clone.grid.length == 0, "clone creates a new array instead");
t.ok( clone.tileSize.equals(layer.tileSize), "tileSize correctly cloned");
layer.tileSize.w += 40;
t.eq( clone.tileSize.w, 500, "changing layer.tileSize does not change clone.tileSize -- a fresh copy was made, not just copied reference");
t.eq( clone.alpha, layer.alpha, "alpha copied correctly");
layer.grid = null;
}
function test_11_Layer_Grid_setMap(t) {
t.plan(2);
var options = {tileSize: new OpenLayers.Size(500,50)};
var map = new OpenLayers.Map('map', options);
layer = new OpenLayers.Layer.Grid(name, url, params);
layer.setMap(map);
t.ok( layer.tileSize != null, "tileSize has been set");
t.ok( (layer.tileSize.h == 50) && (layer.tileSize.w == 500), "tileSize has been set correctly");
}
function test_99_Layer_Grid_destroy (t) {
t.plan( 3 );
var map = new OpenLayers.Map('map');
layer = new OpenLayers.Layer.Grid(name, url, params);
map.addLayer(layer);
layer.destroy();
t.eq( layer.grid, null, "layer.grid is null after destroy" );
t.eq( layer.tileSize, null, "layer.tileSize is null after destroy" );
//test with tile creation
layer = new OpenLayers.Layer.WMS(name, url, params);
map.addLayer(layer);
map.setCenter(new OpenLayers.LonLat(0,0), 5);
//grab a reference to one of the tiles
var tile = layer.grid[0][0];
layer.destroy();
t.ok( layer.grid == null, "tiles appropriately destroyed")
}
// -->
</script>
</head>
<body>
<div id="map" style="width:500px;height:550px;display:none"></div>
</body>
</html>
+183
View File
@@ -0,0 +1,183 @@
<html>
<head>
<script src="../../lib/OpenLayers.js"></script>
<script type="text/javascript"><!--
var layer;
var name = "Test Layer";
var url = "http://octo.metacarta.com/cgi-bin/mapserv";
var params = { map: '/mapdata/vmap_wms.map',
layers: 'basic',
format: 'image/png'};
var options = { chicken: 151, foo: "bar" };
function test_01_Layer_HTTPRequest_constructor (t) {
t.plan( 5 );
layer = new OpenLayers.Layer.HTTPRequest(name, url, params, options);
t.ok( layer instanceof OpenLayers.Layer.HTTPRequest, "new OpenLayers.Layer.HTTPRequest returns correctly typed object" );
// correct bubbling up to Layer.initialize()
t.eq( layer.name, name, "layer.name is correct" );
t.ok( ((layer.options["chicken"] == 151) && (layer.options["foo"] == "bar")), "layer.options correctly set" );
// HTTPRequest-specific properties
t.eq( layer.url, url, "layer.name is correct" );
t.ok( ((layer.params["map"] == '/mapdata/vmap_wms.map') &&
(layer.params["layers"] == "basic") &&
(layer.params["format"] == "image/png")), "layer.params correctly set" );
}
function test_02_Layer_HTTPRequest_clone (t) {
t.plan( 6 );
var toClone = new OpenLayers.Layer.HTTPRequest(name, url, params, options);
toClone.chocolate = 5;
var layer = toClone.clone();
t.eq(layer.chocolate, 5, "correctly copied randomly assigned property");
t.ok( layer instanceof OpenLayers.Layer.HTTPRequest, "new OpenLayers.Layer.HTTPRequest returns correctly typed object" );
// correct bubbling up to Layer.initialize()
t.eq( layer.name, name, "layer.name is correct" );
t.ok( ((layer.options["chicken"] == 151) && (layer.options["foo"] == "bar")), "layer.options correctly set" );
// HTTPRequest-specific properties
t.eq( layer.url, url, "layer.name is correct" );
t.ok( ((layer.params["map"] == '/mapdata/vmap_wms.map') &&
(layer.params["layers"] == "basic") &&
(layer.params["format"] == "image/png")), "layer.params correctly set" );
}
function test_03_Layer_HTTPRequest_setUrl (t) {
t.plan( 1 );
layer = new OpenLayers.Layer.HTTPRequest(name, url, params, options);
layer.setUrl("foo");
t.eq( layer.url, "foo", "setUrl() works");
}
function test_05_Layer_HTTPRequest_mergeNewParams (t) {
t.plan( 3 );
layer = new OpenLayers.Layer.HTTPRequest(name, url, params, options);
var newParams = { layers: 'sooper',
chickpeas: 'image/png'};
layer.mergeNewParams(newParams);
t.eq( layer.params.layers, "sooper", "mergeNewParams() overwrites well");
t.eq( layer.params.chickpeas, "image/png", "mergeNewParams() adds well");
newParams.chickpeas = 151;
t.eq( layer.params.chickpeas, "image/png", "mergeNewParams() makes clean copy of hash");
}
function test_06_Layer_HTTPRequest_getFullRequestString (t) {
tParams = { layers: 'basic',
format: 'image/png'};
t.plan( 9 );
// without ?
tUrl = "http://octo.metacarta.com/cgi-bin/mapserv";
layer = new OpenLayers.Layer.HTTPRequest(name, tUrl, tParams, null);
str = layer.getFullRequestString();
t.eq(str, tUrl + '?' + OpenLayers.Util.getParameterString(tParams), "getFullRequestString() works for url sans ?");
// with ?
tUrl = "http://octo.metacarta.com/cgi-bin/mapserv?";
layer = new OpenLayers.Layer.HTTPRequest(name, tUrl, tParams, null);
str = layer.getFullRequestString();
t.eq(str, tUrl + OpenLayers.Util.getParameterString(tParams), "getFullRequestString() works for url with ?");
// with ?param1=5
tUrl = "http://octo.metacarta.com/cgi-bin/mapserv?param1=5";
layer = new OpenLayers.Layer.HTTPRequest(name, tUrl, tParams, null);
str = layer.getFullRequestString();
t.eq(str, tUrl + '&' + OpenLayers.Util.getParameterString(tParams), "getFullRequestString() works for url with ?param1=5");
// with ?param1=5&
tUrl = "http://octo.metacarta.com/cgi-bin/mapserv?param1=5&format=image/jpeg";
layer = new OpenLayers.Layer.HTTPRequest(name, tUrl, tParams, null);
str = layer.getFullRequestString();
t.eq(str, tUrl + '&' + OpenLayers.Util.getParameterString({'layers':'basic'}), "getFullRequestString() doesn't override already-existing params in URL");
// with ?param1=5&
tUrl = "http://octo.metacarta.com/cgi-bin/mapserv?param1=5&";
layer = new OpenLayers.Layer.HTTPRequest(name, tUrl, tParams, null);
str = layer.getFullRequestString();
t.eq(str, tUrl + OpenLayers.Util.getParameterString(tParams), "getFullRequestString() works for url with ?param1=5&");
// passing in new params
layer = new OpenLayers.Layer.HTTPRequest(name, tUrl, tParams, null);
str = layer.getFullRequestString( { chicken: 6,
layers:"road" } );
t.eq(str, tUrl + OpenLayers.Util.getParameterString({layers: 'road', format: "image/png", chicken: 6}), "getFullRequestString() works for passing in new params");
// layer with null params
layer = new OpenLayers.Layer.HTTPRequest(name, tUrl, null, null);
str = layer.getFullRequestString();
t.eq(str, tUrl + OpenLayers.Util.getParameterString({}), "getFullRequestString() works for layer with null params");
// layer with null params passing in new params
layer = new OpenLayers.Layer.HTTPRequest(name, tUrl, null, null);
str = layer.getFullRequestString( { chicken: 6,
layers:"road" } );
t.eq(str, tUrl + OpenLayers.Util.getParameterString({chicken: 6, layers: "road"}), "getFullRequestString() works for layer with null params passing in new params");
// with specified altUrl parameter
tUrl = "http://octo.metacarta.com/cgi-bin/mapserv";
layer = new OpenLayers.Layer.HTTPRequest(name, "chicken", tParams, null);
str = layer.getFullRequestString(null, tUrl);
t.eq(str, tUrl + '?' + OpenLayers.Util.getParameterString(tParams), "getFullRequestString() works for url sans ?");
}
function test_99_Layer_HTTPRequest_destroy (t) {
t.plan( 6 );
var map = new OpenLayers.Map('map');
layer = new OpenLayers.Layer.HTTPRequest("Test Layer",
"http://www.openlayers.org",
{ foo: 2, bar: 3},
{ opt1: 8, opt2: 9});
map.addLayer(layer);
layer.destroy();
// Ensure Layer.destroy() is called
t.eq( layer.name, null, "layer.name is null after destroy" );
t.eq( layer.div, null, "layer.div is null after destroy" );
t.eq( layer.map, null, "layer.map is null after destroy" );
t.eq( layer.options, null, "layer.options is null after destroy" );
// Specific to HTTPRequest
t.eq( layer.url, null, "layer.url is null after destroy" );
t.eq( layer.params, null, "layer.params is null after destroy" );
}
// -->
</script>
</head>
<body>
<div id="map"></div>
</body>
</html>
+96
View File
@@ -0,0 +1,96 @@
<html>
<head>
<script src="../../lib/OpenLayers.js"></script>
<script type="text/javascript"><!--
var layer;
function test_01_Layer_Image_constructor (t) {
t.plan( 13 );
var options = { chicken: 151, foo: "bar", projection: "none" };
var layer = new OpenLayers.Layer.Image('Test Layer',
'http://earthtrends.wri.org/images/maps/4_m_citylights_lg.gif',
new OpenLayers.Bounds(-180, -88.759, 180, 88.759),
new OpenLayers.Size(580, 288), options);
t.ok( layer instanceof OpenLayers.Layer.Image, "new OpenLayers.Layer.Image returns object" );
t.eq( layer.CLASS_NAME, "OpenLayers.Layer.Image", "CLASS_NAME variable set correctly");
t.eq( layer.name, "Test Layer", "layer.name is correct" );
t.ok( layer.id != null, "Layer is given an id");
t.ok( layer.projection, "none", "default layer projection correctly set");
t.ok( ((layer.chicken == 151) && (layer.foo == "bar")), "layer.options correctly set to Layer Object" );
t.ok( ((layer.options["chicken"] == 151) && (layer.options["foo"] == "bar")), "layer.options correctly backed up" );
options.chicken = 552;
t.eq( layer.options["chicken"], 151 , "layer.options correctly made fresh copy" );
t.eq( layer.isBaseLayer, true, "Default img layer is base layer" );
layer = new OpenLayers.Layer.Image('Test Layer',
'http://earthtrends.wri.org/images/maps/4_m_citylights_lg.gif',
new OpenLayers.Bounds(-180, -88.759, 180, 88.759),
new OpenLayers.Size(580, 288));
t.ok( layer instanceof OpenLayers.Layer.Image, "new OpenLayers.Layer.Image returns object" );
t.eq( layer.name, "Test Layer", "layer.name is correct" );
t.ok( layer.projection == null, "default layer projection correctly set");
t.ok( layer.options instanceof Object, "layer.options correctly initialized as a non-null Object" );
}
function test_50_Layer_Image_tileTests (t) {
t.plan(4);
var map = new OpenLayers.Map('map');
layer = new OpenLayers.Layer.Image('Test Layer',
'http://earthtrends.wri.org/images/maps/4_m_citylights_lg.gif',
new OpenLayers.Bounds(-180, -88.759, 180, 88.759),
new OpenLayers.Size(580, 288));
map.addLayer(layer);
map.zoomToMaxExtent();
t.eq(layer.tile.position.x,-40, "Tile x positioned correctly at maxextent");
t.eq(layer.tile.position.y,107, "Tile y positioned correctly at maxextent");
t.eq(layer.tile.imgDiv.src, "http://earthtrends.wri.org/images/maps/4_m_citylights_lg.gif", "URL is correct");
map.zoomIn();
t.eq(layer.tile.imgDiv.src, "http://earthtrends.wri.org/images/maps/4_m_citylights_lg.gif", "URL is correct");
}
/******
*
*
* HERE IS WHERE SOME TESTS SHOULD BE PUT TO CHECK ON THE LONLAT-PX TRANSLATION
* FUNCTIONS AND RESOLUTION AND GETEXTENT GETZOOMLEVEL, ETC
*
*
*/
function test_99_Layer_Image_destroy (t) {
t.plan( 4 );
var map = new OpenLayers.Map('map');
layer = new OpenLayers.Layer.Image('Test Layer',
'http://earthtrends.wri.org/images/maps/4_m_citylights_lg.gif',
new OpenLayers.Bounds(-180, -88.759, 180, 88.759),
new OpenLayers.Size(580, 288));
map.addLayer(layer);
map.zoomToMaxExtent();
layer.destroy();
t.eq( layer.name, null, "layer.name is null after destroy" );
t.eq( layer.div, null, "layer.div is null after destroy" );
t.eq( layer.map, null, "layer.map is null after destroy" );
t.eq( layer.options, null, "layer.options is null after destroy" );
}
// -->
</script>
</head>
<body>
<div id="map" style="width:500px;height:500px"></div>
<div id="map2" style="width:100px;height:100px"></div>
</body>
</html>
+220
View File
@@ -0,0 +1,220 @@
<html>
<head>
<script src="../../lib/OpenLayers.js"></script>
<script type="text/javascript"><!--
var isMozilla = (navigator.userAgent.indexOf("compatible") == -1);
var layer;
var name = 'Test Layer';
var url = "http://boston.freemap.in/tile.php?";
var params = {
'map':'boston-new',
'g':'border,water,roads,openspace',
'i':'JPEG'
};
var units = "meters";
function test_01_Layer_KaMap_constructor (t) {
t.plan( 1 );
layer = new OpenLayers.Layer.KaMap(name, url, params, units);
t.ok( layer instanceof OpenLayers.Layer.KaMap, "returns OpenLayers.Layer.KaMap object" );
}
function test_02_Layer_KaMap_inittiles (t) {
t.plan( 2 );
var map = new OpenLayers.Map('map');
layer = new OpenLayers.Layer.KaMap(name, url, params, units);
map.addLayer(layer);
map.setCenter(new OpenLayers.LonLat(0,0),5);
t.eq( layer.grid.length, 6, "KaMap rows is correct." );
t.eq( layer.grid[0].length, 4, "KaMap cols is correct." );
}
function test_03_Layer_KaMap_clearTiles (t) {
t.plan( 1 );
var map = new OpenLayers.Map('map');
layer = new OpenLayers.Layer.KaMap(name, url, params, units);
map.addLayer(layer);
map.setCenter(new OpenLayers.LonLat(0,0));
//grab a reference to one of the tiles
var tile = layer.grid[0][0];
layer.clearGrid();
t.ok( layer.grid != null, "layer.grid does not get nullified" );
}
function test_04_Layer_KaMap_getKaMapBounds(t) {
t.plan( 1 );
layer = new OpenLayers.Layer.KaMap(name, url, params, units);
var bl = { bounds: new OpenLayers.Bounds(1,2,0,0)};
var tr = { bounds: new OpenLayers.Bounds(0,0,3,4)};
layer.grid = [ [6, tr],
[bl, 7]];
var bounds = layer.getGridBounds();
var testBounds = new OpenLayers.Bounds(1,2,3,4);
t.ok( bounds.equals(testBounds), "getKaMapBounds() returns correct bounds")
layer.grid = null;
}
function test_05_Layer_KaMap_getResolution(t) {
t.plan( 1 );
var map = new OpenLayers.Map('map');
layer = new OpenLayers.Layer.KaMap(name, url, params, units);
map.addLayer(layer);
map.zoom = 5;
t.eq( layer.getResolution(), 0.0439453125, "getResolution() returns correct value");
}
function test_06_Layer_KaMap_getZoomForExtent(t) {
t.plan( 2 );
var bounds, zoom;
var map = new OpenLayers.Map('map');
layer = new OpenLayers.Layer.KaMap(name, url, params, units);
map.addLayer(layer);
bounds = new OpenLayers.Bounds(10,10,12,12);
zoom = layer.getZoomForExtent(bounds);
t.eq( zoom, 8, "getZoomForExtent() returns correct value");
bounds = new OpenLayers.Bounds(10,10,100,100);
zoom = layer.getZoomForExtent(bounds);
t.eq( zoom, 2, "getZoomForExtent() returns correct value");
}
function test_06_Layer_kaMap_mergeNewParams (t) {
t.plan( 5 );
var map = new OpenLayers.Map("map");
var url = "http://octo.metacarta.com/cgi-bin/mapserv";
layer = new OpenLayers.Layer.KaMap(name, url, params);
var newParams = { layers: 'sooper',
chickpeas: 'image/png'};
map.addLayer(layer);
map.zoomToMaxExtent();
t.ok( !layer.grid[0][0].url.match("chickpeas"), "chickpeas is not in URL of first tile in grid" );
layer.mergeNewParams(newParams);
t.eq( layer.params.layers, "sooper", "mergeNewParams() overwrites well");
t.eq( layer.params.chickpeas, "image/png", "mergeNewParams() adds well");
t.ok( layer.grid[0][0].url.match("chickpeas"), "CHICKPEAS is in URL of first tile in grid" );
newParams.chickpeas = 151;
t.eq( layer.params.chickpeas, "image/png", "mergeNewParams() makes clean copy of hashtable");
}
/** THIS WOULD BE WHERE THE TESTS WOULD GO FOR
*
* -moveTo
* -insertColumn
* -insertRow
function 07_Layer_KaMap_moveTo(t) {
}
function 08_Layer_KaMap_insertColumn(t) {
}
function 09_Layer_KaMap_insertRow(t) {
}
*
*/
function test_10_Layer_KaMap_clone(t) {
t.plan(4);
var options = {tileSize: new OpenLayers.Size(500,50)};
var map = new OpenLayers.Map('map', options);
layer = new OpenLayers.Layer.KaMap(name, url, params, units);
map.addLayer(layer);
layer.grid = [ [6, 7],
[8, 9]];
var clone = layer.clone();
t.ok( clone.grid != layer.grid, "clone does not copy grid");
t.ok( clone.tileSize.equals(layer.tileSize), "tileSize correctly cloned");
layer.tileSize.w += 40;
t.eq( clone.tileSize.w, 500, "changing layer.tileSize does not change clone.tileSize -- a fresh copy was made, not just copied reference");
t.eq( clone.alpha, layer.alpha, "alpha copied correctly");
layer.grid = null;
}
function test_11_Layer_KaMap_setMap(t) {
t.plan(2);
var options = {tileSize: new OpenLayers.Size(500,50)};
var map = new OpenLayers.Map('map', options);
layer = new OpenLayers.Layer.KaMap(name, url, params, units);
layer.setMap(map);
t.ok( layer.tileSize != null, "tileSize has been set");
t.ok( (layer.tileSize.h == 50) && (layer.tileSize.w == 500), "tileSize has been set correctly");
}
function test_99_Layer_KaMap_destroy (t) {
t.plan( 3 );
var map = new OpenLayers.Map('map');
layer = new OpenLayers.Layer.KaMap(name, url, params, units);
map.addLayer(layer);
layer.destroy();
t.eq( layer.grid, null, "layer.grid is null after destroy" );
t.eq( layer.tileSize, null, "layer.tileSize is null after destroy" );
//test with tile creation
layer = new OpenLayers.Layer.KaMap(name, url, params, units);
map.addLayer(layer);
map.setCenter(new OpenLayers.LonLat(0,0), 5);
//grab a reference to one of the tiles
var tile = layer.grid[0][0];
layer.destroy();
t.ok( layer.grid == null, "tiles appropriately destroyed");
}
// -->
</script>
</head>
<body>
<div id="map" style="width:500px;height:550px;display:none"></div>
</body>
</html>
+40
View File
@@ -0,0 +1,40 @@
<html>
<head>
<script src="../../lib/OpenLayers.js"></script>
<script type="text/javascript"><!--
var layer;
function test_01_Layer_Markers_constructor (t) {
t.plan( 2 );
layer = new OpenLayers.Layer.Markers('Test Layer');
t.ok( layer instanceof OpenLayers.Layer.Markers, "new OpenLayers.Layer.Markers returns object" );
t.eq( layer.name, "Test Layer", "layer.name is correct" );
}
function test_02_Layer_Markers_addlayer (t) {
t.plan( 3 );
layer = new OpenLayers.Layer.Markers('Test Layer');
t.ok( layer instanceof OpenLayers.Layer.Markers, "new OpenLayers.Layer.Markers returns object" );
t.eq( layer.name, "Test Layer", "layer.name is correct" );
layer.addMarker(new OpenLayers.Marker(new OpenLayers.LonLat(0,0),
new OpenLayers.Icon())
);
t.eq( layer.markers.length, 1, "addLayer adds marker to layer." );
}
function test_99_Layer_Markers_destroy (t) {
t.plan( 1 );
layer = new OpenLayers.Layer.Markers('Test Layer');
var map = new OpenLayers.Map('map');
map.addLayer(layer);
layer.destroy();
t.eq( layer.map, null, "layer.map is null after destroy" );
}
// -->
</script>
</head>
<body>
<div id="map"></div>
</body>
</html>
+105
View File
@@ -0,0 +1,105 @@
<html>
<head>
<script type="text/javascript" src="http://clients.multimap.com/API/maps/1.1/metacarta_04"></script>
<script src="../../lib/OpenLayers.js"></script>
<script type="text/javascript"><!--
var layer;
function test_01_Layer_MultiMap_constructor (t) {
t.plan( 4 );
var map = new OpenLayers.Map('map');
var layer = new OpenLayers.Layer.MultiMap('Goog Layer');
map.addLayer(layer);
t.ok( layer instanceof OpenLayers.Layer.MultiMap, "new OpenLayers.Layer.MultiMap returns object" );
t.eq( layer.CLASS_NAME, "OpenLayers.Layer.MultiMap", "CLASS_NAME variable set correctly");
t.eq( layer.name, "Goog Layer", "layer.name is correct" );
t.ok ( layer.mapObject != null, "MultiMap Object correctly loaded");
}
function test_02_Layer_MultiMap_isBaseLayer (t) {
t.plan(1);
var layer = new OpenLayers.Layer.MultiMap('Goog Layer');
t.ok(layer.isBaseLayer, "a default load of google layer responds as a base layer");
}
function test_04_Layer_MultiMap_Translation_lonlat (t) {
t.plan( 4 );
var map = new OpenLayers.Map('map');
var layer = new OpenLayers.Layer.MultiMap('Goog Layer');
map.addLayer(layer);
// these two lines specify an appropriate translation.
// the code afterwards works by itself to test that translation
// works correctly both ways.
var gLatLng = new MMLatLon(50,100);
var correspondingOLLonLat = new OpenLayers.LonLat(100,50);
olLonLat = layer.getOLLonLatFromMapObjectLonLat(gLatLng);
t.ok(olLonLat.equals(correspondingOLLonLat), "Translation from GLatLng to OpenLayers.LonLat works");
var transGLatLng = layer.getMapObjectLonLatFromOLLonLat(olLonLat);
t.ok( (transGLatLng.lat == gLatLng.lat) && (transGLatLng.lon == transGLatLng.lon), "Translation from OpenLayers.LonLat to GLatLng works");
t.ok( layer.getMapObjectLonLatFromOLLonLat(null) == null, "getGLatLngFromOLLonLat(null) returns null");
t.ok( layer.getOLLonLatFromMapObjectLonLat(null) == null, "getOLLonLatFromGLatLng(null) returns null");
}
function test_05_Layer_MultiMap_Translation_pixel (t) {
t.plan( 4 );
var map = new OpenLayers.Map('map');
var layer = new OpenLayers.Layer.MultiMap('Goog Layer');
map.addLayer(layer);
// these two lines specify an appropriate translation.
// the code afterwards works by itself to test that translation
// works correctly both ways.
var gPoint = new MMPoint(50,100);
var correspondingOLPixel = new OpenLayers.Pixel(50, 100);
olPixel = layer.getOLPixelFromMapObjectPixel(gPoint);
t.ok( olPixel.equals(correspondingOLPixel), "Translation from GPoint to OpenLayers.Pixel works");
var transGPoint = layer.getMapObjectPixelFromOLPixel(olPixel);
t.ok( ((transGPoint.x == transGPoint.x) && (transGPoint.y == transGPoint.y)), "Translation from OpenLayers.Pixel to GPoint works");
t.ok( layer.getMapObjectPixelFromOLPixel(null) == null, "getGPointFromOLPixel(null) returns null");
t.ok( layer.getOLPixelFromMapObjectPixel(null) == null, "getOLPixelFromGPoint(null) returns null");
}
function test_99_Layer_destroy (t) {
t.plan( 5 );
var map = new OpenLayers.Map('map');
layer = new OpenLayers.Layer.MultiMap('Test Layer');
map.addLayer(layer);
layer.destroy();
t.eq( layer.name, null, "layer.name is null after destroy" );
t.eq( layer.div, null, "layer.div is null after destroy" );
t.eq( layer.map, null, "layer.map is null after destroy" );
t.eq( layer.options, null, "layer.options is null after destroy" );
t.eq( layer.multimap, null, "layer.gmap is null after destroy" );
}
// -->
</script>
</head>
<body>
<div id="map"></div>
</body>
</html>
+164
View File
@@ -0,0 +1,164 @@
<html>
<head>
<script src="../../lib/OpenLayers.js"></script>
<script type="text/javascript"><!--
var isMozilla = (navigator.userAgent.indexOf("compatible") == -1);
var layer;
var name = 'Test Layer';
var url = "http://labs.metacarta.com/wms-c/Basic.py/";
var options = {'layername':'basic', 'type':'png'};
function test_01_Layer_TMS_constructor (t) {
t.plan( 1 );
layer = new OpenLayers.Layer.TMS(name, url, options);
t.ok( layer instanceof OpenLayers.Layer.TMS, "returns OpenLayers.Layer.TMS object" );
}
function test_03_Layer_TMS_clearTiles (t) {
t.plan( 1 );
var map = new OpenLayers.Map('map');
layer = new OpenLayers.Layer.TMS(name, url, options);
map.addLayer(layer);
map.setCenter(new OpenLayers.LonLat(0,0));
//grab a reference to one of the tiles
var tile = layer.grid[0][0];
layer.clearGrid();
t.ok( layer.grid != null, "layer.grid does not get nullified" );
}
function test_04_Layer_TMS_getTMSBounds(t) {
t.plan( 1 );
layer = new OpenLayers.Layer.TMS(name, url, options);
var bl = { bounds: new OpenLayers.Bounds(1,2,0,0)};
var tr = { bounds: new OpenLayers.Bounds(0,0,3,4)};
layer.grid = [ [6, tr],
[bl, 7]];
var bounds = layer.getGridBounds();
var testBounds = new OpenLayers.Bounds(1,2,3,4);
t.ok( bounds.equals(testBounds), "getTMSBounds() returns correct bounds")
layer.grid = null;
}
function test_05_Layer_TMS_getResolution(t) {
t.plan( 1 );
var map = new OpenLayers.Map('map');
layer = new OpenLayers.Layer.TMS(name, url, options);
map.addLayer(layer);
map.zoom = 5;
t.eq( layer.getResolution(), 0.0439453125, "getResolution() returns correct value");
}
function test_06_Layer_TMS_getZoomForExtent(t) {
t.plan( 2 );
var bounds, zoom;
var map = new OpenLayers.Map('map');
layer = new OpenLayers.Layer.TMS(name, url, options);
map.addLayer(layer);
bounds = new OpenLayers.Bounds(10,10,12,12);
zoom = layer.getZoomForExtent(bounds);
t.eq( zoom, 8, "getZoomForExtent() returns correct value");
bounds = new OpenLayers.Bounds(10,10,100,100);
zoom = layer.getZoomForExtent(bounds);
t.eq( zoom, 2, "getZoomForExtent() returns correct value");
}
/** THIS WOULD BE WHERE THE TESTS WOULD GO FOR
*
* -moveTo
* -insertColumn
* -insertRow
function 07_Layer_TMS_moveTo(t) {
}
function 08_Layer_TMS_insertColumn(t) {
}
function 09_Layer_TMS_insertRow(t) {
}
*
*/
function test_10_Layer_TMS_getURL(t) {
t.plan(1);
var map = new OpenLayers.Map('map', options);
var options = {'layername':'basic', 'type':'png'};
layer = new OpenLayers.Layer.TMS(name, url, options);
map.addLayer(layer);
map.setCenter(new OpenLayers.LonLat(0,0), 9);
var tileurl = layer.getURL(new OpenLayers.Bounds(3.515625,45,4.21875,45.703125));
t.eq(tileurl, "http://labs.metacarta.com/wms-c/Basic.py/1.0.0/basic/9/261/192.png", "Tile URL is correct");
}
function test_11_Layer_TMS_setMap(t) {
t.plan(3);
var map = new OpenLayers.Map('map', options);
layer = new OpenLayers.Layer.TMS(name, url, options);
t.eq(layer.tileOrigin, null, "Tile origin starts out null");
layer.setMap(map);
t.eq(layer.tileOrigin.lat, -90, "lat is -90");
t.eq(layer.tileOrigin.lon, -180, "lon is -180");
}
function test_99_Layer_TMS_destroy (t) {
t.plan( 3 );
var map = new OpenLayers.Map('map');
layer = new OpenLayers.Layer.TMS(name, url, options);
map.addLayer(layer);
layer.destroy();
t.eq( layer.grid, null, "layer.grid is null after destroy" );
t.eq( layer.tileSize, null, "layer.tileSize is null after destroy" );
//test with tile creation
layer = new OpenLayers.Layer.TMS(name, url, options);
map.addLayer(layer);
map.setCenter(new OpenLayers.LonLat(0,0), 5);
//grab a reference to one of the tiles
var tile = layer.grid[0][0];
layer.destroy();
t.ok( layer.grid == null, "tiles appropriately destroyed");
}
// -->
</script>
</head>
<body>
<div id="map" style="width:500px;height:550px"></div>
</body>
</html>
+83
View File
@@ -0,0 +1,83 @@
<html>
<head>
<script src="../../lib/OpenLayers.js"></script>
<script type="text/javascript"><!--
var isMozilla = (navigator.userAgent.indexOf("compatible") == -1);
var layer;
function test_01_Layer_Text_constructor (t) {
t.plan( 5 );
layer = new OpenLayers.Layer.Text('Test Layer', { location: 'data_Layer_Text_textfile.txt'});
t.ok( layer instanceof OpenLayers.Layer.Text, "new OpenLayers.Layer.Text returns object" );
t.eq( layer.location, "data_Layer_Text_textfile.txt", "layer.location is correct" );
var markers;
t.delay_call( 1, function() {
t.eq( layer.markers.length, 2, "marker length is correct" );
var ll = new OpenLayers.LonLat(20, 10);
t.ok( layer.markers[0].lonlat.equals(ll), "first marker is correct" );
t.eq( layer.markers[0].icon.url, 'http://boston.openguides.org/markers/ORANGE.png', "icon" );
} );
}
function test_02_Layer_Text_draw (t) {
// t.plan(5);
t.plan( 2 );
layer = new OpenLayers.Layer.Text('Test Layer', { location: 'data_Layer_Text_textfile.txt'});
t.ok( layer instanceof OpenLayers.Layer.Text, "new OpenLayers.Layer.Text returns object" );
var 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.addLayer(layer);
t.eq( map.layers[1].name, layer.name, "Layer added to map okay" );
t.delay_call( 1, function() {
map.setCenter(new OpenLayers.LonLat(0,0),0);
/*
if (!isMozilla)
t.ok( true, "skipping element test outside of Mozilla");
else
t.ok( map.layers[0].div.firstChild instanceof HTMLImageElement, "Marker added to div" )
t.eq( map.layers[0].div.firstChild.style.top, "219px", "Marker top set correctly" )
t.eq( map.layers[0].div.firstChild.style.left, "273px", "Marker left set correctly" )
*/
});;
}
function test_03_Layer_Text_events (t) {
t.plan( 4 );
layer = new OpenLayers.Layer.Text('Test Layer', { location: 'data_Layer_Text_textfile.txt'});
var 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.addLayer(layer);
map.setCenter(new OpenLayers.LonLat(0,0),0);
var event = {};
t.delay_call( 1, function() {
t.ok(layer.markers[0].events, "First marker has an events object");
t.eq(layer.markers[0].events.listeners['click'].length, 1, "Marker events has one object");
layer.markers[0].events.triggerEvent('click', event);
t.eq(map.popups.length, 1, "Popup opened correctly");
layer.markers[1].events.triggerEvent('click', event);
t.eq(map.popups.length, 1, "1st popup gone, 2nd Popup opened correctly");
});
}
function test_99_Layer_Text_destroy (t) {
t.plan( 1 );
layer = new OpenLayers.Layer.Text('Test Layer');
var map = new OpenLayers.Map('map');
map.addLayer(layer);
layer.destroy();
t.eq( layer.map, null, "layer.map is null after destroy" );
}
// -->
</script>
</head>
<body>
<div id="map" style="width:500px; height:500px"></div>
</body>
</html>
+63
View File
@@ -0,0 +1,63 @@
<html>
<head>
<script src="../../lib/OpenLayers.js"></script>
<script type="text/javascript"><!--
var name = "Vector Layer";
function test_01_Layer_Vector_constructor(t) {
t.plan(3);
var layer = new OpenLayers.Layer.Vector(name);
t.ok(layer instanceof OpenLayers.Layer.Vector, "new OpenLayers.Layer.Vector returns correct object" );
t.eq(layer.name, name, "layer name is correctly set");
t.ok(layer.renderer.CLASS_NAME, "layer has a renderer");
}
function test_02_Layer_Vector_addFeatures(t) {
t.plan(2);
var layer = new OpenLayers.Layer.Vector(name);
var point = new OpenLayers.Geometry.Point(-111.04, 45.68);
var pointFeature = new OpenLayers.Feature.Vector(layer, point);
layer.addFeatures([pointFeature]);
t.eq(layer.features.length, 1, "OpenLayers.Layer.Vector.addFeatures adds something to the array");
t.ok(layer.features[0] == pointFeature, "OpenLayers.Layer.Vector.addFeatures returns an array of features");
}
function test_03_Layer_Vector_removeFeatures(t) {
t.plan(1);
var layer = new OpenLayers.Layer.Vector(name);
var point1 = new OpenLayers.Geometry.Point(-111.04, 45.68);
var pointFeature1 = new OpenLayers.Feature.Vector(layer, point1);
var point2 = new OpenLayers.Geometry.Point(-111.14, 45.78);
var pointFeature2 = new OpenLayers.Feature.Vector(layer, point2);
layer.addFeatures([pointFeature1, pointFeature2]);
var features = layer.removeFeatures([pointFeature1]);
t.ok(layer.features.length == 1, "OpenLayers.Layer.Vector.removeFeatures removes a feature from the features array");
}
function test_99_Layer_Vector_destroy (t) {
t.plan(1);
layer = new OpenLayers.Layer.Vector(name);
var map = new OpenLayers.Map('map');
map.addLayer(layer);
layer.destroy();
t.eq(layer.map, null, "layer.map is null after destroy");
}
// -->
</script>
</head>
<body>
<div id="map" style="width:500px;height:550px"></div>
</body>
</html>
+250
View File
@@ -0,0 +1,250 @@
<html>
<head>
<script src='http://maps.google.com/maps?file=api&amp;v=2&amp;key=ABQIAAAAjpkAC9ePGem0lIq5XcMiuhR_wWLPFku8Ix9i2SXYRVK3e45q1BQUd_beF8dtzKET_EteAjPdGDwqpQ'></script>
<script src="../../lib/OpenLayers.js"></script>
<script type="text/javascript"><!--
var isMozilla = (navigator.userAgent.indexOf("compatible") == -1);
var layer;
var name = 'Test Layer';
var url = "http://octo.metacarta.com/cgi-bin/mapserv";
var params = { map: '/mapdata/vmap_wms.map',
layers: 'basic',
format: 'image/png'};
function test_01_Layer_WMS_constructor (t) {
t.plan( 4 );
var url = "http://octo.metacarta.com/cgi-bin/mapserv";
layer = new OpenLayers.Layer.WMS(name, url, params);
t.ok( layer instanceof OpenLayers.Layer.WMS, "new OpenLayers.Layer.WMS returns object" );
t.eq( layer.url, "http://octo.metacarta.com/cgi-bin/mapserv", "layer.url is correct (HTTPRequest inited)" );
t.eq( layer.params.MAP, "/mapdata/vmap_wms.map", "params passed in correctly uppercased" );
t.eq( layer.params.SERVICE, "WMS", "default params correclty uppercased and copied");
}
function test_02_Layer_WMS_addtile (t) {
t.plan( 6 );
var url = "http://octo.metacarta.com/cgi-bin/mapserv";
layer = new OpenLayers.Layer.WMS(name, url, params);
var map = new OpenLayers.Map('map');
map.addLayer(layer);
var pixel = new OpenLayers.Pixel(5,6);
var tile = layer.addTile(new OpenLayers.Bounds(1,2,3,4), pixel);
tile.draw();
var img = tile.imgDiv;
var tParams = OpenLayers.Util.extend({},
OpenLayers.Util.upperCaseObject(params));
tParams = OpenLayers.Util.extend(tParams, {
SERVICE: "WMS", VERSION: "1.1.1",
REQUEST: "GetMap", STYLES: "",
EXCEPTIONS: "application/vnd.ogc.se_inimage",
SRS: "EPSG:4326", BBOX: "1,2,3,4",
WIDTH: "256", HEIGHT: "256"
});
t.eq( img.src,
url + "?" + OpenLayers.Util.getParameterString(tParams),
"image src is created correctly via addtile" );
t.eq( tile.imgDiv.style.top, "6px", "image top is set correctly via addtile" );
t.eq( tile.imgDiv.style.left, "5px", "image top is set correctly via addtile" );
var firstChild = layer.div.firstChild;
if (!isMozilla)
t.ok( true, "skipping element test outside of Mozilla");
else
t.ok( firstChild instanceof HTMLElement, "div first child is an image object" );
t.eq( firstChild.src,
url + "?" + OpenLayers.Util.getParameterString(tParams),
"div first child is correct image object" );
t.eq( tile.position.toString(), "x=5,y=6", "Position of tile is set correctly." );
}
function test_03_Layer_WMS_inittiles (t) {
t.plan( 2 );
var map = new OpenLayers.Map('map');
layer = new OpenLayers.Layer.WMS(name, url, params);
map.addLayer(layer);
map.setCenter(new OpenLayers.LonLat(0,0),5);
t.eq( layer.grid.length, 7, "Grid rows is correct." );
t.eq( layer.grid[0].length, 6, "Grid cols is correct." );
}
function test_04_Layer_WMS_clone (t) {
t.plan(4);
var url = "http://octo.metacarta.com/cgi-bin/mapserv";
var options = {tileSize: new OpenLayers.Size(500,50)};
var map = new OpenLayers.Map('map', options);
layer = new OpenLayers.Layer.WMS(name, url, params);
map.addLayer(layer);
layer.grid = [ [6, 7],
[8, 9]];
var clone = layer.clone();
t.ok( clone.grid != layer.grid, "clone does not copy grid");
t.ok( clone.tileSize.equals(layer.tileSize), "tileSize correctly cloned");
layer.tileSize.w += 40;
t.eq( clone.tileSize.w, 500, "changing layer.tileSize does not change clone.tileSize -- a fresh copy was made, not just copied reference");
t.eq( clone.alpha, layer.alpha, "alpha copied correctly");
layer.grid = null;
}
function test_05_Layer_WMS_isBaseLayer(t) {
t.plan(3);
var url = "http://octo.metacarta.com/cgi-bin/mapserv";
layer = new OpenLayers.Layer.WMS(name, url, params);
t.ok( layer.isBaseLayer, "baselayer is true by default");
var newParams = OpenLayers.Util.extend(new Object(), params);
newParams.transparent = "true";
layer = new OpenLayers.Layer.WMS(name, url, newParams);
t.ok( !layer.isBaseLayer, "baselayer is false when transparent is set to true");
layer = new OpenLayers.Layer.WMS(name, url, params, {isBaseLayer: false});
t.ok( !layer.isBaseLayer, "baselayer is false when option is set to false" );
}
function test_06_Layer_WMS_mergeNewParams (t) {
t.plan( 5 );
var map = new OpenLayers.Map("map");
var url = "http://octo.metacarta.com/cgi-bin/mapserv";
layer = new OpenLayers.Layer.WMS(name, url, params);
var newParams = { layers: 'sooper',
chickpeas: 'image/png'};
map.addLayer(layer);
map.zoomToMaxExtent();
t.ok( !layer.grid[0][0].url.match("CHICKPEAS"), "CHICKPEAS is not in URL of first tile in grid" );
layer.mergeNewParams(newParams);
t.eq( layer.params.LAYERS, "sooper", "mergeNewParams() overwrites well");
t.eq( layer.params.CHICKPEAS, "image/png", "mergeNewParams() adds well");
t.ok( layer.grid[0][0].url.match("CHICKPEAS"), "CHICKPEAS is in URL of first tile in grid" );
newParams.CHICKPEAS = 151;
t.eq( layer.params.CHICKPEAS, "image/png", "mergeNewParams() makes clean copy of hashtable");
}
function test_07_Layer_WMS_getFullRequestString (t) {
t.plan( 2 );
var map = new OpenLayers.Map('map');
map.projection = "xx";
tUrl = "http://octo.metacarta.com/cgi-bin/mapserv";
tParams = { layers: 'basic',
format: 'image/png'};
var tLayer = new OpenLayers.Layer.WMS(name, tUrl, tParams);
map.addLayer(tLayer);
str = tLayer.getFullRequestString();
var tParams = {
LAYERS: "basic", FORMAT: "image/png", SERVICE: "WMS",
VERSION: "1.1.1", REQUEST: "GetMap", STYLES: "",
EXCEPTIONS: "application/vnd.ogc.se_inimage", SRS: "xx"
};
t.eq(str,
tUrl + "?" + OpenLayers.Util.getParameterString(tParams),
"getFullRequestString() adds SRS value");
tLayer.projection = "none";
str = tLayer.getFullRequestString();
delete tParams['SRS'];
t.eq(str,
tUrl + "?" + OpenLayers.Util.getParameterString(tParams),
"getFullRequestString() by default does *not* add SRS value if projection is 'none'");
}
function test_08_Layer_WMS_setOpacity (t) {
t.plan( 5 );
var map = new OpenLayers.Map('map');
map.projection = "xx";
tUrl = "http://octo.metacarta.com/cgi-bin/mapserv";
tParams = { layers: 'basic',
format: 'image/png'};
tOptions = { 'opacity': '0.5' };
var tLayer = new OpenLayers.Layer.WMS(name, tUrl, tParams, tOptions);
map.addLayer(tLayer);
map.zoomToMaxExtent();
t.eq(tLayer.opacity, "0.5", "Opacity is set correctly");
t.eq(parseFloat(tLayer.div.firstChild.style.opacity), 0.5, "Opacity on tile is correct");
tLayer.setOpacity("0.6");
t.eq(tLayer.opacity, "0.6", "setOpacity works properly");
t.eq(parseFloat(tLayer.div.firstChild.style.opacity), 0.6, "Opacity on tile is changed correctly");
var pixel = new OpenLayers.Pixel(5,6);
var tile = tLayer.addTile(new OpenLayers.Bounds(1,2,3,4), pixel);
tile.draw();
t.eq(parseFloat(tile.imgDiv.style.opacity), 0.6, "Tile opacity is set correctly");
}
function test_20_Layer_WMS_Reproject (t) {
t.plan(5);
var map = new OpenLayers.Map('map');
var layer = new OpenLayers.Layer.Google("Google");
map.addLayer(layer);
layer = new OpenLayers.Layer.WMS(name, url, params, {isBaseLayer: false});
layer.isBaseLayer=false;
map.addLayer(layer);
map.setCenter(new OpenLayers.LonLat(0,0), 5);
var tile = layer.grid[0][0];
t.eq( tile.bounds.left, -22.5, "left side matches" );
t.eq( tile.bounds.right, -11.25, "top side matches" );
t.eq( tile.bounds.bottom.toFixed(6), '11.178402', "bottom side matches" );
t.eq( tile.bounds.top.toFixed(6), '21.943046', "top side matches" );
var map = new OpenLayers.Map('map');
layer = new OpenLayers.Layer.WMS(name, url, params);
map.addLayer(layer);
map.setCenter(new OpenLayers.LonLat(0,0), 5);
var tile = layer.grid[0][0];
t.ok( tile.bounds.equals(new OpenLayers.Bounds(-33.75, 33.75, -22.5, 45)), "okay");
}
function test_99_Layer_WMS_destroy (t) {
t.plan( 1 );
var map = new OpenLayers.Map('map');
layer = new OpenLayers.Layer.WMS(name, url, params);
map.addLayer(layer);
map.setCenter(new OpenLayers.LonLat(0,0), 5);
//grab a reference to one of the tiles
var tile = layer.grid[0][0];
layer.destroy();
// checks to make sure superclass (grid) destroy() was called
t.ok( layer.grid == null, "grid set to null");
}
// -->
</script>
</head>
<body>
<div id="map" style="width:500px;height:550px"></div>
</body>
</html>