stamen / modestmaps-js

Modest Maps javascript port
http://modestmaps.com
566 stars 152 forks source link

add handlers for both click & doubleclick on map #16

Closed tmcw closed 13 years ago

tmcw commented 13 years ago

I'm writing some functionality that requires clicks on the map (as well as double-clicks for navigation, of course). Currently I've hacked together something similar to OpenLayers in this respect, but it might be in the scope of Modest Maps itself to deal with the problem of browsers registering dblclick and click 'unusually' in different browsers, and for click events triggering before dblclick events.

RandomEtc commented 13 years ago

It was my expectation when writing the first version of Modest Maps JS that people would have their own opinions on interaction (and indeed they do). (Over in Polymaps land there's a debate about whether the mousewheel should pan or zoom!). Even the default mouse handler is optional, and there are examples for smooth zooming and touch events already. I imagine a click/double-click handler could work the same way. I'd like to see this kind of functionality implemented as an example first and then moved to "core" functionality later.

Cross-browser click vs double-click (and tap vs double-tap) is tricky. I note you're using jQuery there, I'm surprised it doesn't handle it already but the docs even suggest that you don't use both single click and double click on the same element! http://api.jquery.com/dblclick/ (bit of a cop-out, no?) The comments offer this solution, which counts single clicks and chooses one of two callbacks: https://gist.github.com/399624 and the comments on that offer a double-click fix for IE which already (sometimes) suppresses click events if there's a fast double click (I think).

Modest Maps JS already includes some rough and ready DOM event handlers (MM.addEvent etc) to smooth things out for cross browser events (tidying up window.event, mousewheel, canceling events, etc). It seems useful to expose this functionality in addCallback for DOM events, or perhaps to promote certain DOM events into map callbacks (click, drag, wheel, etc.). I filed issue #10 for another similar request... there's no formal roadmap or milestones in play though, so it might be some time before it gets added.

(As an aside I don't know anyone using using Modest Maps JS and not using jQuery. I imagine the library could be cleaned up and compacted quite a bit if we created a jQuery fork of it. Food for thought?)

RandomEtc commented 13 years ago

Perhaps this would be a more useful contribution to a mini library like https://github.com/fat/bean (and perhaps Modest Maps could liberally borrow or utilise http://dustindiaz.com/ender ?)

tmcw commented 13 years ago

Yep, I was going to file an issue about possibly moving some things into jQuery, but decided to throttle my flood of this issue tracker :).

I think it'd be awesome to switch some of the essentials over to jQuery. It'd also be interesting to think about using a micro-library, since it seems like starting from scratch is giving some projects the ability to do things smaller and cleaner, but that'd be less of a win for people who, as you note, are all using jQuery. A cautionary example in OpenLayers which contains bits of Rico...

And it's surprising that even jQuery doesn't have a good implementation of click/doubleclick built in - they don't seem opposed to creating new pseudoevents and stuff like that. I can ask about that over on jQuery's site?

RandomEtc commented 13 years ago

The usual reason for missing jQuery functionality is that it can't be done perfectly consistently on all browsers. It's a worry! But for the case of click/double-click it's a bit weird. Basically you need to have a ~250ms delay on all click events where there's also a double-click listener in place. I can imagine that's a controversial thing - it's just as easy to delay the click response and cancel it on double click, and then the behaviour is controlled at the application level not the library level.

I'm pretty sure Shawn at Stamen would also be interested in a modest maps jquery fork, I remember he asked after it a while ago. And it would probably get more contributions because people are more familiar and hack-happy with jquery.

tmcw commented 13 years ago

Closing; this is out of scope for Modest Maps IMH(current)O.