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
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
2
people like this idea
I like this idea!
Tell me when this idea gets some attention.
The more people who like this idea, the more it gets noticed.
The more people who like this idea, the more it gets noticed.
The best point from the company
-
This is in the latest version in subversion, for AS3. Sorry for the delay!
http://modestmaps.mapstraction.com/tr...
I’m happy
The company thinks
this is one of the best points
-
Inappropriate?This is good stuff. I had a hell of a time with the re-draw issues as well when writing a zoomOn function that would both pan and zoom to a particular location on the map. I ended up scrapping an animated effect for that because it was causing so many problems for me. If reDraw is set to true, it's going to attempt to load tiles for intermediate zoom levels between the start and destination zoom, right?
-
Inappropriate?Hi!
I've used Your PanTo() in my Navigation window. Works good, but when I PanTo(somewhere) my markers are moved to some strage location, when the PanTo stops, they get to their places. How can I updateMarkers on every frame in PanTo ?
Regards
Pol
I’m happy
-
Inappropriate?Thanks Tomas! I'd implemented something similar in the Actionscript 3 version for panning, but not for zooming.
We're making quite a few tweaks over the next couple of days, this will be one of them!
I’m thankful
-
Inappropriate?Please can you share with us the code zoomTo and the panTo in ASĀ·?
-
Inappropriate?Hello Pol,
following worked for me...
in com.modestmaps.core.MarkerClip make the updateClips() method public like so...
public function updateClips():Void
{
for(var id:String in __names)
if(this[__names[id]] && this[__names[id]]._visible)
updateClip(id);
}
in the com.modestmaps.Map add this function...
private function updateMarkerClips()
{
__markers.updateClips();
}
in com.modestmaps.Map call updateMarkerClips() method after onPanned call like so...
private function animationProcess(lastType:String):Void
{
if(__animSteps.length) {
var step:Object = __animSteps.shift();
if(step.type == 'pan') {
//grid.allowPainting(__animSteps.length <= 1);
grid.panRight(step.amount.x);
grid.panDown(step.amount.y);
__currentPosition.x += step.amount.x;
__currentPosition.y += step.amount.y;
onPanned(new Point(__currentPosition.x-__startingPosition.x, __currentPosition.y-__startingPosition.y));
updateMarkerClips(); //<--- this line added by yalu
now the markers should update when calling panTo or panUp or other pan methods in com.modestmaps.Map
I am not a pro but this worked for me flawlessly. Hope this works for everybody.
additionally(and optionally) I also made a little change(instead of using centerPoint.x and centerPoint.y-- i used __width/2 and __height/2) to the panTo function like so...
public function panTo (targetLoc:Location):Void {
var targetPoint:Point = locationPoint(targetLoc, grid);
var distance:Point = new Point(Math.round((targetPoint.x - __width / 2) / panFrames), Math.round((targetPoint.y - __height / 2) / panFrames));
panMap(distance);
}
this worked for me more reliably in the use of panTo function.
Regards,
Yalu
I’m happy
-
Inappropriate?This is in the latest version in subversion, for AS3. Sorry for the delay!
http://modestmaps.mapstraction.com/tr...
I’m happy
The company thinks
this is one of the best points
-
Inappropriate?I just dowloaded the latest AS3 project from trunk and ran the SampleFlexClient. I believe that there is a bug because the left map is draggable and the right map isn't. I was testing in firefox. Is anyone having a problem with this new version. Thanks
-
Inappropriate?When I replaced this new map.as in an existing flex project, it has the same bug. Do you know what this bug could be?
-
Inappropriate?zoomTo and panTo are very useful but I would like to do both at the same time (pan to a location while zooming one level). If someone did it in AS3, let me know.
thanks,
Nicolas
Loading Profile...







EMPLOYEE




