1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369
|
<html>
<head>
<script type="text/javascript">var oldAlert = window.alert, gMess; window.alert = function(message) {gMess = message; return true;};</script>
<!-- this gmaps key generated for http://openlayers.org/dev/ -->
<script src='http://maps.google.com/maps?file=api&v=2&key=ABQIAAAA9XNhd8q0UdwNC7YSO4YZghSPUCi5aRYVveCcVYxzezM4iaj_gxQ9t-UajFL70jfcpquH5l1IJ-Zyyw'></script>
<script type="text/javascript">window.alert = oldAlert;</script>
<script src="../OLLoader.js"></script>
<script type="text/javascript">
var layer;
var validkey = (window.location.protocol == "file:") ||
(window.location.host == "localhost") ||
(window.location.host == "openlayers.org");
function test_Layer_Google_message(t) {
t.plan(0);
if(gMess) {
t.debug_print(gMess);
}
}
function test_Layer_Google_constructor (t) {
if(validkey) {
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");
} else {
t.plan(0);
t.debug_print("Google tests can't be run from " +
window.location.host);
}
}
function test_clone(t) {
if (validkey) {
t.plan(2);
var layer, clone;
// test default layer
layer = new OpenLayers.Layer.Google();
clone = layer.clone();
t.ok(clone instanceof OpenLayers.Layer.Google, "[default] good instance");
layer.destroy();
clone.destroy();
// test with alt type
layer = new OpenLayers.Layer.Google(null, {type: G_SATELLITE_MAP});
clone = layer.clone();
t.ok(clone.type === G_SATELLITE_MAP, "[sat] correct type");
layer.destroy();
clone.destroy();
} else {
t.plan(0);
t.debug_print("Google tests can't be run from " +
window.location.host);
}
}
function test_Layer_Google_isBaseLayer (t) {
if(validkey) {
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");
} else {
t.plan(0);
t.debug_print("Google tests can't be run from " +
window.location.host);
}
}
function test_Layer_Google_Translation_lonlat (t) {
if(validkey) {
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");
} else {
t.plan(0);
t.debug_print("Google tests can't be run from " +
window.location.host);
}
}
function test_Layer_Google_Translation_pixel (t) {
if(validkey) {
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");
} else {
t.plan(0);
t.debug_print("Google tests can't be run from " +
window.location.host);
}
}
function test_Layer_destroy (t) {
if(validkey) {
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" );
} else {
t.plan(0);
t.debug_print("Google tests can't be run from " +
window.location.host);
}
}
function test_Layer_Goole_forwardMercator(t){
if(validkey) {
t.plan(2);
//Just test that the fowardMercator function still exists.
var layer = new OpenLayers.Layer.Google('Test Layer', {'sphericalMercator': true});
layer.forwardMercator = function(evt) {
t.ok(true,
"GoogleMercator.forwardMercator was called and executed." );
return;
}
layer.forwardMercator();
//Now test the fowardMercator returns the expected LonLat object
var layer = new OpenLayers.Layer.Google('Test Layer', {'sphericalMercator': true});
var lonlat2 = new OpenLayers.LonLat(Math.random(),Math.random());
var result = layer.forwardMercator(lonlat2.lon, lonlat2.lat);
t.ok(result instanceof OpenLayers.LonLat, "OpenLayers.Google.fowardMercator returns LonLat object" );
} else {
t.plan(0);
t.debug_print("Google tests can't be run from " +
window.location.host);
}
}
function test_Layer_Google_overlay(t) {
// Test for #849.
if(validkey) {
t.plan(1);
var map = new OpenLayers.Map( 'map' ,
{ controls: [] , 'numZoomLevels':20});
var satellite = new OpenLayers.Layer.Google( "Google Satellite" , {type: G_SATELLITE_MAP, 'maxZoomLevel':18} );
var layer = new OpenLayers.Layer.WMS( "OpenLayers WMS",
"http://labs.metacarta.com/wms/vmap0", {layers: 'basic', 'transparent':true},
{isBaseLayer: false, singleTile: true} );
map.addLayers([satellite, layer]);
map.setCenter(new OpenLayers.LonLat(10.205188,48.857593), 5);
map.zoomIn();
var size = map.getSize();
var px = new OpenLayers.Pixel(size.w, size.h);
var br = map.getLonLatFromPixel(px);
t.ok(layer.grid[0][0].bounds.containsLonLat(br), "Bottom right pixel is covered by untiled WMS layer");
} else {
t.plan(0);
t.debug_print("Google tests can't be run from " +
window.location.host);
}
}
function test_Layer_Google_isBaseLayer (t) {
if(validkey) {
t.plan(3);
var map = new OpenLayers.Map( 'map' ,
{ controls: [] , 'numZoomLevels':20});
var satellite = new OpenLayers.Layer.Google( "Google Satellite" , {type: G_SATELLITE_MAP, 'maxZoomLevel':18} );
map.addLayers([satellite]);
map.zoomToMaxExtent();
t.eq(satellite.div.style.display, "", "Satellite layer is visible.");
satellite.setVisibility(false);
t.eq(satellite.div.style.display, "none", "Satellite layer is not visible.");
satellite.setVisibility(true);
t.eq(satellite.div.style.display, "block", "Satellite layer is visible.");
} else {
t.plan(0);
t.debug_print("Google tests can't be run from " +
window.location.host);
}
}
function test_setOpacity(t) {
if(validkey) {
t.plan(6);
var map = new OpenLayers.Map("map");
var gmap = new OpenLayers.Layer.Google(
"Google Streets", // the default
{numZoomLevels: 20}
);
var ghyb = new OpenLayers.Layer.Google(
"Google Hybrid",
{type: G_HYBRID_MAP, numZoomLevels: 20}
);
var gsat = new OpenLayers.Layer.Google(
"Google Satellite",
{type: G_SATELLITE_MAP, numZoomLevels: 22}
);
map.addLayers([gmap, ghyb, gsat]);
map.zoomToMaxExtent();
var container = map.baseLayer.mapObject.getContainer();
var opacityCheck = function(opacity) {
var style = container.style;
var current = style.opacity === "" ? 1 : parseFloat(style.opacity);
if (style.filter && !style.opacity) {
current = Number(style.filter.replace(/alpha\(opacity=(.+?)\)/, "$1"));
}
return (current === opacity);
};
gmap.setOpacity(0.5);
t.ok(opacityCheck(0.5), "container opacity set for visible layer");
ghyb.setOpacity(0.75);
t.ok(opacityCheck(0.5), "container opacity not changed if layer not visible");
map.setBaseLayer(ghyb);
t.ok(opacityCheck(0.75), "container opacity changed to 0.75 when layer becomes visible");
map.setBaseLayer(gsat);
t.ok(opacityCheck(1), "container opacity set to 1 by default");
gsat.setOpacity(0.25);
t.ok(opacityCheck(0.25), "container opacity changed to 0.25 for visible layer");
map.setBaseLayer(gmap);
t.ok(opacityCheck(0.5), "container opacity set to layer opacity");
map.destroy();
} else {
t.plan(0);
t.debug_print("Google tests can't be run from " +
window.location.host);
}
}
function test_Layer_Google_setGMapVisibility(t) {
if(validkey) {
t.plan(4);
var map1 = new OpenLayers.Map('map');
var gmap1 = new OpenLayers.Layer.Google("Google Streets");
var dummy1 = new OpenLayers.Layer("Dummy", {isBaseLayer: true});
map1.addLayers([dummy1, gmap1]);
map1.zoomToMaxExtent();
t.delay_call(2, function() {
t.ok(gmap1.termsOfUse.style.display == "none" || gmap1.termsOfUse.style.left == "-9999px", "termsOfUse is not visible");
t.eq(gmap1.poweredBy.style.display, "none", "poweredBy is not visible");
map1.destroy();
});
var map2 = new OpenLayers.Map('map', {allOverlays: true});
var gmap2 = new OpenLayers.Layer.Google("Google Streets", {visibility: false});
var dummy2 = new OpenLayers.Layer("Dummy");
map2.addLayers([gmap2, dummy2]);
map2.zoomToMaxExtent();
t.delay_call(2, function() {
t.ok(gmap2.termsOfUse.style.display == "none" || gmap2.termsOfUse.style.left == "-9999px", "allOverlays:true - termsOfUse is not visible");
t.eq(gmap2.poweredBy.style.display, "none", "allOverlays:true - poweredBy is not visible");
map2.destroy();
});
} else {
t.plan(0);
t.debug_print("Google tests can't be run from " +
window.location.host);
}
}
function test_sphericalMercator(t) {
if (validkey) {
t.plan(4);
var map, layer;
map = new OpenLayers.Map("map");
layer = new OpenLayers.Layer.Google();
map.addLayer(layer);
t.ok(!layer.sphericalMercator, "sphericalMercator false by default");
t.eq(map.getProjection(), "EPSG:4326", "4326 by default without sphericalMercator");
map.destroy();
map = new OpenLayers.Map("map");
layer = new OpenLayers.Layer.Google(null, {
sphericalMercator: true
});
map.addLayer(layer);
t.eq(map.getProjection(), "EPSG:900913", "900913 by default with sphericalMercator");
map.destroy();
map = new OpenLayers.Map("map");
layer = new OpenLayers.Layer.Google(null, {
sphericalMercator: true,
projection: "EPSG:102113"
});
map.addLayer(layer);
t.eq(map.getProjection(), "EPSG:102113", "custom code respected with sphericalMercator");
map.destroy();
} else {
t.plan(0);
t.debug_print("Google tests can't be run from " +
window.location.host);
}
}
</script>
</head>
<body>
<div id="map" style="width:500px; height: 500px"></div>
</body>
</html>
|