[OpenLayers-Users] How to convert a coordinate like 5383153.349692758 to 43.468243 ?

Paul Spencer pagameba at gmail.com
Mon Jun 22 08:47:18 EDT 2009


Note that transform does not return a new instance of LonLat, it  
modifies the instance that the method was invoked on.

lonLat.transform(source, destination);

if you want to preserve the original, you must clone it first ...

clonedLonLat = lonLat.clone();
clonedLonLat.transform(source, destination)

Note: If you are using the proj4js library with OpenLayers, you should  
be aware that it marks a geometry as transformed and will not  
transform it again unless you unset the flag, so if you want to  
transform from 900913 to 4326 and then back again at some later point,  
you will not get the expected results.

Cheers

Paul

On 21-Jun-09, at 5:54 AM, toni hernández wrote:

> hi,
> I guess you need to transform the coords from 900913 system to 4326,  
> don't you?
>
> I am not an expert but I think you just need to use the transform  
> function.
> firt get a var called yourcoords (in the example I wrote) with the  
> coordenate you want to transform.
>
> Then do the transform.. like this.
>
> newcoords = yourcoords.transform(new OpenLayers.Projection("EPSG: 
> 900913"),new OpenLayers.Projection("4326"))
>
> 900913 and 4326 are defined (I think) in Openlayers. If this is not  
> working then you can try to do the transform with the proj4js api.  
> If you do, read first this. http://trac.osgeo.org/proj4js/wiki/UserGuide
>
> On Sun, Jun 21, 2009 at 11:35 AM, Jan Martin <janmartin3 at googlemail.com 
> > wrote:
> Hi all,
> I have been fiddling with this way too long already, so I ask:
>
> After changing the Click Event Example a bit I am getting  
> coordinates like this:
>
> 5383153.349692758      1323087.0961396247
>
> Click Event Example: http://www.openlayers.org/dev/examples/click.html
>
> However I need them like this:
> 43.468243    11.880172
>
> Btw. same format as the coordinates in the "data.txt".
>
> I think "All I DID" is changing from WMS to OSM Layers?
> How to automatically convert?
>
> Thanks.
>
>
>
>
> Please find my code:
>
> <html>
> <head>
> <title>map3</title>
>     <style type="text/css">
>         #map {	width: 90%;
> 		height: 90%;
> 		border: 1px solid black;}
>
>
>
>     </style>
>
> <script src="OpenLayers.js"></script>
> <script src="OpenStreetMap.js"></script>
>
> 	<script type="text/javascript">
>             OpenLayers.Control.Click =  
> OpenLayers.Class(OpenLayers.Control, {
>
>
>
>                 defaultHandlerOptions: {
>                     'single': true,
>                     'double': false,
>                     'pixelTolerance': 0,
>                     'stopSingle': false,
>
>
>
>                     'stopDouble': false
>                 },
>
>                 initialize: function(options) {
>                     this.handlerOptions = OpenLayers.Util.extend(
>                         {}, this.defaultHandlerOptions
>
>
>
>                     );
>                     OpenLayers.Control.prototype.initialize.apply(
>                         this, arguments
>                     );
>                     this.handler = new OpenLayers.Handler.Click(
>
>
>
>                         this, {
>                             'click': this.trigger
>                         }, this.handlerOptions
>                     );
>                 },
>
>                 trigger: function(e) {
>
>
>
>                 var lonlat = map.getLonLatFromViewPortPx(e.xy);
>                     alert("You clicked: " + lonlat.lat  + "   " +  
> lonlat.lon);
>                 }
>
>             });
>
> 		var map;
>
>
>
> 		function init() {
> 			map = new OpenLayers.Map ("map", {
> 				controls:[
> 					new OpenLayers.Control.Navigation(),
> 					new OpenLayers.Control.PanZoomBar(),
> 					new OpenLayers.Control.LayerSwitcher(),
>
>
>
> 					],
> 			} );
>
> 			layerMapnik = new OpenLayers.Layer.OSM.Mapnik("Mapnik");
> 			map.addLayer(layerMapnik,{layers: 'basic'});
> 			layerTilesAtHome = new  
> OpenLayers.Layer.OSM.Osmarender("Osmarender");
>
>
>
> 			map.addLayer(layerTilesAtHome);
> 			layerCycleMap = new OpenLayers.Layer.OSM.CycleMap("CycleMap");
> 			map.addLayer(layerCycleMap);
>
>                 var click = new OpenLayers.Control.Click();
>                 map.addControl(click);
>
>
>
>                 click.activate();
>
> 		var dataExtent;
> 		var setExtent = function() {
> 			if(dataExtent) {dataExtent.extend(this.getDataExtent());}
> 			else {dataExtent = this.getDataExtent();}
> 			map.zoomToExtent(dataExtent);
>
>
>
> 		};
>
> 			var newl = new OpenLayers.Layer.Text( "text", {
> 			location: "data.txt",
> 			} );
> 			newl.events.register("loadend", newl, setExtent);
> 			map.addLayer(newl);
> 			map.setCenter(null, null);
>
>
>
> 			};
> </script>
> </head>
>
> <body onload="init();">
> <div id="map"></div>
> </body>
> </html>
>
>
>
> _______________________________________________
> Users mailing list
> Users at openlayers.org
> http://openlayers.org/mailman/listinfo/users
>
>
> _______________________________________________
> Users mailing list
> Users at openlayers.org
> http://openlayers.org/mailman/listinfo/users




More information about the Users mailing list