Ticket #2990 (closed bug: duplicate)

Opened 2 years ago

Last modified 2 years ago

MousePosition Control returns 2,2 at upper left corner of the map

Reported by: sanojr Owned by:
Priority: minor Milestone: 2.11 Release
Component: general Version: 2.10
Keywords: Cc:
State:

Description

Hi,

I am trying to use the OpenStreetMap and was trying to locate the pixel location on the map using lat and lon but was returning me incorrect values. Later i found that when i place the mouse at upper left corner of the map i am receiving 2,2 instead of 0,0.

As mentioned in the examples, this could be a bug. If so, please do fix and if their is a mistake in the way i have used the functionality then please let me know on how it should be corrected.

Below is the simple html code that i am using

<html>
  <head>
    <title>OpenLayers Demo</title>
    <style type="text/css">
      html, body, #map {
          width: 500px;
          height: 500px;
          margin: 0;
      }
    </style>
    <script src="OpenLayers.js"></script>
    <script>
    var map;  
      function init() {
        map = new OpenLayers.Map('map');
        var mapnik = new OpenLayers.Layer.OSM();
        map.addLayer(mapnik);
        map.setCenter(new OpenLayers.LonLat(13.41,52.52) // Center of the map
          .transform(
            new OpenLayers.Projection("EPSG:4326"), // transform from WGS 1984
            new OpenLayers.Projection("EPSG:900913") // to Spherical Mercator Projection
          ), 15 // Zoom level
        );

		map.events.register("mousemove", map, function(e) { 
		var position = this.events.getMousePosition(e);
		OpenLayers.Util.getElement("coords").innerHTML = position;
		});
      }
    </script>
  </head>
  <body onload="init();">
        <table>
        <tr>
            <td>
                <div id="map" class="smallmap"></div>
                   <div id="basicMap"></div>
            </td>
            <td valign="top">
                <div id="coords"></div>
            </td>
        </tr>
    </table>
  </body>
  <style type="text/css">
DIV.olControlMousePosition {
	BOTTOM: 0em; DISPLAY: block; FONT-FAMILY: Arial; FONT-SIZE: smaller; RIGHT: 3px
}
</style>
</html>

let me know if you need more information.

Regards, Sanoj

Change History

Changed 2 years ago by ahocevar

  • status changed from new to closed
  • resolution set to duplicate

Duplicate of #2247, which is fixed in trunk.

Note: See TracTickets for help on using tickets.