binding to "touchstart" events on map?
See original GitHub issueI try to make this work on iOS / Safari:
var map = L.map('map').setView([51.505, -0.09], 13);
map.on('touchstart', function() {
// does not get here when touching the map
alert('touchstart')
})
But couldn’t figure out how. It’s not listed in the API reference but I wonder if there is any way to support this event?
Or maybe there is even a better way to achieve the following: I want to add a marker to a map, by touch and holding for a second. It was easy to set this up for mouse events, but I can’t find a way to make the same for touch events.
Any idea?
Issue Analytics
- State:
- Created 11 years ago
- Comments:7 (3 by maintainers)
Top Results From Across the Web
How to bind 'touchstart' and 'click' events but not respond to ...
First one has to make ie. the body element track touch events: $(document.body).touchOrMouse('init');.
Read more >Map click events to touch events in jQuery - Coderwall
To map click events to "touch events", I put together this based on the ... /how-to-bind-touchstart-and-click-events-but-not-respond-to-both.
Read more >touchstart Event - W3Schools
The touchstart event occurs when the user touches an element. Note: The touchstart event will only work on devices with a touch screen....
Read more >How to bind 'touchstart' and 'click' events but not respond to both
The touchstart event occurs when the user touches an element. But a click event is fired when the user clicks an element.
Read more >support for on('touchstart') for map.on events? - Google Groups
So the first part of the code saves the lat/long of the last mousedown event, and then hammertime uses that to detect a...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
I found a workaround on the mailing list: https://groups.google.com/forum/?fromgroups=#!topic/leaflet-js/M-6fIg7K1CU
Here it is, slightly adjusted, so it adds support for both, touchstard & touchend:
But maybe there is a more elegant solution?
Expanding on the post above… for touch events the
touch.clientX
andtouch.clientY
may not be accurate if the map is not full screen. When I tried the above code the coordinates were off by a bit. I took a look at the way Leaflet figures out the coordinates from event data inL.DomEvent. getMousePosition()
and replicated the logic with touch events.Instead of doing
I did