Changeset 92

Show
Ignore:
Timestamp:
02/05/07 19:46:31 (2 years ago)
Author:
migurski
Message:

Marker set now segmented by tile coverage, with marker visibility report

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/as2/lib/com/modestmaps/core/Coordinate.as

    r67 r92  
    2020    { 
    2121        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); 
    2230    } 
    2331     
  • trunk/as2/lib/com/modestmaps/core/MarkerSet.as

    r91 r92  
    22import com.stamen.twisted.*; 
    33 
     4import com.modestmaps.core.Tile; 
    45import com.modestmaps.core.Marker; 
    56import com.modestmaps.core.TileGrid; 
     
    89class com.modestmaps.core.MarkerSet 
    910{ 
    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() 
    1125    private var grid:TileGrid; 
    1226 
    1327    function MarkerSet(grid:TileGrid) 
    1428    { 
     29        lastZoom = 0; 
     30 
     31        markers = {}; 
     32        tileMarkers = {}; 
     33        /*markerTiles = {};*/ 
     34 
    1535        this.grid = grid; 
    16         set = {}; 
    1736    } 
    1837     
    1938    public function put(name:String, marker:Marker):Void 
    2039    { 
    21         set[name] = marker; 
     40        markers[name] = marker; 
     41        indexMarker(name); 
    2242    } 
    2343     
    24     public function remove(name:String):Void 
     44    public function indexAtZoom(level:Number):Void 
    2545    { 
    26         delete set[name]; 
     46        lastZoom = level; 
     47     
     48        for(var markerName:String in markers) 
     49            indexMarker(markerName); 
    2750    } 
    2851 
    29     private function inBounds(topLeft:Coordinate, bottomRight:Coordinate):/*Marker*/Array 
     52    private function indexMarker(markerName:String):Void 
    3053    { 
    31         var coord:Coordinate; 
    32         var contained:/*Marker*/Array = []; 
     54        var tileKey:String = markers[markerName].coord.zoomTo(lastZoom).container().toString(); 
    3355         
    34         for(var name:String in set) { 
    35             coord = set[name].coord.zoomTo(topLeft.zoom)
     56        if(tileMarkers[tileKey] == undefined) 
     57            tileMarkers[tileKey] = {}
    3658             
    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; 
    4060         
    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); 
    4269    } 
    43  
    44     public function updateActive(topLeft:Coordinate, bottomRight:Coordinate):Void 
     70     
     71    public function overlapping(tiles:/*Tile*/Array):/*Marker*/Array 
    4572    { 
    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; 
    5285    } 
    5386} 
  • trunk/as2/lib/com/modestmaps/core/Tile.as

    r87 r92  
    132132 
    133133    public function toString():String 
     134    { 
     135        return id(); 
     136    } 
     137 
     138    public function id():String 
    134139    { 
    135140        return 'Tile' + coord.toString(); 
  • trunk/as2/lib/com/modestmaps/core/TileGrid.as

    r91 r92  
    124124 
    125125        allocateTiles(); 
    126         positionTiles(); 
    127126    } 
    128127     
     
    135134         
    136135        // impose some limits 
    137         zoomLevel = 11
     136        zoomLevel = initTileCoord.zoom
    138137        topLeftOutLimit = mapProvider.outerLimits()[0]; 
    139138        bottomRightInLimit = mapProvider.outerLimits()[1]; 
     
    163162         
    164163        allocateTiles(); 
    165         positionTiles(); 
    166164         
    167165        labelContainer.swapDepths( getNextHighestDepth() );     
    168166 
    169         // this starts a recurring process 
    170         updateMarkerBounds(); 
     167        // let 'em know we're coming 
     168        markers.indexAtZoom(zoomLevel); 
    171169    } 
    172170     
     
    175173        log('Marker '+name+': '+coord.toString()); 
    176174        markers.put(name, new Marker(coord)); 
    177     } 
    178      
    179     public function deleteMarker(name:String):Void 
    180     { 
    181         markers.remove(name); 
    182     } 
    183      
    184     private function updateMarkerBounds():Void 
    185     { 
    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)); 
    195175    } 
    196176     
     
    283263    private function onWellDrag():Void 
    284264    { 
    285         positionTiles(); 
     265        if(positionTiles()) 
     266            updateMarkers(); 
     267 
    286268        wellDragTask = Reactor.callNextFrame(Delegate.create(this, this.onWellDrag)); 
    287269    } 
     
    458440        wellDragTask.cancel(); 
    459441        well.stopDrag(); 
    460         positionTiles(); 
     442 
     443        if(positionTiles()) 
     444            updateMarkers(); 
     445 
    461446        centerWell(true); 
    462447    } 
     
    479464            normalizeWell(); 
    480465            allocateTiles(); 
    481             positionTiles(); 
    482              
    483466            log('New well scale: '+well._xscale.toString()); 
    484467        } 
     
    497480        centerWell(false); 
    498481        allocateTiles(); 
    499         positionTiles(); 
    500482    } 
    501483     
     
    506488         
    507489        well._x -= pixels; 
    508         positionTiles(); 
     490 
     491        if(positionTiles()) 
     492            updateMarkers(); 
     493 
    509494        centerWell(true); 
    510495    } 
     
    516501         
    517502        well._x += pixels; 
    518         positionTiles(); 
     503 
     504        if(positionTiles()) 
     505            updateMarkers(); 
     506 
    519507        centerWell(true); 
    520508    }  
     
    526514         
    527515        well._y += pixels; 
    528         positionTiles(); 
     516 
     517        if(positionTiles()) 
     518            updateMarkers(); 
     519 
    529520        centerWell(true); 
    530521    }       
     
    536527         
    537528        well._y -= pixels; 
    538         positionTiles(); 
     529 
     530        if(positionTiles()) 
     531            updateMarkers(); 
     532 
    539533        centerWell(true); 
    540534    } 
     
    568562   /** 
    569563    * 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. 
    571565    */ 
    572566    private function allocateTiles():Void 
     
    607601            } 
    608602        } 
     603 
     604        if(positionTiles()) 
     605            updateMarkers(); 
    609606    } 
    610607     
     
    702699         
    703700            log('Scaled to '+zoomLevel+', '+well._xscale+'%'); 
     701            markers.indexAtZoom(zoomLevel); 
    704702        } 
    705703    } 
     
    820818    * Determine if any tiles have wandered too far to the right, left, 
    821819    * 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 
    824823    { 
    825824        if(!tiles) 
    826             return
     825            return false
    827826         
    828827        var tile:Tile; 
    829828        var point:Point; 
    830829        var active:/*Tile*/Array = activeTiles(); 
     830         
     831        // if any tile is moved... 
     832        var touched:Boolean = false; 
    831833         
    832834        point = new Point(0, 0); 
     
    856858                tile.panDown(rows); 
    857859                tile._y += rows * tileHeight; 
     860                touched = true; 
    858861 
    859862            } else if(tile._y > yMax) { 
     
    863866                    tile.panUp(rows); 
    864867                    tile._y -= rows * tileHeight; 
     868                    touched = true; 
    865869                } 
    866870            } 
     
    870874                tile.panRight(columns); 
    871875                tile._x += columns * tileWidth; 
     876                touched = true; 
    872877 
    873878            } else if(tile._x > xMax) { 
     
    877882                    tile.panLeft(columns); 
    878883                    tile._x -= columns * tileWidth; 
     884                    touched = true; 
    879885                } 
    880886            } 
    881887        } 
     888         
     889        return touched; 
     890    } 
     891     
     892    private function updateMarkers():Void 
     893    { 
     894        markers.overlapping(activeTiles()); 
    882895    } 
    883896