Skip to content

Commit 770da2a

Browse files
committed
Merge branch 'master' of https://github.com/mapbox/wax
Conflicts: control/leaf/interaction.js
2 parents 984db19 + aeb5b11 commit 770da2a

File tree

14 files changed

+362
-134
lines changed

14 files changed

+362
-134
lines changed

control/g/interaction.js

Lines changed: 24 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -16,27 +16,36 @@ wax.g.interaction = function(map, tilejson, options) {
1616
// cache of grid information and provide friendly utility methods
1717
// that return `GridTile` objects instead of raw data.
1818
var interaction = {
19-
modifyingEvents: ['dragstart', 'dragend', 'drag', 'zoom_changed',
20-
'resize', 'center_changed', 'bounds_changed'],
21-
2219
waxGM: new wax.GridManager(tilejson),
2320

2421
// This requires wax.Tooltip or similar
2522
callbacks: options.callbacks || new wax.tooltip(),
26-
2723
clickAction: options.clickAction || 'full',
24+
eventHandlers:{},
2825

2926
// Attach listeners to the map
3027
add: function() {
31-
for (var i = 0; i < this.modifyingEvents.length; i++) {
32-
google.maps.event.addListener(
33-
map,
34-
this.modifyingEvents[i],
35-
wax.util.bind(this.clearTileGrid, this)
36-
);
37-
}
38-
google.maps.event.addListener(map, 'mousemove', this.onMove());
39-
google.maps.event.addListener(map, 'click', this.click());
28+
this.eventHandlers.tileloaded = google.maps.event.addListener(map, 'tileloaded',
29+
wax.util.bind(this.clearTileGrid, this));
30+
31+
this.eventHandlers.idle = google.maps.event.addListener(map, 'idle',
32+
wax.util.bind(this.clearTileGrid, this));
33+
34+
this.eventHandlers.mousemove = google.maps.event.addListener(map, 'mousemove',
35+
this.onMove());
36+
37+
this.eventHandlers.click = google.maps.event.addListener(map, 'click',
38+
this.click());
39+
40+
return this;
41+
},
42+
43+
// Remove interaction events from the map.
44+
remove: function() {
45+
google.maps.event.removeListener(this.eventHandlers.tileloaded);
46+
google.maps.event.removeListener(this.eventHandlers.idle);
47+
google.maps.event.removeListener(this.eventHandlers.mousemove);
48+
google.maps.event.removeListener(this.eventHandlers.click);
4049
return this;
4150
},
4251

@@ -80,9 +89,9 @@ wax.g.interaction = function(map, tilejson, options) {
8089
var grid = this.getTileGrid();
8190
for (var i = 0; i < grid.length; i++) {
8291
if ((grid[i][0] < evt.pixel.y) &&
83-
((grid[i][0] + 256) > evt.pixel.y) &&
92+
((grid[i][0] + 256) > evt.pixel.y) &&
8493
(grid[i][1] < evt.pixel.x) &&
85-
((grid[i][1] + 256) > evt.pixel.x)) {
94+
((grid[i][1] + 256) > evt.pixel.x)) {
8695
tile = grid[i][2];
8796
break;
8897
}

control/lib/gridinstance.js

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -21,20 +21,30 @@ wax.GridInstance = function(grid_tile, formatter, options) {
2121
return key;
2222
}
2323

24-
// Lower-level than tileFeature - has nothing to do
25-
// with the DOM. Takes a px offset from 0, 0 of a grid.
26-
instance.gridFeature = function(x, y) {
24+
instance.grid_tile = function() {
25+
return grid_tile;
26+
};
27+
28+
instance.getKey = function(x, y) {
2729
if (!(grid_tile && grid_tile.grid)) return;
2830
if ((y < 0) || (x < 0)) return;
29-
if ((Math.floor(y) > tileSize) ||
30-
(Math.floor(x) > tileSize)) return;
31+
if ((Math.floor(y) >= tileSize) ||
32+
(Math.floor(x) >= tileSize)) return;
3133
// Find the key in the grid. The above calls should ensure that
3234
// the grid's array is large enough to make this work.
33-
var key = resolveCode(grid_tile.grid[
35+
return resolveCode(grid_tile.grid[
3436
Math.floor((y) / resolution)
3537
].charCodeAt(
3638
Math.floor((x) / resolution)
3739
));
40+
};
41+
42+
// Lower-level than tileFeature - has nothing to do
43+
// with the DOM. Takes a px offset from 0, 0 of a grid.
44+
instance.gridFeature = function(x, y) {
45+
// Find the key in the grid. The above calls should ensure that
46+
// the grid's array is large enough to make this work.
47+
var key = this.getKey(x, y);
3848

3949
if (grid_tile.keys[key] && grid_tile.data[grid_tile.keys[key]]) {
4050
return grid_tile.data[grid_tile.keys[key]];

control/lib/request.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ wax.request = {
2525
var that = this;
2626
this.locks[url] = true;
2727
reqwest({
28-
url: url + '?callback=grid',
28+
url: wax.util.addUrlData(url, 'callback=grid'),
2929
type: 'jsonp',
3030
jsonpCallback: 'callback',
3131
success: function(data) {

control/lib/tilejson.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ if (!wax) var wax = {};
33
// A wrapper for reqwest jsonp to easily load TileJSON from a URL.
44
wax.tilejson = function(url, callback) {
55
reqwest({
6-
url: url + '?callback=grid',
6+
url: wax.util.addUrlData(url, 'callback=grid'),
77
type: 'jsonp',
88
jsonpCallback: 'callback',
99
success: callback,

control/lib/util.js

Lines changed: 42 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ wax.util = {
6868
parseInt(htmlComputed.marginTop, 10) &&
6969
!isNaN(parseInt(htmlComputed.marginTop, 10))) {
7070
top += parseInt(htmlComputed.marginTop, 10);
71-
left += parseInt(htmlComputed.marginLeft, 10);
71+
left += parseInt(htmlComputed.marginLeft, 10);
7272
}
7373

7474
return {
@@ -89,14 +89,14 @@ wax.util = {
8989
// Returns a version of a function that always has the second parameter,
9090
// `obj`, as `this`.
9191
bind: function(func, obj) {
92-
var args = Array.prototype.slice.call(arguments, 2);
93-
return function() {
94-
return func.apply(obj, args.concat(Array.prototype.slice.call(arguments)));
95-
};
92+
var args = Array.prototype.slice.call(arguments, 2);
93+
return function() {
94+
return func.apply(obj, args.concat(Array.prototype.slice.call(arguments)));
95+
};
9696
},
9797
// From underscore
9898
isString: function(obj) {
99-
return !!(obj === '' || (obj && obj.charCodeAt && obj.substr));
99+
return !!(obj === '' || (obj && obj.charCodeAt && obj.substr));
100100
},
101101
// IE doesn't have indexOf
102102
indexOf: function(array, item) {
@@ -113,10 +113,10 @@ wax.util = {
113113
},
114114
// From underscore: reimplement the ECMA5 `Object.keys()` method
115115
keys: Object.keys || function(obj) {
116-
var hasOwnProperty = Object.prototype.hasOwnProperty;
116+
var ho = Object.prototype.hasOwnProperty;
117117
if (obj !== Object(obj)) throw new TypeError('Invalid object');
118118
var keys = [];
119-
for (var key in obj) if (hasOwnProperty.call(obj, key)) keys[keys.length] = key;
119+
for (var key in obj) if (ho.call(obj, key)) keys[keys.length] = key;
120120
return keys;
121121
},
122122
// From quirksmode: normalize the offset of an event from the top-left
@@ -139,9 +139,9 @@ wax.util = {
139139
var leftMargin = parseInt(htmlComputed.marginLeft, 10) || 0;
140140
return {
141141
x: e.clientX + (doc && doc.scrollLeft || body && body.scrollLeft || 0) -
142-
(doc && doc.clientLeft || body && body.clientLeft || 0) + leftMargin,
142+
(doc && doc.clientLeft || body && body.clientLeft || 0) + leftMargin,
143143
y: e.clientY + (doc && doc.scrollTop || body && body.scrollTop || 0) -
144-
(doc && doc.clientTop || body && body.clientTop || 0) + topMargin
144+
(doc && doc.clientTop || body && body.clientTop || 0) + topMargin
145145
};
146146
} else if (e.touches && e.touches.length === 1) {
147147
// Touch browsers
@@ -150,5 +150,37 @@ wax.util = {
150150
y: e.touches[0].pageY
151151
};
152152
}
153+
},
154+
// parseUri 1.2.2
155+
// Steven Levithan <stevenlevithan.com>
156+
parseUri: function(str) {
157+
var o = {
158+
strictMode: false,
159+
key: ["source","protocol","authority","userInfo","user","password","host","port","relative","path","directory","file","query","anchor"],
160+
q: {
161+
name: "queryKey",
162+
parser: /(?:^|&)([^&=]*)=?([^&]*)/g
163+
},
164+
parser: {
165+
strict: /^(?:([^:\/?#]+):)?(?:\/\/((?:(([^:@]*)(?::([^:@]*))?)?@)?([^:\/?#]*)(?::(\d*))?))?((((?:[^?#\/]*\/)*)([^?#]*))(?:\?([^#]*))?(?:#(.*))?)/,
166+
loose: /^(?:(?![^:@]+:[^:@\/]*@)([^:\/?#.]+):)?(?:\/\/)?((?:(([^:@]*)(?::([^:@]*))?)?@)?([^:\/?#]*)(?::(\d*))?)(((\/(?:[^?#](?![^?#\/]*\.[^?#\/.]+(?:[?#]|$)))*\/?)?([^?#\/]*))(?:\?([^#]*))?(?:#(.*))?)/
167+
}
168+
},
169+
m = o.parser[o.strictMode ? "strict" : "loose"].exec(str),
170+
uri = {},
171+
i = 14;
172+
173+
while (i--) uri[o.key[i]] = m[i] || "";
174+
175+
uri[o.q.name] = {};
176+
uri[o.key[12]].replace(o.q.parser, function ($0, $1, $2) {
177+
if ($1) uri[o.q.name][$1] = $2;
178+
});
179+
return uri;
180+
},
181+
// appends callback onto urls regardless of existing query params
182+
addUrlData: function(url, data) {
183+
url += (this.parseUri(url).query) ? '&' : '?';
184+
return url += data;
153185
}
154186
};

0 commit comments

Comments
 (0)