Yes, this is the difficult solution. It works, but I was thinking in
another direction. As Bart pointed out, it is possible to put multiple
Mouseposition controls with different DisplayProjections on a page by
means css classes. This means that I can influence the position of these
controls and their projected coordinate values without any other
formating. However, I would also like to be able to change to format of
a lon-lat value to degrees-minutes-seconds. Is there a way to get at the
numeric value of a MousePosition control and alter it?
There are other possibilities for this. Older maps often have national
central meridians, like Paris, Amsterdam, Djakarta. To see the
lon-values on those map in Greenwich values, all lon values need to be
added with a constant. It would be nice if that could be done
automatically via the MousePointer control.
Jan
On 1/10/2013 2:46 PM, Richard Greenwood wrote:
On Thu, Jan 10, 2013 at 6:02 AM, Jan Hartmann <[email protected]
<mailto:[email protected]>> wrote:
Hi Rich, how did you get the lon-lat values on your map formattted
as degrees/minutes/seconds (next to the default decimal degrees?)
Hey Jan -
The hardest part was getting the coordinates to be the same width so
that they did not cause other page elements to move. Without that the
display was quite "jittery". My code is below. I'm using my original
CSCS transformation library, not proj4js, but that shouldn't matter.
Best regards,
Rich
rwg.cursorCoords = function(e) {
var position = this.events.getMousePosition(e);
var pointXY = this.getLonLatFromPixel(position); /* this has a
transform method */
var p = new CSCS.PT <http://CSCS.PT>(pointXY.lon, pointXY.lat);
var text;
/* *** Private functions ***************** */
var zeroPad2 = function(num) {
num += '';
return (num.length<2) ? "0"+num : num;
};
var zeroPad4 = function(num) {
num += '';
return (num.length<4) ? "0"+num : num;
};
var dd2dms = function(v) {
var fv = v % 1; // fractional part
var d = v - fv; // integer part (degrees)
fv = Math.abs(fv);
var m = fv * 60; // minutes
var mf = m % 1; // fractional part of minutes
var mi = m - mf; // integer part of minutes
var s = Math.round(mf*600)/10; // seconds
s = s.toFixed(1);
return d + "° " + zeroPad2(mi) + "' "+ zeroPad4(s)
+ """;
};
// display original state plane coords
text = "N: " + Math.round(p.y) + " E: " + Math.round(p.x);
OpenLayers.Util.getElement("coords").innerHTML = text;
// convert to long/lat and display
CSCS.transform(csSP, csLL, p);
text = "<table cellpadding=\"0\" cellspacing=\"0\"><tr><td>";
text += "Long: " + dd2dms(p.x) + "</td><td> Lat: " +
dd2dms(p.y);
text += "</td></tr><tr><td>Long: " +
Math.round(p.x*10000)/10000 + "°</td><td> Lat: " +
Math.round(p.y*10000)/10000;
text += "°</td></tr></table>";
OpenLayers.Util.getElement("coordsLL").innerHTML = text;
// convert long/lat to UTM and display
CSCS.transform(csLL, csUTM, p);
text = "X =" + Math.round(p.x) + " Y = " + Math.round(p.y);
OpenLayers.Util.getElement("coordsUTM").innerHTML = text;
};
--
Richard Greenwood
[email protected] <mailto:[email protected]>
www.greenwoodmap.com <http://www.greenwoodmap.com>
_______________________________________________
Users mailing list
[email protected]
http://lists.osgeo.org/mailman/listinfo/openlayers-users