I can't get the mousedown event to fire on a mobile device when I click on a marker. I'm using openlayers 2.11 with TouchNavigation. The mousedown event fires just fine in Chrome on my Desktop. Are there touch specific events for openlayers? If yes, where can Ifind the list. The openlayers documentation is driving me crazy.

The code I use:

  var start_point = new OpenLayers.LonLat(latlngs[0].x,latlngs[0].y);
  var start_marker = new OpenLayers.Marker(start_point,green_pin);
  start_marker.events.register('mousedown', start_marker, function(evt) { alert('Ok'); OpenLayers.Event.stop(evt); });
  • Why I can't using events "touchstart"? – Andi N. Dirgantara Dec 2 '13 at 3:18
  • If you have a new question, please ask it by clicking the Ask Question button. Include a link to this question if it helps provide context. – Devdatta Tengshe Dec 2 '13 at 3:58

Correct, the mousedown events do not occur on mobile with Touch events. Instead, you should use a Vector layer -- the Vector layers appropriately handle 'taps' and interpret them as select events.

  • Markers should now be put on the Vector layer. I think OpenLayers is slowly planning to depreciate the MarkerLayer. – fnllc Mar 8 '12 at 21:04
  • So is it impossible to get a click event on the map itself? I'm handling searching on the server side, so I need a generic click event also on the iPad, that's why. – Reinout van Rees Apr 23 '12 at 8:26

I had basically the same question as user506706. I just couldn't believe that the Vector layer was the only layer to handle touches...so if all else fails...read the code. In OpenLayers-2.11/OpenLayers/lib/Events.js I found:

    "mouseover", "mouseout",
    "mousedown", "mouseup", "mousemove",
    "click", "dblclick", "rightclick", "dblrightclick",
    "resize", "focus", "blur",
    "touchstart", "touchmove", "touchend"

So in my existing code that currently uses a Marker layer, I register a handler for the touchstart event...

new_marker.events.register("touchstart", new_marker, function(e) {
                        console.warn("touch start");                                       

I tested on my iPod Touch/Safari Browser and voila...touching the marker got the touchstart event. Upon further debugging to the console, I believe it also gets the mouseover and mouseout events, but not the mousedown mentioned. Hope this helps.

  • RefactorFun ::: your super right – jason gruns Apr 19 '12 at 13:48
  • Awesome man.. Saved my day.. I was literally pushed to the wall... Thanks for sharing this.. – Roy M J Jan 6 '14 at 5:54

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.