[OpenLayers-Users] Projection problem?

Joao Duarte joao.c.duarte at co.sapo.pt
Tue Jan 20 04:45:18 EST 2009


Hi Fabian,

On your code, you've created the map with the projection set to EPSG:900913,
so is normal that you get the coordinates in that same projection.

You have two options: Or you change the projection to EPSG:900913 or after
you get some coordinates, you must convert them to EPSG:32632.

I leave you with an example  of how doing the last option:

var lonlat = map.getLonLatFromPixel(e.xy).transform(new
OpenLayers.Projection("EPSG:900913"), new
OpenLayers.Projection("EPSG:32632"));

I see that you're already performing the transformation, but the source and
destination projections are the same (EPSG:900913). Try the example I gave
you.

Hope it helps,
Regards,
João Duarte

-----Original Message-----
From: users-bounces at openlayers.org [mailto:users-bounces at openlayers.org] On
Behalf Of Fabian Patzke
Sent: terça-feira, 20 de Janeiro de 2009 08:54
To: users at openlayers.org
Subject: [OpenLayers-Users] Projection problem?

Hi there,
at the moment I am working on a university project. I am building a map
and need to get the coordinates from my map to use them in a PHP script.
There is no problem with getting them but they are in some way wrong.
What I want is to get the coordinates in EPSG:32632 just like they are
displayed in the lower left corner of the map.
For example:
I need: lat=5712116.63994 lon=565610.79249
but I get:  lat=6720302.918434498 lon=1107203.4921313925
(they are not for exactly the same position)
Has anyone an idea where my problem is?

Thanks a lot in advance,
greetings Fabian

PS: my map html file:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
    <title>Rauminformationssystem Georg-August-Universität Göttingen</title>
    <link rel="stylesheet" href="style.css" type="text/css" />

    <!-- bring in the OpenLayers javascript library -->
    <script src="http://www.openlayers.org/api/OpenLayers.js"></script>
    <!-- bring in the OpenStreetMap OpenLayers layers -->
    <script
src="http://www.openstreetmap.org/openlayers/OpenStreetMap.js"></script>

    <!-- bring in the proj4js library -->
    <script type="text/javascript"
src="proj4js/lib/proj4js-combined.js"></script>
    <script type="text/javascript"
src="proj4js/lib/defs/EPSG32632.js"></script>
    <script type="text/javascript"
src="proj4js/lib/defs/EPSG900913.js"></script>

    <!-- bring in the Prototype javascript library -->
    <script src="prototype.js" type="text/javascript"></script>

    <script type="text/javascript">
	
	var map;
	OpenLayers.Lang.setCode('de');
	
	// Initialise the 'map' object
	function initmap() {
	    map = new OpenLayers.Map ("map", {
		controls:[
		    new OpenLayers.Control.Navigation(),
		    new OpenLayers.Control.PanZoomBar(),
		    new OpenLayers.Control.Permalink(),
		    new OpenLayers.Control.LayerSwitcher(),
		    new OpenLayers.Control.MousePosition(),
		    new OpenLayers.Control.Attribution(),
		    new OpenLayers.Control.ScaleLine()
		],
		maxExtent: new
OpenLayers.Bounds(-20037508.34,-20037508.34,20037508.34,20037508.34),
		maxResolution: 156543.0399,
		numZoomLevels: 18,
    		units: 'm',
		projection: new OpenLayers.Projection("EPSG:900913"),
		displayProjection: new OpenLayers.Projection("EPSG:32632")
	    } );
	
	    // Binding OSM Layers
	    var layer_mapnik = new OpenLayers.Layer.OSM.Mapnik("Mapnik", new
OpenLayers.Projection("EPSG:900913"));
	    map.addLayer(layer_mapnik);
	    /*var layer_tah = new
OpenLayers.Layer.OSM.Osmarender("Osmarender");
	    map.addLayer(layer_tah);*/
	
	    // Binding WMS Layers
	    var wms = new OpenLayers.Layer.WMS("Gebäude",
"http://localhost:8080/geoserver/wms?service=wms&transparent=true",
	        {layers: 'topp:gebaeude', format: 'image/png'},
{isBaseLayer:
false, visibility: true});
	    var wms_raum = new OpenLayers.Layer.WMS("Räume",
"http://localhost:8080/geoserver/wms?service=wms&transparent=true",
	        {layers: 'topp:g2410_e1pos', format: 'image/png'},
{isBaseLayer: false, visibility: true});
	    map.addLayers([wms, wms_raum]);
	
	    // Get Info by click
	    map.events.register('click', map, function (e) {
		document.getElementById('nodeList').innerHTML = "Lade...";
		var lonlat = map.getLonLatFromPixel(e.xy).transform(
				    new
OpenLayers.Projection("EPSG:900913"), new
OpenLayers.Projection("EPSG:900913")
				);
		//alert("You clicked near " + lonlat.lat + " N, " +
lonlat.lon + " E");
		x = lonlat.lon;
		y = lonlat.lat;
		params = "x=" + x + "&y=" +y;
		var isin = new Ajax.Request (
		    "../postgis/coord_isin_web.php",
		    {
			method: 'get',
			parameters: params,
			onComplete: setHTML
		    }
		);
	    });
	    function setHTML( response ) {
		document.getElementById('nodeList').innerHTML =
response.responseText;
	    }
	}
    </script>
    <meta http-equiv="content-type" content="text/html; charset=UTF-8"/>
</head>

<!-- body.onload is called once the page is loaded (call the 'initmap'
function) -->
<body onload="initmap();">
    <h1 id="title">Rauminformationssystem Uni Göttingen</h1>
    <!-- Permalink not in map for better usabillity -->
    <!-- <a id="permalink" href="">Permalink</a><br /> -->
    <div class="info">
        <h2>Infos</h2>
        <p style="font-size:.8em;">Für Info in die Karte klicken</p>
	<div id="nodeList"></div>
    </div>
    <div id="map" class="map"></div>
</body>
</html>
_______________________________________________
Users mailing list
Users at openlayers.org
http://openlayers.org/mailman/listinfo/users




More information about the Users mailing list