Files
openlayers/tests/test_Layer_Google.html
2006-08-08 18:20:24 +00:00

157 lines
5.9 KiB
HTML

<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.gmap != 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_zoom (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 gZoom = 5;
var correspondingOLZoom = 5;
olZoom = layer.getOLZoomFromGZoom(gZoom);
t.eq(olZoom, correspondingOLZoom, "Translation from GZoom to OL Zoom works");
t.eq(layer.getGZoomFromOLZoom(olZoom), gZoom, "Translation from OL Zoom to GZoom works");
t.ok( layer.getGZoomFromOLZoom(null) == null, "getGZoomFromOLZoom(null) returns null");
t.ok( layer.getOLZoomFromGZoom(null) == null, "getOLZoomFromGZoom(null) returns null");
}
function test_04_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.getOLLonLatFromGLatLng(gLatLng);
t.ok(olLonLat.equals(correspondingOLLonLat), "Translation from GLatLng to OpenLayers.LonLat works");
var transGLatLng = layer.getGLatLngFromOLLonLat(olLonLat);
t.ok( transGLatLng.equals(gLatLng), "Translation from OpenLayers.LonLat to GLatLng works");
t.ok( layer.getGLatLngFromOLLonLat(null) == null, "getGLatLngFromOLLonLat(null) returns null");
t.ok( layer.getOLLonLatFromGLatLng(null) == null, "getOLLonLatFromGLatLng(null) returns null");
}
function test_05_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.getOLPixelFromGPoint(gPoint);
t.ok( olPixel.equals(correspondingOLPixel), "Translation from GPoint to OpenLayers.Pixel works");
var transGPoint = layer.getGPointFromOLPixel(olPixel);
t.ok( transGPoint.equals(gPoint), "Translation from OpenLayers.Pixel to GPoint works");
t.ok( layer.getGPointFromOLPixel(null) == null, "getGPointFromOLPixel(null) returns null");
t.ok( layer.getOLPixelFromGPoint(null) == null, "getOLPixelFromGPoint(null) returns null");
}
function test_06_Layer_Google_Translation_bounds (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 sw = new GLatLng(10,20);
var ne = new GLatLng(50,40)
var gBounds = new GLatLngBounds(sw, ne);
var correspondingOLBounds = new OpenLayers.Bounds(20, 10, 40, 50);
olBounds = layer.getOLBoundsFromGLatLngBounds(gBounds);
t.ok(olBounds.equals(correspondingOLBounds), "Translation from GLatLngBounds to OpenLayers.Bounds works");
var transGBounds = layer.getGLatLngBoundsFromOLBounds(olBounds);
t.ok( transGBounds.equals(gBounds), "Translation from OpenLayers.Bounds to GLatLngBounds works");
t.ok( layer.getGLatLngBoundsFromOLBounds(null) == null, "getGLatLngBoundsFromOLBounds(null) returns null");
t.ok( layer.getOLBoundsFromGLatLngBounds(null) == null, "getOLBoundsFromGLatLngBounds(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>