| 1 |
<html> |
|---|
| 2 |
<head> |
|---|
| 3 |
<script type="text/javascript">var oldAlert = window.alert, gMess; window.alert = function(message) {gMess = message; return true;};</script> |
|---|
| 4 |
<!-- this gmaps key generated for http://openlayers.org/dev/ --> |
|---|
| 5 |
<script src='http://maps.google.com/maps?file=api&v=2&key=ABQIAAAA9XNhd8q0UdwNC7YSO4YZghSPUCi5aRYVveCcVYxzezM4iaj_gxQ9t-UajFL70jfcpquH5l1IJ-Zyyw'></script> |
|---|
| 6 |
<script type="text/javascript">window.alert = oldAlert;</script> |
|---|
| 7 |
<script src="../../lib/OpenLayers.js"></script> |
|---|
| 8 |
<script type="text/javascript"> |
|---|
| 9 |
var layer; |
|---|
| 10 |
var validkey = (window.location.protocol == "file:") || |
|---|
| 11 |
(window.location.host == "localhost") || |
|---|
| 12 |
(window.location.host == "openlayers.org"); |
|---|
| 13 |
|
|---|
| 14 |
function test_Layer_Google_message(t) { |
|---|
| 15 |
t.plan(0); |
|---|
| 16 |
if(gMess) { |
|---|
| 17 |
t.debug_print(gMess); |
|---|
| 18 |
} |
|---|
| 19 |
} |
|---|
| 20 |
|
|---|
| 21 |
function test_Layer_Google_constructor (t) { |
|---|
| 22 |
if(validkey) { |
|---|
| 23 |
t.plan( 4 ); |
|---|
| 24 |
|
|---|
| 25 |
var map = new OpenLayers.Map('map'); |
|---|
| 26 |
var layer = new OpenLayers.Layer.Google('Goog Layer'); |
|---|
| 27 |
map.addLayer(layer); |
|---|
| 28 |
|
|---|
| 29 |
|
|---|
| 30 |
t.ok( layer instanceof OpenLayers.Layer.Google, "new OpenLayers.Layer.Google returns object" ); |
|---|
| 31 |
t.eq( layer.CLASS_NAME, "OpenLayers.Layer.Google", "CLASS_NAME variable set correctly"); |
|---|
| 32 |
|
|---|
| 33 |
t.eq( layer.name, "Goog Layer", "layer.name is correct" ); |
|---|
| 34 |
|
|---|
| 35 |
t.ok ( layer.mapObject != null, "GMap2 Object correctly loaded"); |
|---|
| 36 |
} else { |
|---|
| 37 |
t.plan(0); |
|---|
| 38 |
t.debug_print("Google tests can't be run from " + |
|---|
| 39 |
window.location.host); |
|---|
| 40 |
} |
|---|
| 41 |
} |
|---|
| 42 |
|
|---|
| 43 |
function test_Layer_Google_isBaseLayer (t) { |
|---|
| 44 |
if(validkey) { |
|---|
| 45 |
t.plan(1); |
|---|
| 46 |
|
|---|
| 47 |
var layer = new OpenLayers.Layer.Google('Goog Layer'); |
|---|
| 48 |
|
|---|
| 49 |
t.ok(layer.isBaseLayer, "a default load of google layer responds as a base layer"); |
|---|
| 50 |
} else { |
|---|
| 51 |
t.plan(0); |
|---|
| 52 |
t.debug_print("Google tests can't be run from " + |
|---|
| 53 |
window.location.host); |
|---|
| 54 |
} |
|---|
| 55 |
} |
|---|
| 56 |
|
|---|
| 57 |
function test_Layer_Google_Translation_lonlat (t) { |
|---|
| 58 |
|
|---|
| 59 |
if(validkey) { |
|---|
| 60 |
t.plan( 4 ); |
|---|
| 61 |
|
|---|
| 62 |
var map = new OpenLayers.Map('map'); |
|---|
| 63 |
var layer = new OpenLayers.Layer.Google('Goog Layer'); |
|---|
| 64 |
map.addLayer(layer); |
|---|
| 65 |
|
|---|
| 66 |
// these two lines specify an appropriate translation. |
|---|
| 67 |
// the code afterwards works by itself to test that translation |
|---|
| 68 |
// works correctly both ways. |
|---|
| 69 |
var gLatLng = new GLatLng(50,100); |
|---|
| 70 |
var correspondingOLLonLat = new OpenLayers.LonLat(100,50); |
|---|
| 71 |
|
|---|
| 72 |
|
|---|
| 73 |
olLonLat = layer.getOLLonLatFromMapObjectLonLat(gLatLng); |
|---|
| 74 |
t.ok(olLonLat.equals(correspondingOLLonLat), "Translation from GLatLng to OpenLayers.LonLat works"); |
|---|
| 75 |
|
|---|
| 76 |
var transGLatLng = layer.getMapObjectLonLatFromOLLonLat(olLonLat); |
|---|
| 77 |
t.ok( transGLatLng.equals(gLatLng), "Translation from OpenLayers.LonLat to GLatLng works"); |
|---|
| 78 |
|
|---|
| 79 |
t.ok( layer.getMapObjectLonLatFromOLLonLat(null) == null, "getGLatLngFromOLLonLat(null) returns null"); |
|---|
| 80 |
t.ok( layer.getOLLonLatFromMapObjectLonLat(null) == null, "getOLLonLatFromGLatLng(null) returns null"); |
|---|
| 81 |
} else { |
|---|
| 82 |
t.plan(0); |
|---|
| 83 |
t.debug_print("Google tests can't be run from " + |
|---|
| 84 |
window.location.host); |
|---|
| 85 |
} |
|---|
| 86 |
} |
|---|
| 87 |
|
|---|
| 88 |
function test_Layer_Google_setMapType (t) { |
|---|
| 89 |
if (validkey) { |
|---|
| 90 |
t.plan(3); |
|---|
| 91 |
var layer = new OpenLayers.Layer.Google('Goog Layer'); |
|---|
| 92 |
layer.map = {'events':{'unregister': function() {}}}; |
|---|
| 93 |
layer.loadMapObject(); |
|---|
| 94 |
layer.mapObject.getCenter= function() { return true; } |
|---|
| 95 |
layer.mapObject.getMapTypes = function() { return [0, 1]; } |
|---|
| 96 |
layer.mapObject.addMapType = function(type) { |
|---|
| 97 |
t.eq(type, 5, "new map type passed correctly."); |
|---|
| 98 |
} |
|---|
| 99 |
layer.mapObject.setMapType = function(arg) { |
|---|
| 100 |
t.eq(arg, 5, "got map type"); |
|---|
| 101 |
} |
|---|
| 102 |
layer.type = 5; |
|---|
| 103 |
layer.setMapType(); |
|---|
| 104 |
layer.mapObject.setMapType = function(arg) { |
|---|
| 105 |
t.eq(arg, 0, "got map type"); |
|---|
| 106 |
} |
|---|
| 107 |
layer.type = 0 |
|---|
| 108 |
layer.setMapType(); |
|---|
| 109 |
|
|---|
| 110 |
} else { |
|---|
| 111 |
t.plan(0); |
|---|
| 112 |
t.debug_print("Google tests can't be run from " + |
|---|
| 113 |
window.location.host); |
|---|
| 114 |
} |
|---|
| 115 |
} |
|---|
| 116 |
|
|---|
| 117 |
function test_Layer_Google_Translation_pixel (t) { |
|---|
| 118 |
if(validkey) { |
|---|
| 119 |
t.plan( 4 ); |
|---|
| 120 |
|
|---|
| 121 |
var map = new OpenLayers.Map('map'); |
|---|
| 122 |
var layer = new OpenLayers.Layer.Google('Goog Layer'); |
|---|
| 123 |
map.addLayer(layer); |
|---|
| 124 |
|
|---|
| 125 |
// these two lines specify an appropriate translation. |
|---|
| 126 |
// the code afterwards works by itself to test that translation |
|---|
| 127 |
// works correctly both ways. |
|---|
| 128 |
var gPoint = new GPoint(50,100); |
|---|
| 129 |
var correspondingOLPixel = new OpenLayers.Pixel(50, 100); |
|---|
| 130 |
|
|---|
| 131 |
|
|---|
| 132 |
olPixel = layer.getOLPixelFromMapObjectPixel(gPoint); |
|---|
| 133 |
t.ok( olPixel.equals(correspondingOLPixel), "Translation from GPoint to OpenLayers.Pixel works"); |
|---|
| 134 |
|
|---|
| 135 |
var transGPoint = layer.getMapObjectPixelFromOLPixel(olPixel); |
|---|
| 136 |
t.ok( transGPoint.equals(gPoint), "Translation from OpenLayers.Pixel to GPoint works"); |
|---|
| 137 |
|
|---|
| 138 |
t.ok( layer.getMapObjectPixelFromOLPixel(null) == null, "getGPointFromOLPixel(null) returns null"); |
|---|
| 139 |
t.ok( layer.getOLPixelFromMapObjectPixel(null) == null, "getOLPixelFromGPoint(null) returns null"); |
|---|
| 140 |
} else { |
|---|
| 141 |
t.plan(0); |
|---|
| 142 |
t.debug_print("Google tests can't be run from " + |
|---|
| 143 |
window.location.host); |
|---|
| 144 |
} |
|---|
| 145 |
} |
|---|
| 146 |
|
|---|
| 147 |
function test_Layer_destroy (t) { |
|---|
| 148 |
if(validkey) { |
|---|
| 149 |
t.plan( 5 ); |
|---|
| 150 |
|
|---|
| 151 |
var map = new OpenLayers.Map('map'); |
|---|
| 152 |
|
|---|
| 153 |
layer = new OpenLayers.Layer.Google('Test Layer'); |
|---|
| 154 |
map.addLayer(layer); |
|---|
| 155 |
|
|---|
| 156 |
layer.destroy(); |
|---|
| 157 |
|
|---|
| 158 |
t.eq( layer.name, null, "layer.name is null after destroy" ); |
|---|
| 159 |
t.eq( layer.div, null, "layer.div is null after destroy" ); |
|---|
| 160 |
t.eq( layer.map, null, "layer.map is null after destroy" ); |
|---|
| 161 |
t.eq( layer.options, null, "layer.options is null after destroy" ); |
|---|
| 162 |
t.eq( layer.gmap, null, "layer.gmap is null after destroy" ); |
|---|
| 163 |
} else { |
|---|
| 164 |
t.plan(0); |
|---|
| 165 |
t.debug_print("Google tests can't be run from " + |
|---|
| 166 |
window.location.host); |
|---|
| 167 |
} |
|---|
| 168 |
} |
|---|
| 169 |
|
|---|
| 170 |
function test_Layer_Goole_forwardMercator(t){ |
|---|
| 171 |
if(validkey) { |
|---|
| 172 |
t.plan(2); |
|---|
| 173 |
//Just test that the fowardMercator function still exists. |
|---|
| 174 |
var layer = new OpenLayers.Layer.Google('Test Layer', {'sphericalMercator': true}); |
|---|
| 175 |
layer.forwardMercator = function(evt) { |
|---|
| 176 |
t.ok(true, |
|---|
| 177 |
"GoogleMercator.forwardMercator was called and executed." ); |
|---|
| 178 |
return; |
|---|
| 179 |
} |
|---|
| 180 |
layer.forwardMercator(); |
|---|
| 181 |
//Now test the fowardMercator returns the expected LonLat object |
|---|
| 182 |
var layer = new OpenLayers.Layer.Google('Test Layer', {'sphericalMercator': true}); |
|---|
| 183 |
var lonlat2 = new OpenLayers.LonLat(Math.random(),Math.random()); |
|---|
| 184 |
var result = layer.forwardMercator(lonlat2.lon, lonlat2.lat); |
|---|
| 185 |
t.ok(result instanceof OpenLayers.LonLat, "OpenLayers.Google.fowardMercator returns LonLat object" ); |
|---|
| 186 |
} else { |
|---|
| 187 |
t.plan(0); |
|---|
| 188 |
t.debug_print("Google tests can't be run from " + |
|---|
| 189 |
window.location.host); |
|---|
| 190 |
} |
|---|
| 191 |
} |
|---|
| 192 |
|
|---|
| 193 |
function test_Layer_Google_overlay(t) { |
|---|
| 194 |
// Test for #849. |
|---|
| 195 |
if(validkey) { |
|---|
| 196 |
t.plan(1); |
|---|
| 197 |
var map = new OpenLayers.Map( 'map' , |
|---|
| 198 |
{ controls: [] , 'numZoomLevels':20}); |
|---|
| 199 |
|
|---|
| 200 |
var satellite = new OpenLayers.Layer.Google( "Google Satellite" , {type: G_SATELLITE_MAP, 'maxZoomLevel':18} ); |
|---|
| 201 |
var layer = new OpenLayers.Layer.WMS.Untiled( "OpenLayers WMS", |
|---|
| 202 |
"http://labs.metacarta.com/wms/vmap0", {layers: 'basic', 'transparent':true}, |
|---|
| 203 |
{isBaseLayer: false} ); |
|---|
| 204 |
|
|---|
| 205 |
map.addLayers([satellite, layer]); |
|---|
| 206 |
map.setCenter(new OpenLayers.LonLat(10.205188,48.857593), 5); |
|---|
| 207 |
map.zoomIn(); |
|---|
| 208 |
var size = map.getSize(); |
|---|
| 209 |
var px = new OpenLayers.Pixel(size.w, size.h); |
|---|
| 210 |
var br = map.getLonLatFromPixel(px); |
|---|
| 211 |
t.ok(layer.grid[0][0].bounds.containsLonLat(br), "Bottom right pixel is covered by untiled WMS layer"); |
|---|
| 212 |
} else { |
|---|
| 213 |
t.plan(0); |
|---|
| 214 |
t.debug_print("Google tests can't be run from " + |
|---|
| 215 |
window.location.host); |
|---|
| 216 |
} |
|---|
| 217 |
} |
|---|
| 218 |
function test_Layer_Google_isBaseLayer (t) { |
|---|
| 219 |
if(validkey) { |
|---|
| 220 |
t.plan(3); |
|---|
| 221 |
var map = new OpenLayers.Map( 'map' , |
|---|
| 222 |
{ controls: [] , 'numZoomLevels':20}); |
|---|
| 223 |
|
|---|
| 224 |
var satellite = new OpenLayers.Layer.Google( "Google Satellite" , {type: G_SATELLITE_MAP, 'maxZoomLevel':18} ); |
|---|
| 225 |
map.addLayers([satellite]); |
|---|
| 226 |
map.zoomToMaxExtent(); |
|---|
| 227 |
|
|---|
| 228 |
t.eq(satellite.div.style.display, "", "Satellite layer is visible."); |
|---|
| 229 |
satellite.setVisibility(false); |
|---|
| 230 |
t.eq(satellite.div.style.display, "none", "Satellite layer is not visible."); |
|---|
| 231 |
satellite.setVisibility(true); |
|---|
| 232 |
t.eq(satellite.div.style.display, "block", "Satellite layer is visible."); |
|---|
| 233 |
|
|---|
| 234 |
} else { |
|---|
| 235 |
t.plan(0); |
|---|
| 236 |
t.debug_print("Google tests can't be run from " + |
|---|
| 237 |
window.location.host); |
|---|
| 238 |
} |
|---|
| 239 |
} |
|---|
| 240 |
|
|---|
| 241 |
</script> |
|---|
| 242 |
</head> |
|---|
| 243 |
<body> |
|---|
| 244 |
<div id="map" style="width:500px; height: 500px"></div> |
|---|
| 245 |
</body> |
|---|
| 246 |
</html> |
|---|