From 5c6934b0b03e130876762a72b3cc37ec97d8e377 Mon Sep 17 00:00:00 2001 From: crschmidt Date: Wed, 19 Dec 2007 01:33:20 +0000 Subject: [PATCH] Allow the use of custom GMapTypes via the Layer.Google. When passed a type in the Layer.Google constructor, we check if the type we are given is not in the map's list of types, and if so, add it. (Closes #1082) r=tschaub git-svn-id: http://svn.openlayers.org/trunk/openlayers@5504 dc9f47b5-9b13-0410-9fdd-eb0c1a62fdaf --- lib/OpenLayers/Layer/Google.js | 7 +++++++ tests/Layer/test_Google.html | 29 +++++++++++++++++++++++++++++ 2 files changed, 36 insertions(+) diff --git a/lib/OpenLayers/Layer/Google.js b/lib/OpenLayers/Layer/Google.js index 6282851d0c..257002b4e3 100644 --- a/lib/OpenLayers/Layer/Google.js +++ b/lib/OpenLayers/Layer/Google.js @@ -159,6 +159,13 @@ OpenLayers.Layer.Google = OpenLayers.Class( */ setMapType: function() { if (this.mapObject.getCenter() != null) { + + // Support for custom map types. + if (OpenLayers.Util.indexOf(this.mapObject.getMapTypes(), + this.type) == -1) { + this.mapObject.addMapType(this.type); + } + this.mapObject.setMapType(this.type); this.map.events.unregister("moveend", this, this.setMapType); } diff --git a/tests/Layer/test_Google.html b/tests/Layer/test_Google.html index 2f8e81d950..cf56a47244 100644 --- a/tests/Layer/test_Google.html +++ b/tests/Layer/test_Google.html @@ -85,6 +85,35 @@ } } + function test_Layer_Google_setMapType (t) { + if (validkey) { + t.plan(3); + var layer = new OpenLayers.Layer.Google('Goog Layer'); + layer.map = {'events':{'unregister': function() {}}}; + layer.loadMapObject(); + layer.mapObject.getCenter= function() { return true; } + layer.mapObject.getMapTypes = function() { return [0, 1]; } + layer.mapObject.addMapType = function(type) { + t.eq(type, 5, "new map type passed correctly."); + } + layer.mapObject.setMapType = function(arg) { + t.eq(arg, 5, "got map type"); + } + layer.type = 5; + layer.setMapType(); + layer.mapObject.setMapType = function(arg) { + t.eq(arg, 0, "got map type"); + } + layer.type = 0 + layer.setMapType(); + + } else { + t.plan(0); + t.debug_print("Google tests can't be run from " + + window.location.host); + } + } + function test_04_Layer_Google_Translation_pixel (t) { if(validkey) { t.plan( 4 );