Changeset 184
- Timestamp:
- 03/20/07 21:24:14 (2 years ago)
- Files:
-
- trunk/as2/lib/com/modestmaps/Map.as (modified) (27 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
trunk/as2/lib/com/modestmaps/Map.as
r179 r184 1 1 /* 2 2 * vim:et sts=4 sw=4 cindent: 3 * $Id$ 3 * @ignore 4 * 5 * @author Michal Migurski <mike@stamen.com> 6 * @author Darren David <darren@lookorfeel.com> 7 * 8 * com.modestmaps.Map is the base class and interface for Modest Maps. 9 * 10 * Correctly attaching an instance of this MovieClip subclass should result 11 * in a pannable map. Controls and event handlers must be added separately. 12 * 13 * @usage <code> 14 * import com.modestmaps.Map; 15 * import com.modestmaps.geo.Location; 16 * import com.modestmaps.mapproviders.BlueMarbleMapProvider; 17 * import com.stamen.twisted.Reactor; 18 * ... 19 * Reactor.run(clip, null, 50); 20 * var map:Map = Map(clip.attachMovie(Map.symbolName, 'map', clip.getNextHighestDepth())); 21 * map.init(640, 480, true, new BlueMarbleMapProvider()); 22 * </code> 4 23 */ 5 24 … … 30 49 31 50 // frames-per-2x-zoom 32 p rivate static var __zoomFrames:Number = 6;51 public var zoomFrames:Number = 6; 33 52 34 53 // frames-per-full-pan 35 p rivate static var __panFrames:Number = 12;54 public var panFrames:Number = 12; 36 55 37 56 private var __startingPosition:Point; … … 63 82 /* 64 83 * Initialize the map: set properties, add a tile grid, draw it. 84 * Default extent covers the entire globe, (+/-85, +/-180). 85 * 86 * @param Width of map, in pixels. 87 * @param Height of map, in pixels. 88 * @param Whether the map can be dragged or not. 89 * @param Desired map provider, e.g. Blue Marble. 90 * 91 * @see com.modestmaps.core.TileGrid 65 92 */ 66 93 public function init(width:Number, height:Number, draggable:Boolean, provider:IMapProvider):Void … … 94 121 * bounds using calculateMapExtent(), and inform the grid of 95 122 * tile coordinate and point by calling grid.resetTiles(). 123 * Resulting map extent will ensure that all passed locations 124 * are visible. 125 * 126 * @param Array of locations. 127 * 128 * @see com.modestmaps.Map#calculateMapExtent 129 * @see com.modestmaps.core.TileGrid#resetTiles 96 130 */ 97 131 public function setExtent(locations:/*Location*/Array):Void … … 107 141 * tile coordinate and point using calculateMapCenter(), and inform 108 142 * the grid of tile coordinate and point by calling grid.resetTiles(). 143 * 144 * @param Location of center. 145 * @param Desired zoom level. 146 * 147 * @see com.modestmaps.Map#calculateMapExtent 148 * @see com.modestmaps.core.TileGrid#resetTiles 109 149 */ 110 150 public function setCenterZoom(location:Location, zoom:Number):Void … … 191 231 /* 192 232 * Return the current coverage area of the map, as four locations. 233 * 234 * @return Array of four locations: [top-left, top-right, bottom-left, bottom-right]. 193 235 */ 194 236 public function getExtent():/*Location*/Array … … 220 262 221 263 /* 222 * Return the current center location and zoom of the map, in a two-element array. 264 * Return the current center location and zoom of the map. 265 * 266 * @return Array of center and zoom: [center location, zoom number]. 223 267 */ 224 268 public function getCenterZoom():Array … … 228 272 229 273 /** 230 * Set new map size. 274 * Set new map size, call onResized(). 275 * 276 * @param New map width. 277 * @param New map height. 278 * 279 * @see com.modestmaps.Map#onResized 231 280 */ 232 281 public function setSize(width:Number, height:Number):Void … … 239 288 240 289 /** 241 * Get map size, width:Number, height:Number. 290 * Get map size. 291 * 292 * @return Array of [width, height]. 242 293 */ 243 294 public function getSize():/*Number*/Array … … 248 299 249 300 /** 250 * Get a reference to the current mapProvider. 301 * Get a reference to the current map provider. 302 * 303 * @return Map provider. 304 * 305 * @see com.modestmaps.mapproviders.IMapProvider 251 306 */ 252 307 public function getMapProvider():IMapProvider … … 256 311 257 312 /** 258 * Set a new mapProvider, repainting tiles and changing bounding box if necessary. 313 * Set a new map provider, repainting tiles and changing bounding box if necessary. 314 * 315 * @param Map provider. 316 * 317 * @see com.modestmaps.mapproviders.IMapProvider 259 318 */ 260 319 public function setMapProvider(newProvider:IMapProvider):Void … … 276 335 /** 277 336 * Get a point (x, y) for a location (lat, lon) in the context of a given clip. 337 * 338 * @param Location to match. 339 * @param Movie clip context in which returned point should make sense. 340 * 341 * @return Matching point. 278 342 */ 279 343 public function locationPoint(location:Location, context:MovieClip):Point … … 285 349 /** 286 350 * Get a location (lat, lon) for a point (x, y) in the context of a given clip. 351 * 352 * @param Point to match. 353 * @param Movie clip context in which passed point should make sense. 354 * 355 * @return Matching location. 287 356 */ 288 357 public function pointLocation(point:Point, context:MovieClip):Location … … 294 363 /** 295 364 * Pan up by 2/3 of the map height. 365 * @see com.modestmaps.Map#panMap 296 366 */ 297 367 public function panUp():Void 298 368 { 299 369 var distance:Number = -2*__height / 3; 300 panMap(new Point(0, Math.round(distance/ __panFrames)));370 panMap(new Point(0, Math.round(distance/panFrames))); 301 371 } 302 372 303 373 /** 304 374 * Pan down by 2/3 of the map height. 375 * @see com.modestmaps.Map#panMap 305 376 */ 306 377 public function panDown():Void 307 378 { 308 379 var distance:Number = 2*__height / 3; 309 panMap(new Point(0, Math.round(distance/ __panFrames)));380 panMap(new Point(0, Math.round(distance/panFrames))); 310 381 } 311 382 312 383 /** 313 384 * Pan to the left by 2/3 of the map width. 385 * @see com.modestmaps.Map#panMap 314 386 */ 315 387 public function panLeft():Void 316 388 { 317 389 var distance:Number = -2*__width / 3; 318 panMap(new Point(Math.round(distance/ __panFrames, 0)));390 panMap(new Point(Math.round(distance/panFrames, 0))); 319 391 } 320 392 321 393 /** 322 394 * Pan to the right by 2/3 of the map width. 395 * @see com.modestmaps.Map#panMap 323 396 */ 324 397 public function panRight():Void 325 398 { 326 399 var distance:Number = 2*__width / 3; 327 panMap(new Point(Math.round(distance/ __panFrames, 0)));400 panMap(new Point(Math.round(distance/panFrames, 0))); 328 401 } 329 402 330 403 private function panMap(perFrame:Point):Void 331 404 { 332 for(var i = 1; i <= __panFrames; i += 1)405 for(var i = 1; i <= panFrames; i += 1) 333 406 __animSteps.push({type: 'pan', amount: perFrame}); 334 407 … … 343 416 344 417 /** 345 * Zoom in by 200% over the course of __zoomFrames frames. 418 * Zoom in by 200% over the course of several frames. 419 * @see com.modestmaps.Map#zoomFrames 346 420 */ 347 421 public function zoomIn():Void 348 422 { 349 for(var i = 1; i <= __zoomFrames; i += 1)350 __animSteps.push({type: 'zoom', amount: 1/ __zoomFrames, redraw: Boolean(i == __zoomFrames)});423 for(var i = 1; i <= zoomFrames; i += 1) 424 __animSteps.push({type: 'zoom', amount: 1/zoomFrames, redraw: Boolean(i == zoomFrames)}); 351 425 352 426 if(!__animTask) { … … 360 434 361 435 /** 362 * Zoom in by 200% over the course of __zoomFrames frames. 436 * Zoom out by 50% over the course of several frames. 437 * @see com.modestmaps.Map#zoomFrames 363 438 */ 364 439 public function zoomOut():Void 365 440 { 366 for(var i = 1; i <= __zoomFrames; i += 1)367 __animSteps.push({type: 'zoom', amount: -1/ __zoomFrames, redraw: Boolean(i == __zoomFrames)});441 for(var i = 1; i <= zoomFrames; i += 1) 442 __animSteps.push({type: 'zoom', amount: -1/zoomFrames, redraw: Boolean(i == zoomFrames)}); 368 443 369 444 if(!__animTask) { … … 425 500 /** 426 501 * Add a marker with the given id and location (lat, lon). 502 * 503 * @param ID of marker, opaque string. 504 * @param Location of marker. 427 505 */ 428 506 public function putMarker(id:String, location:Location):Void … … 434 512 /** 435 513 * Remove a marker with the given id. 514 * 515 * @param ID of marker, opaque string. 436 516 */ 437 517 public function removeMarker(id:String):Void … … 443 523 * Dispatches EVENT_MARKER_ENTERS when a given marker enters the tile coverage area. 444 524 * Event object includes id:String and location:Location. 525 * 526 * @param ID of marker. 527 * @param Location of marker. 528 * 529 * @see com.modestmaps.Map#EVENT_MARKER_ENTERS 445 530 */ 446 531 public function onMarkerEnters(id:String, location:Location):Void … … 453 538 * Dispatches EVENT_MARKER_LEAVES when a given marker leaves the tile coverage area. 454 539 * Event object includes id:String and location:Location. 540 * 541 * @param ID of marker. 542 * @param Location of marker. 543 * 544 * @see com.modestmaps.Map#EVENT_MARKER_LEAVES 455 545 */ 456 546 public function onMarkerLeaves(id:String, location:Location):Void … … 463 553 * Dispatches EVENT_START_ZOOMING when the map starts zooming. 464 554 * Event object includes level:Number. 555 * 556 * @see com.modestmaps.Map#EVENT_START_ZOOMING 465 557 */ 466 558 public function onStartZoom():Void … … 473 565 * Dispatches EVENT_STOP_ZOOMING when the map stops zooming. 474 566 * Callback arguments includes level:Number. 567 * 568 * @see com.modestmaps.Map#EVENT_STOP_ZOOMING 475 569 */ 476 570 public function onStopZoom():Void … … 483 577 * Dispatches EVENT_ZOOMED_BY when the map is zooomed. 484 578 * Callback arguments includes delta:Number, difference in levels from zoom start. 579 * 580 * @param Change in level since beginning of zoom. 581 * 582 * @see com.modestmaps.Map#EVENT_ZOOMED_BY 485 583 */ 486 584 public function onZoomed(delta:Number):Void … … 492 590 /** 493 591 * Dispatches EVENT_START_PANNING when the map starts to be panned. 592 * 593 * @see com.modestmaps.Map#EVENT_START_PANNING 494 594 */ 495 595 public function onStartPan():Void … … 501 601 /** 502 602 * Dispatches EVENT_STOP_PANNING when the map stops being panned. 603 * 604 * @see com.modestmaps.Map#EVENT_STOP_PANNING 503 605 */ 504 606 public function onStopPan():Void … … 511 613 * Dispatches EVENT_PANNED_BY when the map is panned. 512 614 * Callback arguments includes delta:Point, difference in pixels from pan start. 615 * 616 * @param Change in position since beginning of pan. 617 * 618 * @see com.modestmaps.Map#EVENT_PANNED_BY 513 619 */ 514 620 public function onPanned(delta:Point):Void … … 521 627 * Dispatches EVENT_RESIZED_TO when the map is resized. 522 628 * Callback arguments include width:Number and height:Number. 629 * 630 * @see com.modestmaps.Map#EVENT_RESIZED_TO 523 631 */ 524 632 public function onResized():Void
