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">
10 var validkey = (window.location.protocol == "file:") ||
11 (window.location.host == "localhost") ||
12 (window.location.host == "openlayers.org");
14 function test_Layer_Google_message(t) {
21 function test_Layer_Google_constructor (t) {
25 var map = new OpenLayers.Map('map');
26 var layer = new OpenLayers.Layer.Google('Goog Layer');
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");
33 t.eq( layer.name, "Goog Layer", "layer.name is correct" );
35 t.ok ( layer.mapObject != null, "GMap2 Object correctly loaded");
38 t.debug_print("Google tests can't be run from " +
39 window.location.host);
43 function test_Layer_Google_isBaseLayer (t) {
47 var layer = new OpenLayers.Layer.Google('Goog Layer');
49 t.ok(layer.isBaseLayer, "a default load of google layer responds as a base layer");
52 t.debug_print("Google tests can't be run from " +
53 window.location.host);
57 function test_Layer_Google_Translation_lonlat (t) {
62 var map = new OpenLayers.Map('map');
63 var layer = new OpenLayers.Layer.Google('Goog Layer');
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);
73 olLonLat = layer.getOLLonLatFromMapObjectLonLat(gLatLng);
74 t.ok(olLonLat.equals(correspondingOLLonLat), "Translation from GLatLng to OpenLayers.LonLat works");
76 var transGLatLng = layer.getMapObjectLonLatFromOLLonLat(olLonLat);
77 t.ok( transGLatLng.equals(gLatLng), "Translation from OpenLayers.LonLat to GLatLng works");
79 t.ok( layer.getMapObjectLonLatFromOLLonLat(null) == null, "getGLatLngFromOLLonLat(null) returns null");
80 t.ok( layer.getOLLonLatFromMapObjectLonLat(null) == null, "getOLLonLatFromGLatLng(null) returns null");
83 t.debug_print("Google tests can't be run from " +
84 window.location.host);
88 function test_Layer_Google_setMapType (t) {
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.");
99 layer.mapObject.setMapType = function(arg) {
100 t.eq(arg, 5, "got map type");
104 layer.mapObject.setMapType = function(arg) {
105 t.eq(arg, 0, "got map type");
112 t.debug_print("Google tests can't be run from " +
113 window.location.host);
117 function test_Layer_Google_Translation_pixel (t) {
121 var map = new OpenLayers.Map('map');
122 var layer = new OpenLayers.Layer.Google('Goog Layer');
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);
132 olPixel = layer.getOLPixelFromMapObjectPixel(gPoint);
133 t.ok( olPixel.equals(correspondingOLPixel), "Translation from GPoint to OpenLayers.Pixel works");
135 var transGPoint = layer.getMapObjectPixelFromOLPixel(olPixel);
136 t.ok( transGPoint.equals(gPoint), "Translation from OpenLayers.Pixel to GPoint works");
138 t.ok( layer.getMapObjectPixelFromOLPixel(null) == null, "getGPointFromOLPixel(null) returns null");
139 t.ok( layer.getOLPixelFromMapObjectPixel(null) == null, "getOLPixelFromGPoint(null) returns null");
142 t.debug_print("Google tests can't be run from " +
143 window.location.host);
147 function test_Layer_destroy (t) {
151 var map = new OpenLayers.Map('map');
153 layer = new OpenLayers.Layer.Google('Test Layer');
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" );
165 t.debug_print("Google tests can't be run from " +
166 window.location.host);
170 function test_Layer_Goole_forwardMercator(t){
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) {
177 "GoogleMercator.forwardMercator was called and executed." );
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" );
188 t.debug_print("Google tests can't be run from " +
189 window.location.host);
193 function test_Layer_Google_overlay(t) {
197 var map = new OpenLayers.Map( 'map' ,
198 { controls: [] , 'numZoomLevels':20});
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} );
205 map.addLayers([satellite, layer]);
206 map.setCenter(new OpenLayers.LonLat(10.205188,48.857593), 5);
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");
214 t.debug_print("Google tests can't be run from " +
215 window.location.host);
218 function test_Layer_Google_isBaseLayer (t) {
221 var map = new OpenLayers.Map( 'map' ,
222 { controls: [] , 'numZoomLevels':20});
224 var satellite = new OpenLayers.Layer.Google( "Google Satellite" , {type: G_SATELLITE_MAP, 'maxZoomLevel':18} );
225 map.addLayers([satellite]);
226 map.zoomToMaxExtent();
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.");
236 t.debug_print("Google tests can't be run from " +
237 window.location.host);
244 <div id="map" style="width:500px; height: 500px"></div>