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.setCenter(new OpenLayers.LonLat(lon, lat), zoom);
|
||||||
map.addControl(new OpenLayers.Control.LayerSwitcher());
|
map.addControl(new OpenLayers.Control.LayerSwitcher());
|
||||||
|
map.addControl(new OpenLayers.Control.ScaleLine());
|
||||||
}
|
}
|
||||||
</script>
|
</script>
|
||||||
</head>
|
</head>
|
||||||
|
|||||||
@@ -495,7 +495,7 @@ OpenLayers.Control.OverviewMap = OpenLayers.Class(OpenLayers.Control, {
|
|||||||
updateRectToMap: function() {
|
updateRectToMap: function() {
|
||||||
// The base layer for overview map needs to be in the same projection
|
// 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.
|
// 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())) {
|
if(this.ovmap.getProjection() && (this.map.getProjection() != this.ovmap.getProjection())) {
|
||||||
alert(OpenLayers.i18n("sameProjection"));
|
alert(OpenLayers.i18n("sameProjection"));
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -153,7 +153,7 @@ OpenLayers.Control.ScaleLine = OpenLayers.Class(OpenLayers.Control, {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
var curMapUnits = this.map.units;
|
var curMapUnits = this.map.getUnits();
|
||||||
var inches = OpenLayers.INCHES_PER_UNIT;
|
var inches = OpenLayers.INCHES_PER_UNIT;
|
||||||
|
|
||||||
// convert maxWidth to map units
|
// convert maxWidth to map units
|
||||||
|
|||||||
@@ -1763,6 +1763,21 @@ OpenLayers.Map = OpenLayers.Class({
|
|||||||
return resolution;
|
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
|
* APIMethod: getScale
|
||||||
*
|
*
|
||||||
|
|||||||
@@ -86,8 +86,8 @@
|
|||||||
map.addControl(control);
|
map.addControl(control);
|
||||||
t.eq(control.div.firstChild.style.visibility, "visible", "top scale is present.");
|
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.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.firstChild.innerHTML, "200 m", "top scale has correct text.");
|
||||||
t.eq(control.div.lastChild.innerHTML, "20000 mi", "bottom scale has correct text.");
|
t.eq(control.div.lastChild.innerHTML, "1000 ft", "bottom scale has correct text.");
|
||||||
map.destroy();
|
map.destroy();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1000,6 +1000,23 @@
|
|||||||
layer.destroy();
|
layer.destroy();
|
||||||
map.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) {
|
function test_Map_destroy (t) {
|
||||||
t.plan( 3 );
|
t.plan( 3 );
|
||||||
|
|||||||
Reference in New Issue
Block a user