Get your own customer support community
 

zoomTo and PanTo

I wrote a couple of functions for a recent project and thought I'd share them here. They seem like they'd be likely to pop up in most map-type projects.

Both functions are added to the AS2 version of the com.modestmaps.Map class.

The first is zoomTo:

public function zoomTo (zoomTarget:Number):Void
{
var levelDelta:Number = zoomTarget - grid.zoomLevel;
if (levelDelta == 0) { return; }
for(var i = 1; i <= zoomFrames; i += 1)
__animSteps.push({type: 'zoom', amount: ((1/zoomFrames) * levelDelta), redraw: true});

if(!__animTask) {
__startingZoom = grid.zoomLevel;
__currentZoom = grid.zoomLevel;

onStartZoom();
animationProcess();
}
}

Just pass it the zoom level you want to zoom to, and it'll zoom there. I set the redraw to true on each step because I was having serious redraw problems if I just redrew on the last step, as both zoomIn() and zoomOut() do.

Second is PanTo:

public function panTo (targetLoc:Location):Void {
var centerPoint:Point = locationPoint(__mapProvider.coordinateLocation(grid.centerCoordinate()), grid);
var targetPoint:Point = locationPoint(targetLoc, grid);
var distance:Point = new Point(Math.round((targetPoint.x - centerPoint.x) / panFrames), Math.round((targetPoint.y - centerPoint.y) / panFrames));
panMap(distance);
}

Give it a location object, and it will pan to center that location on the map. Pretty straight-forward. Let me know if anyone finds this useful.

tma
 
happy I’m happy
Inappropriate?
2 people like this idea

User_default_medium