add displayProjection API Property on the Map, and on relevant controls.
Spherical mercator example now makes use of this, displaying coordinates in lon/lat instead of meters, and permalink/argparser now work in lon/lat as well. this functionality will make using SphericalMercator easier for a number of applications. r=tschaub (Closes #1036) git-svn-id: http://svn.openlayers.org/trunk/openlayers@5519 dc9f47b5-9b13-0410-9fdd-eb0c1a62fdaf
This commit is contained in:
@@ -30,6 +30,20 @@ OpenLayers.Control.ArgParser = OpenLayers.Class(OpenLayers.Control, {
|
||||
* {Array(<OpenLayers.Layer>)}
|
||||
*/
|
||||
layers: null,
|
||||
|
||||
/**
|
||||
* APIProperty: displayProjection
|
||||
* {<OpenLayers.Projection>} Requires proj4js support.
|
||||
* Projection used when reading the coordinates from the URL. This will
|
||||
* reproject the map coordinates from the URL into the map's
|
||||
* projection.
|
||||
*
|
||||
* If you are using this functionality, be aware that any permalink
|
||||
* which is added to the map will determine the coordinate type which
|
||||
* is read from the URL, which means you should not add permalinks with
|
||||
* different displayProjections to the same map.
|
||||
*/
|
||||
displayProjection: null,
|
||||
|
||||
/**
|
||||
* Constructor: OpenLayers.Control.ArgParser
|
||||
@@ -56,6 +70,14 @@ OpenLayers.Control.ArgParser = OpenLayers.Class(OpenLayers.Control, {
|
||||
var control = this.map.controls[i];
|
||||
if ( (control != this) &&
|
||||
(control.CLASS_NAME == "OpenLayers.Control.ArgParser") ) {
|
||||
|
||||
// If a second argparser is added to the map, then we
|
||||
// override the displayProjection to be the one added to the
|
||||
// map.
|
||||
if (control.displayProjection != this.displayProjection) {
|
||||
this.displayProjection = control.displayProjection;
|
||||
}
|
||||
|
||||
break;
|
||||
}
|
||||
}
|
||||
@@ -97,7 +119,12 @@ OpenLayers.Control.ArgParser = OpenLayers.Class(OpenLayers.Control, {
|
||||
//dont need to listen for this one anymore
|
||||
this.map.events.unregister('changebaselayer', this,
|
||||
this.setCenter);
|
||||
|
||||
|
||||
if (this.displayProjection) {
|
||||
this.center.transform(this.displayProjection,
|
||||
this.map.getProjectionObject());
|
||||
}
|
||||
|
||||
this.map.setCenter(this.center, this.zoom);
|
||||
}
|
||||
},
|
||||
|
||||
@@ -51,6 +51,13 @@ OpenLayers.Control.MousePosition = OpenLayers.Class(OpenLayers.Control, {
|
||||
* {<OpenLayers.LonLat>}
|
||||
*/
|
||||
lastXy: null,
|
||||
|
||||
/**
|
||||
* APIProperty: displayProjection
|
||||
* {<OpenLayers.Projection>} A projection that the
|
||||
* mousecontrol will display.
|
||||
*/
|
||||
displayProjection: null,
|
||||
|
||||
/**
|
||||
* Constructor: OpenLayers.Control.MousePosition
|
||||
@@ -113,7 +120,12 @@ OpenLayers.Control.MousePosition = OpenLayers.Class(OpenLayers.Control, {
|
||||
// map has not yet been properly initialized
|
||||
return;
|
||||
}
|
||||
if (this.displayProjection) {
|
||||
lonLat.transform(this.map.getProjectionObject(),
|
||||
this.displayProjection );
|
||||
}
|
||||
this.lastXy = evt.xy;
|
||||
|
||||
}
|
||||
|
||||
var digits = parseInt(this.numdigits);
|
||||
|
||||
@@ -25,6 +25,18 @@ OpenLayers.Control.Permalink = OpenLayers.Class(OpenLayers.Control, {
|
||||
*/
|
||||
base: '',
|
||||
|
||||
/**
|
||||
* APIProperty: displayProjection
|
||||
* {<OpenLayers.Projection>} Requires proj4js support. Projection used
|
||||
* when creating the coordinates in the link. This will reproject the
|
||||
* map coordinates into display coordinates. If you are using this
|
||||
* functionality, the permalink which is last added to the map will
|
||||
* determine the coordinate type which is read from the URL, which
|
||||
* means you should not add permalinks with different
|
||||
* displayProjections to the same map.
|
||||
*/
|
||||
displayProjection: null,
|
||||
|
||||
/**
|
||||
* Constructor: OpenLayers.Control.Permalink
|
||||
*
|
||||
@@ -67,11 +79,20 @@ OpenLayers.Control.Permalink = OpenLayers.Class(OpenLayers.Control, {
|
||||
for(var i=0; i< this.map.controls.length; i++) {
|
||||
var control = this.map.controls[i];
|
||||
if (control.CLASS_NAME == "OpenLayers.Control.ArgParser") {
|
||||
|
||||
// If a permalink is added to the map, and an ArgParser already
|
||||
// exists, we override the displayProjection to be the one
|
||||
// on the permalink.
|
||||
if (control.displayProjection != this.displayProjection) {
|
||||
this.displayProjection = control.displayProjection;
|
||||
}
|
||||
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (i == this.map.controls.length) {
|
||||
this.map.addControl(new OpenLayers.Control.ArgParser());
|
||||
this.map.addControl(new OpenLayers.Control.ArgParser(
|
||||
{ 'displayProjection': this.displayProjection }));
|
||||
}
|
||||
|
||||
},
|
||||
@@ -112,9 +133,20 @@ OpenLayers.Control.Permalink = OpenLayers.Class(OpenLayers.Control, {
|
||||
var params = OpenLayers.Util.getParameters(this.base);
|
||||
|
||||
params.zoom = this.map.getZoom();
|
||||
params.lat = Math.round(center.lat*100000)/100000;
|
||||
params.lon = Math.round(center.lon*100000)/100000;
|
||||
|
||||
var lat = center.lat;
|
||||
var lon = center.lon;
|
||||
|
||||
if (this.displayProjection) {
|
||||
var mapPosition = OpenLayers.Projection.transform(
|
||||
{ x: lon, y: lat },
|
||||
this.map.getProjectionObject(),
|
||||
this.displayProjection );
|
||||
lon = mapPosition.x;
|
||||
lat = mapPosition.y;
|
||||
}
|
||||
params.lat = Math.round(lat*100000)/100000;
|
||||
params.lon = Math.round(lon*100000)/100000;
|
||||
|
||||
params.layers = '';
|
||||
for(var i=0; i< this.map.layers.length; i++) {
|
||||
var layer = this.map.layers[i];
|
||||
|
||||
Reference in New Issue
Block a user