Take the 2-minute tour ×
Geographic Information Systems Stack Exchange is a question and answer site for cartographers, geographers and GIS professionals. It's 100% free, no registration required.

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);
share|improve this question
    
Why I can't using events "touchstart"? –  Andi Nugroho 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
add comment

2 Answers 2

up vote 5 down vote accepted

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.

share|improve this answer
    
Markers should now be put on the Vector layer. I think OpenLayers is slowly planning to depreciate the MarkerLayer. –  user506706 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
add comment

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.

share|improve this answer
    
RefactorFun ::: your super right –  ghulma 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 at 5:54
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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