Changeset 92
- Timestamp:
- 02/05/07 19:46:31 (2 years ago)
- Files:
-
- trunk/as2/lib/com/modestmaps/core/Coordinate.as (modified) (1 diff)
- trunk/as2/lib/com/modestmaps/core/MarkerSet.as (modified) (2 diffs)
- trunk/as2/lib/com/modestmaps/core/Tile.as (modified) (1 diff)
- trunk/as2/lib/com/modestmaps/core/TileGrid.as (modified) (20 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
trunk/as2/lib/com/modestmaps/core/Coordinate.as
r67 r92 20 20 { 21 21 return new Coordinate(row, column, zoom); 22 } 23 24 /** 25 * Return a new coordinate that corresponds to that of the tile containing this one 26 */ 27 public function container():Coordinate 28 { 29 return new Coordinate(Math.floor(row), Math.floor(column), zoom); 22 30 } 23 31 trunk/as2/lib/com/modestmaps/core/MarkerSet.as
r91 r92 2 2 import com.stamen.twisted.*; 3 3 4 import com.modestmaps.core.Tile; 4 5 import com.modestmaps.core.Marker; 5 6 import com.modestmaps.core.TileGrid; … … 8 9 class com.modestmaps.core.MarkerSet 9 10 { 10 private var set:Object; 11 private var lastZoom:Number; 12 13 // markers hashed by name 14 private var markers:Object; 15 16 // marker lists hashed by containing tile id 17 private var tileMarkers:Object; 18 19 /* 20 // tile id's hashed by marker name 21 private var markerTiles:Object; 22 */ 23 24 // for use of TileGrid.log() 11 25 private var grid:TileGrid; 12 26 13 27 function MarkerSet(grid:TileGrid) 14 28 { 29 lastZoom = 0; 30 31 markers = {}; 32 tileMarkers = {}; 33 /*markerTiles = {};*/ 34 15 35 this.grid = grid; 16 set = {};17 36 } 18 37 19 38 public function put(name:String, marker:Marker):Void 20 39 { 21 set[name] = marker; 40 markers[name] = marker; 41 indexMarker(name); 22 42 } 23 43 24 public function remove(name:String):Void44 public function indexAtZoom(level:Number):Void 25 45 { 26 delete set[name]; 46 lastZoom = level; 47 48 for(var markerName:String in markers) 49 indexMarker(markerName); 27 50 } 28 51 29 private function in Bounds(topLeft:Coordinate, bottomRight:Coordinate):/*Marker*/Array52 private function indexMarker(markerName:String):Void 30 53 { 31 var coord:Coordinate; 32 var contained:/*Marker*/Array = []; 54 var tileKey:String = markers[markerName].coord.zoomTo(lastZoom).container().toString(); 33 55 34 for(var name:String in set) {35 coord = set[name].coord.zoomTo(topLeft.zoom);56 if(tileMarkers[tileKey] == undefined) 57 tileMarkers[tileKey] = {}; 36 58 37 if(coord.row >= topLeft.row && coord.column >= topLeft.column && coord.row <= bottomRight.row && coord.column <= bottomRight.column) 38 contained.push(set[name]); 39 } 59 tileMarkers[tileKey][markerName] = true; 40 60 41 return contained; 61 /* 62 if(markerTiles[markerName] == undefined) 63 markerTiles[markerName] = {}; 64 65 markerTiles[markerName][tileKey] = true; 66 */ 67 68 grid.log('Marker '+markerName+' in '+tileKey); 42 69 } 43 44 public function updateActive(topLeft:Coordinate, bottomRight:Coordinate):Void70 71 public function overlapping(tiles:/*Tile*/Array):/*Marker*/Array 45 72 { 46 grid.log('Active markers: '+inBounds(topLeft, bottomRight).length); 47 } 48 49 public function updateVisible(topLeft:Coordinate, bottomRight:Coordinate):Void 50 { 51 grid.log('Visible markers: '+inBounds(topLeft, bottomRight).length); 73 var names:Array = []; 74 var touched:/*Marker*/Array = []; 75 76 for(var i:Number = 0; i < tiles.length; i += 1) 77 if(tileMarkers[tiles[i].coord.toString()] != undefined) 78 for(var markerName:String in tileMarkers[tiles[i].coord.toString()]) { 79 names.push(markerName); 80 touched.push(markers[markerName]); 81 } 82 83 grid.log('Touched markers: '+names.toString()); 84 return touched; 52 85 } 53 86 } trunk/as2/lib/com/modestmaps/core/Tile.as
r87 r92 132 132 133 133 public function toString():String 134 { 135 return id(); 136 } 137 138 public function id():String 134 139 { 135 140 return 'Tile' + coord.toString(); trunk/as2/lib/com/modestmaps/core/TileGrid.as
r91 r92 124 124 125 125 allocateTiles(); 126 positionTiles();127 126 } 128 127 … … 135 134 136 135 // impose some limits 137 zoomLevel = 11;136 zoomLevel = initTileCoord.zoom; 138 137 topLeftOutLimit = mapProvider.outerLimits()[0]; 139 138 bottomRightInLimit = mapProvider.outerLimits()[1]; … … 163 162 164 163 allocateTiles(); 165 positionTiles();166 164 167 165 labelContainer.swapDepths( getNextHighestDepth() ); 168 166 169 // this starts a recurring process170 updateMarkerBounds();167 // let 'em know we're coming 168 markers.indexAtZoom(zoomLevel); 171 169 } 172 170 … … 175 173 log('Marker '+name+': '+coord.toString()); 176 174 markers.put(name, new Marker(coord)); 177 }178 179 public function deleteMarker(name:String):Void180 {181 markers.remove(name);182 }183 184 private function updateMarkerBounds():Void185 {186 if(tiles) {187 var farTopLeft:Coordinate = pointCoordinate(new Point(-tileWidth, -tileHeight));188 var farBottomRight:Coordinate = pointCoordinate(new Point(width + tileWidth, height + tileHeight));189 190 markers.updateActive(farTopLeft, farBottomRight);191 markers.updateVisible(topLeftCoordinate(), bottomRightCoordinate());192 }193 194 Reactor.callLater(4000, Delegate.create(this, this.updateMarkerBounds));195 175 } 196 176 … … 283 263 private function onWellDrag():Void 284 264 { 285 positionTiles(); 265 if(positionTiles()) 266 updateMarkers(); 267 286 268 wellDragTask = Reactor.callNextFrame(Delegate.create(this, this.onWellDrag)); 287 269 } … … 458 440 wellDragTask.cancel(); 459 441 well.stopDrag(); 460 positionTiles(); 442 443 if(positionTiles()) 444 updateMarkers(); 445 461 446 centerWell(true); 462 447 } … … 479 464 normalizeWell(); 480 465 allocateTiles(); 481 positionTiles();482 483 466 log('New well scale: '+well._xscale.toString()); 484 467 } … … 497 480 centerWell(false); 498 481 allocateTiles(); 499 positionTiles();500 482 } 501 483 … … 506 488 507 489 well._x -= pixels; 508 positionTiles(); 490 491 if(positionTiles()) 492 updateMarkers(); 493 509 494 centerWell(true); 510 495 } … … 516 501 517 502 well._x += pixels; 518 positionTiles(); 503 504 if(positionTiles()) 505 updateMarkers(); 506 519 507 centerWell(true); 520 508 } … … 526 514 527 515 well._y += pixels; 528 positionTiles(); 516 517 if(positionTiles()) 518 updateMarkers(); 519 529 520 centerWell(true); 530 521 } … … 536 527 537 528 well._y -= pixels; 538 positionTiles(); 529 530 if(positionTiles()) 531 updateMarkers(); 532 539 533 centerWell(true); 540 534 } … … 568 562 /** 569 563 * Determine the number of tiles needed to cover the current grid, 570 * and add rows and columns if necessary. 564 * and add rows and columns if necessary. Finally, position new tiles. 571 565 */ 572 566 private function allocateTiles():Void … … 607 601 } 608 602 } 603 604 if(positionTiles()) 605 updateMarkers(); 609 606 } 610 607 … … 702 699 703 700 log('Scaled to '+zoomLevel+', '+well._xscale+'%'); 701 markers.indexAtZoom(zoomLevel); 704 702 } 705 703 } … … 820 818 * Determine if any tiles have wandered too far to the right, left, 821 819 * top, or bottom, and shunt them to the opposite side if needed. 822 */ 823 private function positionTiles():Void 820 * Return true if any tiles have been repositioned. 821 */ 822 private function positionTiles():Boolean 824 823 { 825 824 if(!tiles) 826 return ;825 return false; 827 826 828 827 var tile:Tile; 829 828 var point:Point; 830 829 var active:/*Tile*/Array = activeTiles(); 830 831 // if any tile is moved... 832 var touched:Boolean = false; 831 833 832 834 point = new Point(0, 0); … … 856 858 tile.panDown(rows); 857 859 tile._y += rows * tileHeight; 860 touched = true; 858 861 859 862 } else if(tile._y > yMax) { … … 863 866 tile.panUp(rows); 864 867 tile._y -= rows * tileHeight; 868 touched = true; 865 869 } 866 870 } … … 870 874 tile.panRight(columns); 871 875 tile._x += columns * tileWidth; 876 touched = true; 872 877 873 878 } else if(tile._x > xMax) { … … 877 882 tile.panLeft(columns); 878 883 tile._x -= columns * tileWidth; 884 touched = true; 879 885 } 880 886 } 881 887 } 888 889 return touched; 890 } 891 892 private function updateMarkers():Void 893 { 894 markers.overlapping(activeTiles()); 882 895 } 883 896
