[OpenLayers-Users] getLonLatFromPixel in IE

Luís de Sousa luis.a.de.sousa at gmail.com
Tue May 25 10:50:58 EDT 2010


 2010/5/25 Frank Broniewski <brfr at metrico.lu>
Hi,

well obviously you can't pass any arguments to an event function (in IE).
The function only has access to window.event. You can do

function coords(event) {
               var xy = event.object.
>
> getLonLatFromViewPortPx(event.xy);
>                var x = xy.lon;
>                var y = xy.lat;
>                ...
> }



Thank you Frank, that did it, works both with Firefox and IE.

Note though that the listener has to be registered the way you indicated,
not how I had tried initially. Full code below.

Thanks,

Luís

<html>
  <head>
    <title>OpenLayers Demo</title>
    <style type="text/css">
      html, body, #basicMap {
          width: 400px;
          height: 300px;
          margin: 0;
      }
    </style>
    <!--<script src="http://www.openlayers.org/api/OpenLayers.js
"></script>-->
    <script src="../openlayers/OpenLayers.js"></script>
    <script src='
http://maps.google.com/maps?file=api&amp;v=2&amp;key=ABQIAAAAjpkAC9ePGem0lIq5XcMiuhR_wWLPFku8Ix9i2SXYRVK3e45q1BQUd_beF8dtzKET_EteAjPdGDwqpQ
'></script>
    <script>
      function init() {
        map = new OpenLayers.Map("basicMap");
        var gphy = new OpenLayers.Layer.Google(
                "Google Physical",
                {type: G_PHYSICAL_MAP}
            );
        map.addLayer(gphy);
        map.zoomToMaxExtent();
        map.events.register("click", map, showCoords);
      }

      function showCoords(e)
      {
        var xy = e.object.getLonLatFromViewPortPx(e.xy);
        window.alert(xy.lon + " " + xy.lat);
      }
    </script>
  </head>
  <body onload="init();">
    <div id="basicMap"></div>
  </body>
</html>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.osgeo.org/pipermail/openlayers-users/attachments/20100525/f15701da/attachment.html


More information about the Users mailing list