[OpenLayers-Dev] Translate mousecoordinates and show them on page

Michael Adair madair at dmsolutions.ca
Thu Jul 21 10:00:27 EDT 2011


Did you include the projection definitions in your code somewhere?

Proj4js.defs["EPSG:3008"] = "+proj=tmerc +lat_0=0 +lon_0=13.5 +k=1 +x_0=150000 +y_0=0 +ellps=GRS80 +towgs84=0,0,0,0,0,0,0 +units=m +no_defs";
Proj4js.defs["EPSG:3006"] = "+proj=utm +zone=33 +ellps=GRS80 +towgs84=0,0,0,0,0,0,0 +units=m +no_defs";
Proj4js.defs["EPSG:3021"] = "+proj=tmerc +lat_0=0 +lon_0=15.80827777777778 +k=1 +x_0=1500000 +y_0=0 +ellps=bessel +units=m +no_defs";

I got these values from spatialreference.org

Mike




On 21/07/2011 7:55 AM, LightningStrike wrote:
> I'm trying to transform mouse coordinates but it doesn't work, i want to show
> the coordinates in four different ways. "LonLat", "SWEREF99TM", "SWEREF99 13
> 30" and in "RT90"
> The code is something like this
>
> the map is in "EPSG:3008" so i'm not shore which format
> map.getLonLatFromViewPortPx(e.xy) gets, is it the maps projection or LonLat?
> <----------------START--------------->
> var mousepos = map.getLonLatFromViewPortPx(e.xy);
> 			
> var sweref = mousepos.transform(new OpenLayers.Projection("EPSG:3006"),new
> OpenLayers.Projection("EPSG:3008"));
> var lonlat  =  mousepos.transform(new OpenLayers.Projection("EPSG:3006"),new
> OpenLayers.Projection("EPSG:4326"));
> var rt90  =  mousepos.transform(new OpenLayers.Projection("EPSG:3006"),new
> OpenLayers.Projection("EPSG:3021"));
> 			
> OpenLayers.Util.getElement("coords1").innerHTML = "*Halmstads lokala
> (SWEREF99 13 30):*<br/>" + mousepos;
> OpenLayers.Util.getElement("coords2").innerHTML = "*Long/Lat:*<br/>" +
> lonlat;
> OpenLayers.Util.getElement("coords3").innerHTML = "*SWEREF99 TM:*<br/>" +
> sweref;
> OpenLayers.Util.getElement("coords4").innerHTML = "*RT90 2.5 gon V:*<br/>"
> + rt90;
> <-----------------------END----------------------->
>
> The output shows the same coordinates as the map uses on all four so the
> transformations doesn't work
>
> --
> View this message in context: http://osgeo-org.1803224.n2.nabble.com/Translate-mousecoordinates-and-show-them-on-page-tp6606425p6606425.html
> Sent from the OpenLayers Dev mailing list archive at Nabble.com.
> _______________________________________________
> Dev mailing list
> Dev at lists.osgeo.org
> http://lists.osgeo.org/mailman/listinfo/openlayers-dev


More information about the Dev mailing list