Note that there are some explanatory texts on larger screens.

plurals
  1. POOpenLayers click event on iPhone with PhoneGap
    primarykey
    data
    text
    <p>I have a problem with the click event on an OpenLayers Map on iPhone 4 using PhoneGap. It appears that the Position received by my setMarker(evt) function is dependent from the scroll position. After taking a closer look at the values for x and y I found out that y can even be negative. The same code is working on Android, with setMarker receiving plausible values for both x and y.</p> <p>Here is a short example where this problem occurs:</p> <pre><code>&lt;!DOCTYPE html&gt; &lt;html&gt; &lt;head&gt; &lt;title&gt;&lt;/title&gt; &lt;meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no;" /&gt; &lt;meta charset="utf-8"&gt; &lt;style&gt; html, body { height:99%; width:99%; } &lt;/style&gt; &lt;script type="text/javascript" charset="utf-8" src="phonegap-1.4.1.js"&gt;&lt;/script&gt; &lt;script type="text/javascript" charset="utf-8" src="OpenLayers.js"&gt;&lt;/script&gt; &lt;script type="text/javascript"&gt; var map, layer, markers; function setMarker(e){ markers.clearMarkers(); var markerpos = map.getLonLatFromViewPortPx(e.xy); var size = new window.OpenLayers.Size(21,25); var offset = new window.OpenLayers.Pixel(-(size.w/2), -size.h); var icon = new window.OpenLayers.Icon('http://www.openlayers.org/dev/img/marker.png',size,offset); var marker = new window.OpenLayers.Marker(markerpos,icon); markers.addMarker(marker); } function onDeviceReady() { map = new window.OpenLayers.Map("map", { controls: [new window.OpenLayers.Control.Navigation()]}); layer = new window.OpenLayers.Layer.OSM("Simple OSM Map"); map.addLayer(layer); map.setCenter( new window.OpenLayers.LonLat(10,50).transform( new window.OpenLayers.Projection("EPSG:4326"), // From WGS 84 map.getProjectionObject() // to Spherical Mercator ), 18 //Zoom ); var touchNav = new window.OpenLayers.Control.TouchNavigation({ defaultClickOptions:{ pixelTolerance: 10 } }); // A click will set the marker: window.OpenLayers.Util.extend(touchNav, { defaultClick: function(evt) { alert("you clicked " + evt.xy); setMarker(evt); } }); map.addControl(touchNav); touchNav.activate(); markers = new window.OpenLayers.Layer.Markers("Markers"); map.addLayer(markers); console.log("map generated"); } &lt;/script&gt; &lt;/head&gt; &lt;body onload="document.addEventListener('deviceready', onDeviceReady, false);"&gt; &lt;br/&gt;&lt;br/&gt;&lt;br/&gt;&lt;br/&gt;&lt;br/&gt;&lt;br/&gt;&lt;br/&gt;&lt;br/&gt;&lt;br/&gt;&lt;br/&gt;&lt;br/&gt;&lt;br/&gt;&lt;br/&gt;&lt;br/&gt;&lt;br/&gt;&lt;br/&gt;&lt;br/&gt;&lt;br/&gt; &lt;div id="map" style="width:100%;height:100%"&gt;&lt;/div&gt; &lt;br/&gt;&lt;br/&gt;&lt;br/&gt;&lt;br/&gt;&lt;br/&gt;&lt;br/&gt;&lt;br/&gt;&lt;br/&gt;&lt;br/&gt;&lt;br/&gt;&lt;br/&gt;&lt;br/&gt;&lt;br/&gt;&lt;br/&gt;&lt;br/&gt;&lt;br/&gt;&lt;br/&gt;&lt;br/&gt; &lt;/body&gt; &lt;/html&gt; </code></pre> <p>A similar problem is here, but as I am already using OpenLayers 2.11 his solution does not help me: <a href="https://stackoverflow.com/questions/8667464/problems-with-zooming-and-mouse-events-in-openlayers">Problems with zooming and mouse events in Openlayers</a></p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload