root/trunk/as2/lib/com/modestmaps/Map.as

Revision 550, 24.6 kB (checked in by allens, 4 months ago)

added Map.backgroundColor

  • Property svn:keywords set to Id
Line 
1 /**
2  * vim:et sts=4 sw=4 cindent:
3  * @ignore
4  *
5  * @author migurski
6  * @author darren
7  * $Id$
8  *
9  * com.modestmaps.Map is the base class and interface for Modest Maps.
10  *
11  * @description Map is the base class and interface for Modest Maps.
12  *                              Correctly attaching an instance of this MovieClip subclass
13  *                              should result in a pannable map. Controls and event
14  *                              handlers must be added separately.
15  *
16  * @usage <code>
17  *          import com.modestmaps.Map;
18  *          import com.modestmaps.geo.Location;
19  *          import com.modestmaps.mapproviders.BlueMarbleMapProvider;
20  *          import com.stamen.twisted.Reactor;
21  *          ...
22  *          Reactor.run(clip, null, 50);
23  *          var map:Map = Map(clip.attachMovie(Map.symbolName, 'map', clip.getNextHighestDepth()));
24  *          map.init(640, 480, true, new BlueMarbleMapProvider());
25  *        </code>
26  */
27
28 import com.bigspaceship.utils.Delegate;
29 import org.casaframework.movieclip.DispatchableMovieClip;
30 import flash.geom.Point;
31
32 import com.modestmaps.core.MapExtent;
33 import com.modestmaps.core.MapPosition;
34 import com.modestmaps.core.Coordinate;
35 import com.modestmaps.core.TileGrid;
36 import com.modestmaps.core.MarkerClip;
37 import com.modestmaps.geo.Location;
38 import com.modestmaps.mapproviders.IMapProvider;
39 import com.stamen.twisted.DelayedCall;
40 import com.stamen.twisted.Reactor;
41
42 class com.modestmaps.Map
43 extends DispatchableMovieClip
44 {
45     private var __width:Number = 320;
46     private var __height:Number = 240;
47     private var __draggable:Boolean = true;
48    
49     public var backgroundColor:Number = 0x666666;
50
51     // pending animation steps, array of {type:'pan'/'zoom', amount:Point/Number, redraw:Boolean}
52     private var __animSteps:/*Object*/Array;
53
54     // associated animation call
55     private var __animTask:DelayedCall;
56
57     // frames-per-2x-zoom
58     public var zoomFrames:Number = 6;
59    
60     // frames-per-full-pan
61     public var panFrames:Number = 12;
62    
63     private var __startingPosition:Point;
64     private var __currentPosition:Point;
65     private var __startingZoom:Number;
66     private var __currentZoom:Number;
67
68     // das grid
69     public var grid:TileGrid;
70
71     // markers are attached here
72     private var __markers:MarkerClip;
73     private var __mask:MovieClip;
74
75     // Who do we get our Map graphics from?
76     private var __mapProvider:IMapProvider;
77
78     // Events thrown
79     public static var EVENT_MARKER_ENTERS:String = 'Marker enters';
80     public static var EVENT_MARKER_LEAVES:String = 'Marker leaves';
81     public static var EVENT_START_ZOOMING:String = 'Start zooming';
82     public static var EVENT_STOP_ZOOMING:String = 'Stop zooming';
83     public static var EVENT_ZOOMED_BY:String = 'Zoomed by...';
84     public static var EVENT_START_PANNING:String = 'Start panning';
85     public static var EVENT_STOP_PANNING:String = 'Stop panning';
86     public static var EVENT_PANNED_BY:String = 'Panned by...';
87     public static var EVENT_RESIZED_TO:String = 'Resized to...';
88     public static var EVENT_EXTENT_CHANGED:String = 'Extent changed';
89
90     public static var symbolName:String = '__Packages.com.modestmaps.Map';
91     public static var symbolOwner:Function = Map;
92     public static var symbolLink:Boolean = Object.registerClass(symbolName, symbolOwner);
93    
94    /*
95     * Initialize the map: set properties, add a tile grid, draw it.
96     * This method must be called before the map can be used!
97     * Default extent covers the entire globe, (+/-85, +/-180).
98     *
99     * @param    Width of map, in pixels.
100     * @param    Height of map, in pixels.
101     * @param    Whether the map can be dragged or not.
102     * @param    Desired map provider, e.g. Blue Marble.
103     *
104     * @see com.modestmaps.core.TileGrid
105     */
106     public function init(width:Number, height:Number, draggable:Boolean, provider:IMapProvider):Void
107     {
108         if(!Reactor.running())
109         {
110             // throw new Error('com.modestmaps.Map.init(): com.stamen.Twisted.Reactor ought to be running at this point.');
111             Reactor.run(this, 50);
112         }
113
114         __animSteps = [];
115
116         setSize(width, height);
117         setMapProvider(provider);
118         __draggable = draggable;
119    
120         grid = TileGrid(attachMovie(TileGrid.symbolName, 'grid', getNextHighestDepth()));
121         grid.init(width, height, draggable, provider, this);
122
123         __markers = MarkerClip(attachMovie(MarkerClip.symbolName, '__markers', getNextHighestDepth(), {_x: __width/2, _y: __height/2}));
124         __mask = createEmptyMovieClip('__mask', getNextHighestDepth());
125         __markers.setMask(__mask);
126         __markers.setMap(this);
127        
128         redraw();
129     }
130
131    /*
132     * Based on a MapExtent, determine appropriate map
133     * bounds using extentPosition(), and inform the grid of
134     * tile coordinate and point by calling grid.resetTiles().
135     * Resulting map extent will ensure that all passed locations
136     * are visible.
137     *
138     * @param    MapExtent.
139     *
140     * @see com.modestmaps.Map#extentPosition
141     * @see com.modestmaps.core.TileGrid#resetTiles
142     */
143     public function setExtent(extent:MapExtent):Void
144     {
145         // what to do if a bad extent is passed?
146         var position:MapPosition = extentPosition(extent);
147    
148         // tell grid what the rock is cooking
149         grid.resetTiles(position.coord, position.point);
150         onExtentChanged(getExtent());
151         Reactor.callNextFrame(Delegate.create(this, this.callCopyright));
152         Reactor.callNextFrame(Delegate.create(this, this.callCopyright));
153     }
154    
155    /*
156     * Based on a location and zoom level, determine appropriate initial
157     * tile coordinate and point using coordinatePosition(), and inform
158     * the grid of tile coordinate and point by calling grid.resetTiles().
159     *
160     * @param    Location of center.
161     * @param    Desired zoom level.
162     *
163     * @see com.modestmaps.Map#extentPosition
164     * @see com.modestmaps.core.TileGrid#resetTiles
165     */
166     public function setCenterZoom(location:Location, zoom:Number):Void
167     {
168         var center:MapPosition = coordinatePosition(__mapProvider.locationCoordinate(location).zoomTo(zoom));
169        
170         // tell grid what the rock is cooking
171         grid.resetTiles(center.coord, center.point);
172         onExtentChanged(getExtent());
173         Reactor.callNextFrame(Delegate.create(this, this.callCopyright));
174         Reactor.callNextFrame(Delegate.create(this, this.callCopyright));
175     }
176    
177    /*
178     * Based on a coordinate, determine appropriate starting tile and position,
179     * and return a MapPosition.
180     */
181     private function coordinatePosition(centerCoord:Coordinate):MapPosition
182     {
183         // initial tile coordinate
184         var initTileCoord:Coordinate = new Coordinate(Math.floor(centerCoord.row), Math.floor(centerCoord.column), Math.floor(centerCoord.zoom));
185
186         // initial tile position, assuming centered tile well in grid
187         var initX:Number = (initTileCoord.column - centerCoord.column) * TileGrid.TILE_WIDTH;
188         var initY:Number = (initTileCoord.row - centerCoord.row) * TileGrid.TILE_HEIGHT;
189         var initPoint:Point = new Point(Math.round(initX), Math.round(initY));
190        
191         return new MapPosition(initTileCoord, initPoint);
192     }
193    
194    /*
195     * Based on an array of locations, determine appropriate map bounds
196     * in terms of tile grid, and return a MapPosition from coordinatePosition().
197     */
198     private function locationsPosition(locations:/*Location*/Array):MapPosition
199     {
200         // my kingdom for a decent map() function in AS2
201         var coordinates:/*Coordinate*/Array = [];
202        
203         for(var i:Number = 0; i < locations.length; i += 1)
204             coordinates.unshift(__mapProvider.locationCoordinate(locations[i]));
205    
206         // get outermost top left and bottom right coordinates to cover all locations
207         var TL:Coordinate = new Coordinate(coordinates[0].row, coordinates[0].column, coordinates[0].zoom);
208         var BR:Coordinate = new Coordinate(coordinates[0].row, coordinates[0].column, coordinates[0].zoom);
209        
210         while(coordinates.length) {
211             TL = new Coordinate(Math.min(TL.row, coordinates[0].row), Math.min(TL.column, coordinates[0].column), Math.min(TL.zoom, coordinates[0].zoom));
212             BR = new Coordinate(Math.max(BR.row, coordinates[0].row), Math.max(BR.column, coordinates[0].column), Math.max(BR.zoom, coordinates[0].zoom));
213             coordinates.shift();
214         }
215
216         // multiplication factor between horizontal span and map width
217         var hFactor:Number = (BR.column - TL.column) / (__width / TileGrid.TILE_WIDTH);
218        
219         // multiplication factor expressed as base-2 logarithm, for zoom difference
220         var hZoomDiff:Number = Math.log(hFactor) / Math.log(2);
221        
222         // possible horizontal zoom to fit geographical extent in map width
223         var hPossibleZoom:Number = TL.zoom - Math.ceil(hZoomDiff);
224        
225         // multiplication factor between vertical span and map height
226         var vFactor:Number = (BR.row - TL.row) / (__height / TileGrid.TILE_HEIGHT);
227        
228         // multiplication factor expressed as base-2 logarithm, for zoom difference
229         var vZoomDiff:Number = Math.log(vFactor) / Math.log(2);
230        
231         // possible vertical zoom to fit geographical extent in map height
232         var vPossibleZoom:Number = TL.zoom - Math.ceil(vZoomDiff);
233        
234         // initial zoom to fit extent vertically and horizontally
235         // additionally, make sure it's not outside the boundaries set by provider limits
236         var initZoom:Number = Math.min(hPossibleZoom, vPossibleZoom);
237         initZoom = Math.min(initZoom, __mapProvider.outerLimits()[1].zoom);
238         initZoom = Math.max(initZoom, __mapProvider.outerLimits()[0].zoom);
239
240         // coordinate of extent center
241         var centerRow:Number = (TL.row + BR.row) / 2;
242         var centerColumn:Number = (TL.column + BR.column) / 2;
243         var centerZoom:Number = (TL.zoom + BR.zoom) / 2;
244         var centerCoord:Coordinate = (new Coordinate(centerRow, centerColumn, centerZoom)).zoomTo(initZoom);
245        
246         return coordinatePosition(centerCoord);
247     }
248
249    /*
250     * Based on a MapExtent, determine appropriate map bounds
251     * in terms of tile grid, and return a MapPosition from calculateMapCenter().
252     */
253     private function extentPosition(extent:MapExtent):MapPosition
254     {
255         var locations:/*Location*/Array = [extent.northWest, extent.southEast];
256         return locationsPosition(locations);
257     }
258    
259    /*
260     * Return the current coverage area of the map, as MapExtent.
261     *
262     * @return   MapExtent.
263     */
264     public function getExtent():MapExtent
265     {
266         if(!__mapProvider)
267             return new MapExtent();
268
269         var coordTL:Coordinate = grid.topLeftCoordinate();
270         var coordBR:Coordinate = grid.bottomRightCoordinate();
271         var coordTR:Coordinate = new Coordinate(coordTL.row, coordBR.column, coordTL.zoom);
272         var coordBL:Coordinate = new Coordinate(coordBR.row, coordTL.column, coordBR.zoom);
273        
274         var TL:Location = __mapProvider.coordinateLocation(coordTL);
275         var BR:Location = __mapProvider.coordinateLocation(coordBR);
276         var TR:Location = __mapProvider.coordinateLocation(coordTR);
277         var BL:Location = __mapProvider.coordinateLocation(coordBL);
278        
279         return new MapExtent(Math.max(Math.max(TL.lat, TR.lat), Math.max(BL.lat, BR.lat)),
280                              Math.min(Math.min(TL.lat, TR.lat), Math.min(BL.lat, BR.lat)),
281                              Math.max(Math.max(TL.lon, TR.lon), Math.max(BL.lon, BR.lon)),
282                              Math.min(Math.min(TL.lon, TR.lon), Math.min(BL.lon, BR.lon)));
283     }
284
285    /*
286     * Return the current center location and zoom of the map.
287     *
288     * @return   Array of center and zoom: [center location, zoom number].
289     */
290     public function getCenterZoom():Array
291     {
292         return [__mapProvider.coordinateLocation(grid.centerCoordinate()), grid.zoomLevel];
293     }
294
295    /**
296     * Set new map size, call onResized().
297     *
298     * @param    New map width.
299     * @param    New map height.
300     *
301     * @see com.modestmaps.Map#onResized
302     */
303     public function setSize(width:Number, height:Number):Void
304     {
305         __width = width;
306         __height = height;
307         redraw();
308
309         grid.resizeTo(new Point(__width, __height));
310         onResized();
311     }
312
313    /**
314     * Get map size.
315     *
316     * @return   Array of [width, height].
317     */
318     public function getSize():/*Number*/Array
319     {
320         var size:/*Number*/Array = [__width, __height];
321         return size;
322     }
323
324    /**
325     * Get a reference to the current map provider.
326     *
327     * @return   Map provider.
328     *
329     * @see com.modestmaps.mapproviders.IMapProvider
330     */
331     public function getMapProvider():IMapProvider
332     {
333         return __mapProvider;
334     }
335
336    /**
337     * Set a new map provider, repainting tiles and changing bounding box if necessary.
338     *
339     * @param   Map provider.
340     *
341     * @see com.modestmaps.mapproviders.IMapProvider
342     */
343     public function setMapProvider(newProvider:IMapProvider):Void
344     {
345         var previousGeometry:String = __mapProvider.geometry();
346         var extent:MapExtent = getExtent();
347        
348         __mapProvider = newProvider;
349         grid.setMapProvider(__mapProvider);
350        
351         if(__mapProvider.geometry() == previousGeometry) {
352                 grid.repaintTiles();
353                
354         } else {
355                 setExtent(extent);
356                
357         }
358
359         Reactor.callLater(1000, Delegate.create(this, this.callCopyright));
360     }
361    
362    /**
363     * Get a point (x, y) for a location (lat, lon) in the context of a given clip.
364     *
365     * @param    Location to match.
366     * @param    Movie clip context in which returned point should make sense.
367     *
368     * @return   Matching point.
369     */
370     public function locationPoint(location:Location, context:MovieClip):Point
371     {
372         var coord:Coordinate = __mapProvider.locationCoordinate(location);
373         return grid.coordinatePoint(coord, context);
374     }
375    
376    /**
377     * Get a location (lat, lon) for a point (x, y) in the context of a given clip.
378     *
379     * @param    Point to match.
380     * @param    Movie clip context in which passed point should make sense.
381     *
382     * @return   Matching location.
383     */
384     public function pointLocation(point:Point, context:MovieClip):Location
385     {
386         var coord:Coordinate = grid.pointCoordinate(point, context);
387         return __mapProvider.coordinateLocation(coord);
388     }
389    
390    /**
391     * Pan up by 2/3 of the map height.
392     * @see com.modestmaps.Map#panMap
393     */
394     public function panUp():Void
395     {
396         var distance:Number = -2*__height / 3;
397         panMap(new Point(0, Math.round(distance/panFrames)));
398     }     
399
400    /**
401     * Pan down by 2/3 of the map height.
402     * @see com.modestmaps.Map#panMap
403     */
404     public function panDown():Void
405     {
406         var distance:Number = 2*__height / 3;
407         panMap(new Point(0, Math.round(distance/panFrames)));
408     }
409    
410    /**
411     * Pan to the left by 2/3 of the map width.
412     * @see com.modestmaps.Map#panMap
413     */
414     public function panLeft():Void
415     {
416         var distance:Number = -2*__width / 3;
417         panMap(new Point(Math.round(distance/panFrames, 0)));
418     }     
419
420    /**
421     * Pan to the right by 2/3 of the map width.
422     * @see com.modestmaps.Map#panMap
423     */
424     public function panRight():Void
425     {
426         var distance:Number = 2*__width / 3;
427         panMap(new Point(Math.round(distance/panFrames, 0)));
428     }
429    
430     private function panMap(perFrame:Point):Void
431     {
432         for(var i = 1; i <= panFrames; i += 1)
433             __animSteps.push({type: 'pan', amount: perFrame});
434            
435         if(!__animTask) {
436             __startingPosition = new Point(grid._x, grid._y);
437             __currentPosition = new Point(grid._x, grid._y);
438
439             onStartPan();
440             animationProcess();
441         }
442     }
443    
444    /**
445     * Zoom in by 200% over the course of several frames.
446     * @see com.modestmaps.Map#zoomFrames
447     */
448     public function zoomIn():Void
449     {
450         for(var i = 1; i <= zoomFrames; i += 1)
451             __animSteps.push({type: 'zoom', amount: 1/zoomFrames, redraw: Boolean(i == zoomFrames)});
452            
453         if(!__animTask) {
454             __startingZoom = grid.zoomLevel;
455             __currentZoom = grid.zoomLevel;
456
457             onStartZoom();
458             animationProcess();
459         }
460     }
461    
462    /**
463     * Zoom out by 50% over the course of several frames.
464     * @see com.modestmaps.Map#zoomFrames
465     */
466     public function zoomOut():Void
467     {
468         for(var i = 1; i <= zoomFrames; i += 1)
469             __animSteps.push({type: 'zoom', amount: -1/zoomFrames, redraw: Boolean(i == zoomFrames)});
470            
471         if(!__animTask) {
472             __startingZoom = grid.zoomLevel;
473             __currentZoom = grid.zoomLevel;
474
475             onStartZoom();
476             animationProcess();
477         }
478     }
479    
480     private function animationProcess(lastType:String):Void
481     {
482         if(__animSteps.length) {
483             var step:Object = __animSteps.shift();
484
485             if(step.type == 'pan') {
486                 //grid.allowPainting(__animSteps.length <= 1);
487                 grid.panRight(step.amount.x);
488                 grid.panDown(step.amount.y);
489    
490                 __currentPosition.x += step.amount.x;
491                 __currentPosition.y += step.amount.y;
492                 onPanned(new Point(__currentPosition.x-__startingPosition.x, __currentPosition.y-__startingPosition.y));
493
494             } else if(step.type == 'zoom') {
495                 grid.allowPainting(__animSteps.length <= 1);
496                 grid.zoomBy(Number(step.amount), Boolean(step.redraw));
497    
498                 __currentZoom += Number(step.amount);
499                 onZoomed(__currentZoom - __startingZoom);
500            
501             }
502
503             __animTask = Reactor.callNextFrame(Delegate.create(this, this.animationProcess), step.type);
504            
505             if(lastType == 'pan' && step.type == 'zoom') {
506                 onStopPan();
507                 onStartZoom();
508
509             } else if(lastType == 'zoom' && step.type == 'pan') {
510                 onStopZoom();
511                 onStartPan();
512
513             }
514
515         } else {
516             grid.allowPainting(true);
517             delete __animTask;
518
519             if(lastType == 'pan')
520                 onStopPan();
521
522             if(lastType == 'zoom')
523                 onStopZoom();
524         }
525     }
526
527    /**
528     * Add a marker with the given id and location (lat, lon).
529     *
530     * @param    ID of marker, opaque string.
531     * @param    Location of marker.
532     * @param    Optional symbol name if a clip is to be attached.
533     * @return   Optional attached movie clip, if a valid symbol was provided.
534     */
535     public function putMarker(id:String, location:Location, symbol:String):MovieClip
536     {
537         //trace('Marker '+id+': '+location.toString());
538         grid.putMarker(id, __mapProvider.locationCoordinate(location), location);
539        
540         if(symbol)
541             return __markers.attachMarker(id, location, symbol);
542            
543         return undefined;
544     }
545
546    /**
547     * Get a marker clip with the given id if one was created.
548     *
549     * @param    ID of marker, opaque string.
550     * @return   Optional attached movie clip, if a valid symbol was provided.
551     */
552     public function getMarker(id:String):MovieClip
553     {
554         return __markers.getMarker(id);
555     }
556
557    /**
558     * Remove a marker with the given id.
559     *
560     * @param    ID of marker, opaque string.
561     */
562     public function removeMarker(id:String):Void
563     {
564         grid.removeMarker(id);
565         __markers.removeMarker(id);
566     }
567    
568    /**
569     * Call javascript:modestMaps.copyright() with details about current view.
570     * See js/copyright.js.
571     */
572     private function callCopyright():Void
573     {
574         var cenP:Point = new Point(__width/2, __height/2);
575         var minP:Point = new Point(__width/5, __height/5);
576         var maxP:Point = new Point(__width*4/5, __height*4/5);
577        
578         var cenC:Coordinate = grid.pointCoordinate(cenP, this);
579         var minC:Coordinate = grid.pointCoordinate(minP, this);
580         var maxC:Coordinate = grid.pointCoordinate(maxP, this);
581        
582         var cenL:Location = __mapProvider.coordinateLocation(__mapProvider.sourceCoordinate(cenC));
583         var minL:Location = __mapProvider.coordinateLocation(__mapProvider.sourceCoordinate(minC));
584         var maxL:Location = __mapProvider.coordinateLocation(__mapProvider.sourceCoordinate(maxC));
585    
586         var minLat:Number = Math.min(minL.lat, maxL.lat);
587         var minLon:Number = Math.min(minL.lon, maxL.lon);
588         var maxLat:Number = Math.max(minL.lat, maxL.lat);
589         var maxLon:Number = Math.max(minL.lon, maxL.lon);
590        
591         getURL('javascript:try{modestMaps.copyright("'+__mapProvider.toString()+'", '+cenL.lat+', '+cenL.lon+', '+minLat+', '+minLon+', '+maxLat+', '+maxLon+', '+grid.zoomLevel+');}catch(e){void(0);};void(0);');
592     }
593    
594    /**
595     * Dispatches EVENT_MARKER_ENTERS when a given marker enters the tile coverage area.
596     * Event object includes id:String and location:Location.
597     *
598     * @param    ID of marker.
599     * @param    Location of marker.
600     *
601     * @see com.modestmaps.Map#EVENT_MARKER_ENTERS
602     */
603     public function onMarkerEnters(id:String, location:Location):Void
604     {
605         //trace('+ '+marker.toString());
606         dispatchEvent( EVENT_MARKER_ENTERS, id, location );
607     }
608    
609    /**
610     * Dispatches EVENT_MARKER_LEAVES when a given marker leaves the tile coverage area.
611     * Event object includes id:String and location:Location.
612     *
613     * @param    ID of marker.
614     * @param    Location of marker.
615     *
616     * @see com.modestmaps.Map#EVENT_MARKER_LEAVES
617     */
618     public function onMarkerLeaves(id:String, location:Location):Void
619     {
620         //trace('- '+marker.toString());
621         dispatchEvent( EVENT_MARKER_LEAVES, id, location );
622     }
623    
624    /**
625     * Dispatches EVENT_START_ZOOMING when the map starts zooming.
626     * Event object includes level:Number.
627     *
628     * @see com.modestmaps.Map#EVENT_START_ZOOMING
629     */
630     public function onStartZoom():Void
631     {
632         //trace('Leaving zoom level '+grid.zoomLevel+'...');
633         dispatchEvent( EVENT_START_ZOOMING, grid.zoomLevel );
634     }
635    
636    /**
637     * Dispatches EVENT_STOP_ZOOMING when the map stops zooming.
638     * Callback arguments includes level:Number.
639     *
640     * @see com.modestmaps.Map#EVENT_STOP_ZOOMING
641     */
642     public function onStopZoom():Void
643     {
644         //trace('...Entering zoom level '+grid.zoomLevel);
645         dispatchEvent( EVENT_STOP_ZOOMING, grid.zoomLevel );
646         callCopyright();
647     }
648    
649    /**
650     * Dispatches EVENT_ZOOMED_BY when the map is zooomed.
651     * Callback arguments includes delta:Number, difference in levels from zoom start.
652     *
653     * @param    Change in level since beginning of zoom.
654     *
655     * @see com.modestmaps.Map#EVENT_ZOOMED_BY
656     */
657     public function onZoomed(delta:Number):Void
658     {
659         //trace('Current well offset from start: '+delta.toString());
660         dispatchEvent( EVENT_ZOOMED_BY, delta );
661     }
662    
663    /**
664     * Dispatches EVENT_START_PANNING when the map starts to be panned.
665     *
666     * @see com.modestmaps.Map#EVENT_START_PANNING
667     */
668     public function onStartPan():Void
669     {
670         //trace('Starting pan...');
671         dispatchEvent( EVENT_START_PANNING );
672     }
673    
674    /**
675     * Dispatches EVENT_STOP_PANNING when the map stops being panned.
676     *
677     * @see com.modestmaps.Map#EVENT_STOP_PANNING
678     */
679     public function onStopPan():Void
680     {
681         //trace('...Stopping pan');
682         dispatchEvent( EVENT_STOP_PANNING );
683         callCopyright();
684     }
685    
686    /**
687     * Dispatches EVENT_PANNED_BY when the map is panned.
688     * Callback arguments includes delta:Point, difference in pixels from pan start.
689     *
690     * @param    Change in position since beginning of pan.
691     *
692     * @see com.modestmaps.Map#EVENT_PANNED_BY
693     */
694     public function onPanned(delta:Point):Void
695     {
696         //trace('Current well offset from start: '+delta.toString());
697         dispatchEvent( EVENT_PANNED_BY, delta );
698     }
699    
700    /**
701     * Dispatches EVENT_RESIZED_TO when the map is resized.
702     * Callback arguments include width:Number and height:Number.
703     *
704     * @see com.modestmaps.Map#EVENT_RESIZED_TO
705     */
706     public function onResized():Void
707     {
708         dispatchEvent( EVENT_RESIZED_TO, __width, __height );
709     }
710    
711    /**
712     * Dispatches EVENT_EXTENT_CHANGED when the map extent changes.
713     * Callback arguments include extent:MapExtent.
714     *
715     * @see com.modestmaps.Map#EVENT_EXTENT_CHANGED
716     */
717     public function onExtentChanged(extent:MapExtent):Void
718     {
719         dispatchEvent( EVENT_RESIZED_TO, extent );
720     }
721    
722     private function redraw()
723     {
724         clear();
725
726         __mask.clear();
727         __mask.moveTo(0, 0);
728         __mask.lineStyle();
729         __mask.beginFill(0xFF00FF, 0);
730         __mask.lineTo(0, __height);
731         __mask.lineTo(__width, __height);
732         __mask.lineTo(__width, 0);
733         __mask.lineTo(0, 0);
734         __mask.endFill();
735     }
736 }
Note: See TracBrowser for help on using the browser.