Permalink
Browse files

fixed bug with new more reliable anyscale event handler

  • Loading branch information...
1 parent a164776 commit 3a17b8b7a5f1b49ca93c3195a34a3fafb7aa0ee5 @RandomEtc RandomEtc committed Feb 8, 2011
Showing with 198 additions and 172 deletions.
  1. +5 −0 CHANGELOG
  2. +156 −0 examples/anyscale/anyzoom.js
  3. +2 −142 examples/anyscale/index.html
  4. +17 −14 modestmaps.js
  5. +2 −2 modestmaps.min.js
  6. +15 −13 src/map.js
  7. +1 −1 src/start.js
View
@@ -8,6 +8,11 @@ Following the semantic versioning recommendation best we can:
minor version, and backwards incompatible API changes increment
the major version." -- http://semver.org/
+v0.13.5
+ - changed the order of initialization so that event handlers go last
+ (this is so that attributes like layerParent are in place for complex
+ event handlers like anyzoom.js... handlers can also use callbacks now)
+
2011-01-03 note:
- broke modestmap.js file into src folder, now building with Makefile
- no functionality change to modestmaps.js (just whitespace changes)
@@ -0,0 +1,156 @@
+// TODO: namespace/anonymous function
+
+var AnyZoomHandler = function(map) {
+ if (map !== undefined) {
+ this.init(map);
+ }
+ this.last = 0;
+};
+
+// https://bugs.webkit.org/show_bug.cgi?id=40441
+var bug40441 = /WebKit\/533/.test(navigator.userAgent) ? -1 : 0;
+
+AnyZoomHandler.prototype = {
+
+ init: function(map) {
+ this.map = map;
+ com.modestmaps.addEvent(map.layerParent, 'dblclick', this.getDoubleClick());
+ com.modestmaps.addEvent(map.layerParent, 'mousedown', this.getMouseDown());
+ com.modestmaps.addEvent(map.parent, 'mousewheel', this.getMouseWheel());
+ },
+
+ mouseDownHandler: null,
+
+ getMouseDown: function() {
+ if (!this.mouseDownHandler) {
+ var theHandler = this;
+ this.mouseDownHandler = function(e) {
+
+ com.modestmaps.addEvent(document, 'mouseup', theHandler.getMouseUp());
+ com.modestmaps.addEvent(document, 'mousemove', theHandler.getMouseMove());
+
+ theHandler.prevMouse = new com.modestmaps.Point(e.clientX, e.clientY);
+
+ theHandler.map.parent.style.cursor = 'move';
+
+ return com.modestmaps.cancelEvent(e);
+ };
+ }
+ return this.mouseDownHandler;
+ },
+
+ mouseMoveHandler: null,
+
+ getMouseMove: function() {
+ if (!this.mouseMoveHandler) {
+ var theHandler = this;
+ this.mouseMoveHandler = function(e) {
+
+ if (theHandler.prevMouse) {
+ theHandler.map.panBy(e.clientX - theHandler.prevMouse.x, e.clientY - theHandler.prevMouse.y);
+ theHandler.prevMouse.x = e.clientX;
+ theHandler.prevMouse.y = e.clientY;
+ }
+
+ return com.modestmaps.cancelEvent(e);
+ };
+ }
+ return this.mouseMoveHandler;
+ },
+
+ mouseUpHandler: null,
+
+ getMouseUp: function() {
+ if (!this.mouseUpHandler) {
+ var theHandler = this;
+ this.mouseUpHandler = function(e) {
+
+ com.modestmaps.removeEvent(document, 'mouseup', theHandler.getMouseUp());
+ com.modestmaps.removeEvent(document, 'mousemove', theHandler.getMouseMove());
+
+ theHandler.prevMouse = null;
+
+ theHandler.map.parent.style.cursor = '';
+
+ return com.modestmaps.cancelEvent(e);
+ };
+ }
+ return this.mouseUpHandler;
+ },
+
+ mouseWheelHandler: null,
+
+ getMouseWheel: function() {
+ if (!this.mouseWheelHandler) {
+ var theHandler = this;
+ this.mouseWheelHandler = function(e) {
+
+ var delta = 0;
+
+ if (e.wheelDelta) {
+ delta = e.wheelDelta / 120;
+ }
+ else if (e.detail) {
+ delta = -e.detail;
+ }
+
+ delta *= 0.1;
+
+ /* Detect fast & large wheel events on WebKit. */
+ if (bug40441 < 0) {
+ var now = new Date().getTime(), since = now - this.last;
+ if ((since > 9) && (Math.abs(e.wheelDelta) / since >= 50)) bug40441 = 1;
+ this.last = now;
+ }
+ if (bug40441 == 1) delta *= .03;
+
+ var point = theHandler.getMousePoint(e);
+
+ theHandler.map.zoomByAbout(delta, point);
+ //Math.min(0.5, Math.max(-0.5, delta/10.0)), point);
+
+ return com.modestmaps.cancelEvent(e);
+ };
+ }
+ return this.mouseWheelHandler;
+ },
+
+ doubleClickHandler: null,
+
+ getDoubleClick: function() {
+ if (!this.doubleClickHandler) {
+ var theHandler = this;
+ this.doubleClickHandler = function(e) {
+
+ var point = theHandler.getMousePoint(e);
+
+ // use shift-double-click to zoom out
+ theHandler.map.zoomByAbout(e.shiftKey ? -1 : 1, point);
+
+ return com.modestmaps.cancelEvent(e);
+ };
+ }
+ return this.doubleClickHandler;
+ },
+
+ // interaction helper
+
+ getMousePoint: function(e)
+ {
+ // start with just the mouse (x, y)
+ var point = new com.modestmaps.Point(e.clientX, e.clientY);
+
+ // correct for scrolled document
+ point.x += document.body.scrollLeft + document.documentElement.scrollLeft;
+ point.y += document.body.scrollTop + document.documentElement.scrollTop;
+
+ // correct for nested offsets in DOM
+ for(var node = this.map.parent; node; node = node.offsetParent) {
+ point.x -= node.offsetLeft;
+ point.y -= node.offsetTop;
+ }
+
+ return point;
+ }
+
+};
@@ -3,151 +3,11 @@
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=0;" />
<meta name="apple-mobile-web-app-status-bar-style" content="black" />
<meta name="apple-mobile-web-app-capable" content="yes" />
-<title>Modest Maps JS - Touch Tester</title>
+<title>Modest Maps JS - Any Zoom Demo</title>
<script type="text/javascript" src="../../modestmaps.js"></script>
+<script type="text/javascript" src="anyzoom.js"></script>
<script type="text/javascript">
- var AnyZoomHandler = function(map) {
- if (map !== undefined) {
- this.init(map);
- }
- };
-
- AnyZoomHandler.prototype = {
-
- init: function(map) {
- this.map = map;
- com.modestmaps.addEvent(map.parent, 'dblclick', this.getDoubleClick());
- com.modestmaps.addEvent(map.parent, 'mousedown', this.getMouseDown());
- com.modestmaps.addEvent(map.parent, 'mousewheel', this.getMouseWheel());
- },
-
- mouseDownHandler: null,
-
- getMouseDown: function() {
- if (!this.mouseDownHandler) {
- var theHandler = this;
- this.mouseDownHandler = function(e) {
-
- com.modestmaps.addEvent(document, 'mouseup', theHandler.getMouseUp());
- com.modestmaps.addEvent(document, 'mousemove', theHandler.getMouseMove());
-
- theHandler.prevMouse = new com.modestmaps.Point(e.clientX, e.clientY);
-
- theHandler.map.parent.style.cursor = 'move';
-
- return com.modestmaps.cancelEvent(e);
- };
- }
- return this.mouseDownHandler;
- },
-
- mouseMoveHandler: null,
-
- getMouseMove: function() {
- if (!this.mouseMoveHandler) {
- var theHandler = this;
- this.mouseMoveHandler = function(e) {
-
- if (theHandler.prevMouse) {
- theHandler.map.panBy(e.clientX - theHandler.prevMouse.x, e.clientY - theHandler.prevMouse.y);
- theHandler.prevMouse.x = e.clientX;
- theHandler.prevMouse.y = e.clientY;
- }
-
- return com.modestmaps.cancelEvent(e);
- };
- }
- return this.mouseMoveHandler;
- },
-
- mouseUpHandler: null,
-
- getMouseUp: function() {
- if (!this.mouseUpHandler) {
- var theHandler = this;
- this.mouseUpHandler = function(e) {
-
- com.modestmaps.removeEvent(document, 'mouseup', theHandler.getMouseUp());
- com.modestmaps.removeEvent(document, 'mousemove', theHandler.getMouseMove());
-
- theHandler.prevMouse = null;
-
- theHandler.map.parent.style.cursor = '';
-
- return com.modestmaps.cancelEvent(e);
- };
- }
- return this.mouseUpHandler;
- },
-
- mouseWheelHandler: null,
-
- getMouseWheel: function() {
- if (!this.mouseWheelHandler) {
- var theHandler = this;
- this.mouseWheelHandler = function(e) {
-
- var delta = 0;
-
- if (e.wheelDelta) {
- delta = e.wheelDelta / 60;
- }
- else if (e.detail) {
- delta = -e.detail / 2;
- }
-
- var point = theHandler.getMousePoint(e);
-
- theHandler.map.zoomByAbout(Math.min(0.5, Math.max(-0.5, delta/10.0)), point);
-
- return com.modestmaps.cancelEvent(e);
- };
- }
- return this.mouseWheelHandler;
- },
-
- doubleClickHandler: null,
-
- getDoubleClick: function() {
- if (!this.doubleClickHandler) {
- var theHandler = this;
- this.doubleClickHandler = function(e) {
-
- var point = theHandler.getMousePoint(e);
-
- // use shift-double-click to zoom out
- theHandler.map.zoomByAbout(e.shiftKey ? -1 : 1, point);
-
- return com.modestmaps.cancelEvent(e);
- };
- }
- return this.doubleClickHandler;
- },
-
- // interaction helper
-
- getMousePoint: function(e)
- {
- // start with just the mouse (x, y)
- var point = new com.modestmaps.Point(e.clientX, e.clientY);
-
- // correct for scrolled document
- point.x += document.body.scrollLeft + document.documentElement.scrollLeft;
- point.y += document.body.scrollTop + document.documentElement.scrollTop;
-
- // correct for nested offsets in DOM
- for(var node = this.map.parent; node; node = node.offsetParent) {
- point.x -= node.offsetLeft;
- point.y -= node.offsetTop;
- }
-
- return point;
- }
-
- };
-
-
var map;
function initMap() {
View
@@ -1,5 +1,5 @@
/*!
- * Modest Maps JS v0.13.4
+ * Modest Maps JS v0.13.5
* http://modestmaps.com/
*
* Copyright (c) 2010 Stamen Design, All Rights Reserved.
@@ -111,6 +111,7 @@ if (!com) {
return new MM.Point(px, py);
};
+
MM.Coordinate = function(row, column, zoom) {
this.row = row;
this.column = column;
@@ -981,19 +982,6 @@ if (!com) {
this.dimensions = dimensions;
- if (eventHandlers === undefined) {
- this.eventHandlers = [];
- this.eventHandlers.push(new MM.MouseHandler(this));
- }
- else {
- this.eventHandlers = eventHandlers;
- if (eventHandlers instanceof Array) {
- for (var i = 0; i < eventHandlers.length; i++) {
- eventHandlers[i].init(this);
- }
- }
- }
-
// TODO: is it sensible to do this (could be more than one map on a page)
/*
// add a style element so layer/tile styles can be class-based
@@ -1032,6 +1020,21 @@ if (!com) {
this.setProvider(provider);
this.callbackManager = new MM.CallbackManager(this, [ 'zoomed', 'panned', 'centered', 'extentset', 'resized', 'drawn' ]);
+
+ // set up handlers last so that all required attributes/functions are in place if needed
+ if (eventHandlers === undefined) {
+ this.eventHandlers = [];
+ this.eventHandlers.push(new MM.MouseHandler(this));
+ }
+ else {
+ this.eventHandlers = eventHandlers;
+ if (eventHandlers instanceof Array) {
+ for (var i = 0; i < eventHandlers.length; i++) {
+ eventHandlers[i].init(this);
+ }
+ }
+ }
+
};
MM.Map.prototype = {
View

Large diffs are not rendered by default.

Oops, something went wrong.
Oops, something went wrong.

0 comments on commit 3a17b8b

Please sign in to comment.