Changeset 337
- Timestamp:
- 08/11/07 20:50:59 (1 year ago)
- Files:
-
- trunk/as3/lib/com/modestmaps/core/MarkerClip.as (modified) (6 diffs)
- trunk/as3/lib/com/modestmaps/core/TileGrid.as (modified) (23 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
trunk/as3/lib/com/modestmaps/core/MarkerClip.as
r335 r337 16 16 import flash.utils.Dictionary; 17 17 import flash.display.DisplayObject; 18 import flash.utils.getTimer; 18 19 19 20 /** This is different from the as2 version for now, because … … 24 25 public class MarkerClip extends Sprite 25 26 { 26 // TODO: mask me !27 // TODO: mask me? 27 28 private var map:Map; 28 29 private var starting:Point; 29 30 private var locations:Dictionary = new Dictionary(); 30 private var markers:Array = []; 31 private var markers:Array = []; // all markers 31 32 private var markersByName:Object = {}; 32 33 … … 74 75 } 75 76 delete locations[marker]; 77 delete markersByName[marker.name]; 76 78 } 77 79 78 80 private function updateClips(event:Event=null):void 79 81 { 82 var t:int = flash.utils.getTimer(); 80 83 for each (var marker:DisplayObject in markers) { 81 84 updateClip(marker); 82 85 } 86 trace("reprojected all markers in " + (flash.utils.getTimer() - t) + "ms"); 83 87 } 84 88 … … 86 90 { 87 91 var location:Location = locations[marker]; 88 var point:Point = map.locationPoint(location, this);92 var point:Point = map.locationPoint(location, this); 89 93 marker.x = point.x; 90 94 marker.y = point.y; … … 94 98 { 95 99 if (!getChildByName(event.marker)) { 96 addChild(getMarker(event.marker)); 100 var marker:DisplayObject = getMarker(event.marker); 101 addChild(marker); 97 102 } 98 103 } … … 101 106 { 102 107 if (getChildByName(event.marker)) { 103 removeChild(getMarker(event.marker)); 108 var marker:DisplayObject = getMarker(event.marker); 109 removeChild(marker); 104 110 } 105 111 } trunk/as3/lib/com/modestmaps/core/TileGrid.as
r336 r337 78 78 protected var _mapProvider:IMapProvider; 79 79 80 protected var _drawWell:Boolean = true;81 protected var _drawGridArea:Boolean = true;80 protected var _drawWell:Boolean = true; 81 protected var _drawGridArea:Boolean = true; 82 82 83 83 public function init(width:Number, height:Number, draggable:Boolean, provider:IMapProvider, map:Map):void … … 111 111 _initTileCoord = coord; 112 112 _initTilePoint = point; 113 // Reactor.callNextFrame(initializeTiles);114 113 } 115 114 … … 119 118 public function resetTiles(coord:Coordinate, point:Point):void 120 119 { 121 //trace('resetting tiles...');122 120 if (!_tiles) 123 121 { 124 //trace("no _tiles for resetTiles() yet");125 122 setInitialTile(coord, point); 126 123 return; 127 124 } 128 125 129 //trace('REALLY resetting tiles...'); 126 try { 127 var initTile:Tile; 128 var condemnedTiles:/*Tile*/Array = activeTiles(); 129 130 for (var i:int = 0; i < condemnedTiles.length; i++) 131 { 132 condemnedTiles[i].expire(); 133 } 134 135 Reactor.callLater(condemnationDelay(), destroyTiles, condemnedTiles); 130 136 131 try { 132 var initTile:Tile; 133 var condemnedTiles:/*Tile*/Array = activeTiles(); 134 135 for (var i:int = 0; i < condemnedTiles.length; i++) 136 { 137 condemnedTiles[i].expire(); 138 } 139 140 Reactor.callLater(condemnationDelay(), destroyTiles, condemnedTiles); 141 142 zoomLevel = coord.zoom; 143 initTile = createTile(this, coord, point.x, point.y); 144 145 centerWell(true); 146 147 _rows = 1; 148 _columns = 1; 149 150 allocateTiles(); 151 } 152 catch(e:Error) { 153 trace(e.getStackTrace()); 154 } 137 zoomLevel = coord.zoom; 138 initTile = createTile(this, coord, point.x, point.y); 139 140 centerWell(true); 141 142 _rows = 1; 143 _columns = 1; 144 145 allocateTiles(); 146 } 147 catch(e:Error) { 148 trace(e.getStackTrace()); 149 } 155 150 156 151 } … … 163 158 var initTile:Tile; 164 159 165 // trace('initializing...'); 166 167 if (!_initTileCoord) { 168 trace("no _initTileCoord"); 169 return; 170 } 160 if (!_initTileCoord) { 161 trace("no _initTileCoord"); 162 return; 163 } 171 164 172 165 // impose some limits … … 175 168 bottomRightInLimit = _mapProvider.outerLimits()[1]; 176 169 177 //trace('REALLY initializing, like _tiles and shit...'); 178 179 _tiles = []; 170 _tiles = []; 180 171 initTile = createTile(this, _initTileCoord, _initTilePoint.x, _initTilePoint.y); 181 172 … … 199 190 { 200 191 var marker:Marker = new Marker(id, coord, location); 201 //trace('Marker '+id+': '+coord.toString());202 192 markers.put(marker); 203 193 … … 221 211 _well.name = 'well'; 222 212 223 if (_draggable)224 {225 _well.mouseChildren = false;226 _well.addEventListener(MouseEvent.MOUSE_DOWN, startWellDrag);227 _well.addEventListener(MouseEvent.MOUSE_UP, stopWellDrag);228 }213 if (_draggable) 214 { 215 _well.mouseChildren = false; 216 _well.addEventListener(MouseEvent.MOUSE_DOWN, startWellDrag); 217 _well.addEventListener(MouseEvent.MOUSE_UP, stopWellDrag); 218 } 229 219 230 220 addChild(_well); … … 240 230 _mask.name = 'mask'; 241 231 // as3 masks need to be child, so add the mask to the grid not the well 242 // because well children are all tiles243 addChild(_mask);232 // because well children are all tiles 233 addChild(_mask); 244 234 this.mask = _mask; 245 235 } … … 260 250 261 251 if (_mapProvider.geometry() != previousGeometry) 262 {252 { 263 253 markers.initializeIndex(); 264 254 markers.indexAtZoom(zoomLevel); … … 288 278 protected function destroyTile(tile:Tile):void 289 279 { 290 //trace('Destroying tile: '+tile.toString());291 280 _tiles.splice(tileIndex(tile), 1); 292 281 tile.cancelDraw(); … … 300 289 { 301 290 if (tiles.length) 302 {291 { 303 292 destroyTile(Tile(tiles.shift())); 304 293 Reactor.callLater(0, destroyTiles, tiles); … … 448 437 max.x = _well.x - max.x; 449 438 max.y = _well.y - max.y; 450 451 //trace('min/max for drag: '+min+', '+max+' ('+topLeftOutLimit+', '+bottomRightInLimit+')'); 452 439 453 440 // weird negative edge conditions, limit all movement on an axis 454 441 if(min.x > max.x) … … 467 454 public function startWellDrag(event:MouseEvent):void 468 455 { 469 stage.addEventListener(MouseEvent.MOUSE_UP, stopWellDrag);470 stage.addEventListener( MouseEvent.MOUSE_OUT, stopWellDrag);456 stage.addEventListener(MouseEvent.MOUSE_UP, stopWellDrag); 457 stage.addEventListener(Event.MOUSE_LEAVE, stopWellDrag); 471 458 472 459 var bounds:Bounds = getWellBounds(true); … … 499 486 : bounds.max.y); 500 487 501 //trace('Drag bounds would be: '+xMin+', '+yMin+', '+xMax+', '+yMax); 502 503 _startingWellPosition = new Point(_well.x, _well.y); 504 //trace('Starting well position: '+_startingWellPosition.toString()); 488 _startingWellPosition = new Point(_well.x, _well.y); 505 489 506 490 _map.onStartPan(); … … 514 498 * Halts _wellDragTask. 515 499 */ 516 public function stopWellDrag(event:MouseEvent):void 517 { 518 stage.removeEventListener(MouseEvent.MOUSE_OUT, stopWellDrag); 500 public function stopWellDrag(event:Event):void 501 { 502 stage.removeEventListener(MouseEvent.MOUSE_UP, stopWellDrag); 503 stage.removeEventListener(Event.MOUSE_LEAVE, stopWellDrag); 519 504 505 if (_wellDragTask) { 506 _wellDragTask.call(); // issue final onPan, notify markers, etc. 507 _wellDragTask.cancel(); // but cancel the follow-on call 508 } 520 509 _map.onStopPan(); 521 if (_wellDragTask) {522 _wellDragTask.call(); // issue final onPan, notify markers, etc.523 _wellDragTask.cancel(); // but cancel the follow-on call524 }525 510 _well.stopDrag(); 526 511 … … 628 613 var matches:Array = new Array(); 629 614 if (_tiles) { 630 matches = _tiles.filter(function(item:Tile, index:int, list:Array):Boolean { return item.isActive();} );631 if (matches.length == 0) {632 trace("no matches for active tiles... DOOM!");633 }634 }615 matches = _tiles.filter(function(item:Tile, index:int, list:Array):Boolean { return item.isActive();} ); 616 if (matches.length == 0) { 617 trace("no matches for active tiles... DOOM!"); 618 } 619 } 635 620 return matches; 636 621 } … … 774 759 //trace('This is where we scale the whole well by '+zoomAdjust+' zoom levels: '+(100 / scaleAdjust)+'%'); 775 760 776 var n:int;761 var n:int; 777 762 for (n = 0; n < zoomAdjust; n += 1) 778 {763 { 779 764 splitTiles(); 780 765 zoomLevel += 1; … … 782 767 783 768 for (n = 0; n > zoomAdjust; n -= 1) 784 {769 { 785 770 mergeTiles(); 786 771 zoomLevel -= 1; … … 839 824 // this should never happen 840 825 if(!referenceTile) { 841 trace("TileGrid problem - no reference tile");826 trace("TileGrid problem - no reference tile"); 842 827 return; 843 828 } … … 845 830 // this should never happen either 846 831 if(!referenceTile.coord) { 847 trace("TileGrid problem - no coord in reference tile");832 trace("TileGrid problem - no coord in reference tile"); 848 833 return; 849 834 } … … 907 892 // this should never happen 908 893 if(!referenceTile) { 909 throw new Error("no reference tile in mergeTiles()");894 throw new Error("no reference tile in mergeTiles()"); 910 895 } 911 896 912 897 // this should never happen either 913 898 if(!referenceTile.coord) { 914 throw new Error("no reference tile coord in mergeTiles()");899 throw new Error("no reference tile coord in mergeTiles()"); 915 900 } 916 901 … … 1103 1088 return function(a:Tile, b:Tile):Number 1104 1089 { 1105 // TODO: can probably nix the sqrt if we're just sorting by distance1106 // FYI: this whole method isn't really ever used, it can probably just go away entirely1090 // TODO: can probably nix the sqrt if we're just sorting by distance 1091 // FYI: this whole method isn't really ever used, it can probably just go away entirely 1107 1092 var aDist:Number = Math.sqrt(Math.pow(a.center().x - p.x, 2) + Math.pow(a.center().y - p.y, 2)); 1108 1093 var bDist:Number = Math.sqrt(Math.pow(b.center().x - p.x, 2) + Math.pow(b.center().y - p.y, 2)); … … 1160 1145 } 1161 1146 1162 // set to false, and set drawGridArea to false, if you want the background swf color to show through 1163 public function set drawWell(draw:Boolean):void { 1164 _drawWell = draw; 1147 /** 1148 * Set to false if you want the background swf color to show through 1149 * See TileGrid.drawGridArea too. 1150 */ 1151 public function set drawWell(draw:Boolean):void { 1152 _drawWell = draw; 1165 1153 redrawWell(); 1166 1154 } 1167 // set to false, and set drawWell to false, if you want the background swf color to show through 1168 public function set drawGridArea(draw:Boolean):void { 1155 1156 /** 1157 * Set to false if you want the background swf color to show through 1158 * See TileGrid.drawWell too. 1159 */ 1160 public function set drawGridArea(draw:Boolean):void { 1169 1161 _drawGridArea = draw; 1170 1162 redrawGridArea();
