add a map getUnits method, r=ahocevar (Closes 1591)
git-svn-id: http://svn.openlayers.org/trunk/openlayers@7374 dc9f47b5-9b13-0410-9fdd-eb0c1a62fdaf
This commit is contained in:
@@ -47,6 +47,7 @@
|
||||
|
||||
map.setCenter(new OpenLayers.LonLat(lon, lat), zoom);
|
||||
map.addControl(new OpenLayers.Control.LayerSwitcher());
|
||||
map.addControl(new OpenLayers.Control.ScaleLine());
|
||||
}
|
||||
</script>
|
||||
</head>
|
||||
|
||||
@@ -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"));
|
||||
}
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
*
|
||||
|
||||
@@ -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();
|
||||
}
|
||||
|
||||
|
||||
@@ -1001,6 +1001,23 @@
|
||||
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 );
|
||||
map = new OpenLayers.Map('map');
|
||||
|
||||
Reference in New Issue
Block a user