From 4340867918f8eddd1b297376f8e050b8a175f684 Mon Sep 17 00:00:00 2001 From: pgiraud Date: Wed, 18 Jun 2008 08:57:02 +0000 Subject: [PATCH] add a map getUnits method, r=ahocevar (Closes 1591) git-svn-id: http://svn.openlayers.org/trunk/openlayers@7374 dc9f47b5-9b13-0410-9fdd-eb0c1a62fdaf --- examples/projected-map.html | 1 + lib/OpenLayers/Control/OverviewMap.js | 2 +- lib/OpenLayers/Control/ScaleLine.js | 2 +- lib/OpenLayers/Map.js | 15 +++++++++++++++ tests/Control/ScaleLine.html | 4 ++-- tests/Map.html | 17 +++++++++++++++++ 6 files changed, 37 insertions(+), 4 deletions(-) diff --git a/examples/projected-map.html b/examples/projected-map.html index 07ffa8e2a9..6b77a4599b 100644 --- a/examples/projected-map.html +++ b/examples/projected-map.html @@ -47,6 +47,7 @@ map.setCenter(new OpenLayers.LonLat(lon, lat), zoom); map.addControl(new OpenLayers.Control.LayerSwitcher()); + map.addControl(new OpenLayers.Control.ScaleLine()); } diff --git a/lib/OpenLayers/Control/OverviewMap.js b/lib/OpenLayers/Control/OverviewMap.js index 12a9def34f..e1ffab6c23 100644 --- a/lib/OpenLayers/Control/OverviewMap.js +++ b/lib/OpenLayers/Control/OverviewMap.js @@ -495,7 +495,7 @@ OpenLayers.Control.OverviewMap = OpenLayers.Class(OpenLayers.Control, { updateRectToMap: function() { // The base layer for overview map needs to be in the same projection // as the base layer for the main map. This should be made more robust. - if(this.map.units != 'degrees') { + if(this.map.getUnits() != 'degrees') { if(this.ovmap.getProjection() && (this.map.getProjection() != this.ovmap.getProjection())) { alert(OpenLayers.i18n("sameProjection")); } diff --git a/lib/OpenLayers/Control/ScaleLine.js b/lib/OpenLayers/Control/ScaleLine.js index 5c3e7892c7..df1c51e939 100644 --- a/lib/OpenLayers/Control/ScaleLine.js +++ b/lib/OpenLayers/Control/ScaleLine.js @@ -153,7 +153,7 @@ OpenLayers.Control.ScaleLine = OpenLayers.Class(OpenLayers.Control, { return; } - var curMapUnits = this.map.units; + var curMapUnits = this.map.getUnits(); var inches = OpenLayers.INCHES_PER_UNIT; // convert maxWidth to map units diff --git a/lib/OpenLayers/Map.js b/lib/OpenLayers/Map.js index 9fe62a421e..3e553afa9d 100644 --- a/lib/OpenLayers/Map.js +++ b/lib/OpenLayers/Map.js @@ -1763,6 +1763,21 @@ OpenLayers.Map = OpenLayers.Class({ return resolution; }, + /** + * APIMethod: getUnits + * + * Returns: + * {Float} The current units of the map. + * If no baselayer is set, returns null. + */ + getUnits: function () { + var units = null; + if (this.baseLayer != null) { + units = this.baseLayer.units; + } + return units; + }, + /** * APIMethod: getScale * diff --git a/tests/Control/ScaleLine.html b/tests/Control/ScaleLine.html index 019d9f7a23..a560cf9721 100644 --- a/tests/Control/ScaleLine.html +++ b/tests/Control/ScaleLine.html @@ -86,8 +86,8 @@ map.addControl(control); t.eq(control.div.firstChild.style.visibility, "visible", "top scale is present."); t.eq(control.div.lastChild.style.visibility, "visible", "bottom scale is present."); - t.eq(control.div.firstChild.innerHTML, "20000 km", "top scale has correct text."); - t.eq(control.div.lastChild.innerHTML, "20000 mi", "bottom scale has correct text."); + t.eq(control.div.firstChild.innerHTML, "200 m", "top scale has correct text."); + t.eq(control.div.lastChild.innerHTML, "1000 ft", "bottom scale has correct text."); map.destroy(); } diff --git a/tests/Map.html b/tests/Map.html index c9b35446b5..2c1542c037 100644 --- a/tests/Map.html +++ b/tests/Map.html @@ -1000,6 +1000,23 @@ layer.destroy(); map.destroy(); } + + function test_Map_getUnits(t) { + t.plan(2); + var map = new OpenLayers.Map("map"); + var units = map.getUnits(); + t.eq(units, null, "getUnits returns null for no base layer"); + + var layer = new OpenLayers.Layer("test", { + isBaseLayer: true, + units: 'foo' + }); + map.addLayer(layer); + var units = map.getUnits(); + t.eq(units, 'foo', "getUnits returns the base layer units property"); + layer.destroy(); + map.destroy(); + } function test_Map_destroy (t) { t.plan( 3 );