Skip to content

Commit

Permalink
Clear locations on map idle, with testing code in index.html. Not ful…
Browse files Browse the repository at this point in the history
…ly formed
  • Loading branch information
tmcw committed Jul 31, 2012
1 parent 40867ce commit 18b332c
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 18 deletions.
1 change: 1 addition & 0 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
<div class='right'>
<p>Easey is a map animation library. It works with <a href='http://modestmaps.com/'>Modest Maps</a> and provides
advanced <a href='http://www.robertpenner.com/easing/'>easing</a> as well as inertial panning and zooming.</p>
<pre id='console'></pre>
<pre class='live'>
easey().map(map)
.to(map.locationCoordinate({ lat: 38, lon: -80 })
Expand Down
46 changes: 28 additions & 18 deletions src/easey.handlers.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,21 @@
p0 = new MM.Point(0, 0),
p1 = new MM.Point(0, 0);

function focusMap(e) {
map.parent.focus();
}

function clearLocations() {
for (var loc in locations) {
if (locations.hasOwnProperty(loc)) {
delete locations[loc];
}
}
}

function animate(t) {
var dt = Math.max(0.001, (t - prevT) / 1000.0);
document.getElementById('console').innerHTML = Object.keys(locations).length;
if (nowPoint && oldPoint &&
(lastMove > (+new Date() - 50))) {
dir.x = nowPoint.x - oldPoint.x;
Expand All @@ -43,19 +56,14 @@
}
if (speed.x || speed.y) {
map.panBy(speed.x, speed.y);
} else if (!wasPinching) {
clearLocations();
}
prevT = t;
// tick every frame for time-based anim accuracy
MM.getFrame(animate);
}

// Test whether touches are from the same source -
// whether this is the same touchmove event.
function sameTouch (event, touch) {
return (event && event.touch) &&
(touch.identifier == event.touch.identifier);
}

function updateTouches (e) {
for (var i = 0; i < e.touches.length; i += 1) {
var t = e.touches[i];
Expand Down Expand Up @@ -99,8 +107,8 @@
if (taps.length &&
(tap.time - taps[0].time) < maxDoubleTapDelay) {
onDoubleTap(tap);
taps = [];
return;
taps = [];
return;
}
taps = [tap];
}
Expand All @@ -113,6 +121,7 @@
.to(map.pointCoordinate(tap).zoomTo(map.getZoom() + 1))
.path('about').run(200, function() {
map.dispatchCallback('zoomed');
clearLocations();
});
}

Expand Down Expand Up @@ -149,17 +158,16 @@
var center = MM.Point.interpolate(p0, p1, 0.5);

map.zoomByAbout(
Math.log(e.scale) / Math.LN2 -
Math.log(l0.scale) / Math.LN2,
Math.log(e.scale) / Math.LN2 - Math.log(l0.scale) / Math.LN2,
center);

// pan from the previous center of these touches
prevX = l0.x + (l1.x - l0.x) * 0.5;
prevY = l0.y + (l1.y - l0.y) * 0.5;
map.panBy(center.x - prevX,
center.y - prevY);
wasPinching = true;
lastPinchCenter = center;
// pan from the previous center of these touches
prevX = l0.x + (l1.x - l0.x) * 0.5;
prevY = l0.y + (l1.y - l0.y) * 0.5;
map.panBy(center.x - prevX,
center.y - prevY);
wasPinching = true;
lastPinchCenter = center;
}

// When a pinch event ends, round the zoom of the map.
Expand All @@ -169,12 +177,14 @@
var z = map.getZoom(), // current zoom
tz = Math.round(z); // target zoom
map.zoomByAbout(tz - z, p);
clearLocations();
}
wasPinching = false;
}

function touchEndMachine(e) {
var now = new Date().getTime();

// round zoom if we're done pinching
if (e.touches.length === 0 && wasPinching) {
onPinched(lastPinchCenter);
Expand Down

0 comments on commit 18b332c

Please sign in to comment.