OpenLayers Mobile – Do Mousedown Events Fire with Touch Events?

eventsmobileopenlayers-2

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); });
  StartFinishLayer.addMarker(start_marker);

Best Answer

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:

BROWSER_EVENTS: [
    "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.