Changeset 346

Show
Ignore:
Timestamp:
08/15/07 23:05:24 (1 year ago)
Author:
tom
Message:

MarkerClip? no longer uses TileGrid's indexing and event passing and does bounds checking instead

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/as3/lib/com/modestmaps/core/MarkerClip.as

    r340 r346  
    1717        import flash.display.DisplayObject; 
    1818        import flash.utils.getTimer; 
     19        import flash.geom.Rectangle; 
    1920         
    2021        /** This is different from the as2 version for now, because 
     
    5657            public function attachMarker(marker:DisplayObject, location:Location):void 
    5758            { 
    58                 map.grid.putMarker(marker.name, map.getMapProvider().locationCoordinate(location), location); 
     59                //map.grid.putMarker(marker.name, map.getMapProvider().locationCoordinate(location), location); 
    5960                 
    6061                locations[marker] = location; 
     
    6364                 
    6465                var point:Point = map.locationPoint(location, this); 
    65                 marker.x = point.x; 
    66                 marker.y = point.y; 
    67                  
    68                 // TODO: check if it should be added now? 
    69                 addChild(marker); 
     66                marker.x = Math.round(point.x); 
     67                marker.y = Math.round(point.y); 
     68                 
     69                var w:Number = map.getWidth() * 2; 
     70                var h:Number = map.getHeight() * 2; 
     71                if (marker.x > -w/2 && marker.x < w/2 && marker.y > -h/2 && marker.y < h/2) { 
     72                addChild(marker); 
     73            } 
    7074            } 
    7175             
     
    7781            public function removeMarker(id:String):void 
    7882            { 
    79                 map.grid.removeMarker(id); 
     83                //map.grid.removeMarker(id); 
    8084                var marker:DisplayObject = getMarker(id); 
    8185                if (marker) { 
     
    9397            { 
    9498                //var t:int = flash.utils.getTimer(); 
     99                var w:Number = map.getWidth() * 2; 
     100                var h:Number = map.getHeight() * 2; 
    95101                for each (var marker:DisplayObject in markers) { 
    96                         updateClip(marker); 
     102                    if (marker.visible) { 
     103                        updateClip(marker); 
     104                        if (marker.x > -w/2 && marker.x < w/2 && marker.y > -h/2 && marker.y < h/2) { 
     105                            if (!contains(marker)) { 
     106                                addChild(marker); 
     107                            } 
     108                        } 
     109                        else if (contains(marker)) { 
     110                            removeChild(marker); 
     111                        } 
     112                    } 
    97113                } 
    98114                //trace("reprojected all markers in " + (flash.utils.getTimer() - t) + "ms"); 
    99115            } 
    100116             
    101             private function updateClip(marker:DisplayObject):void 
     117            public function updateClip(marker:DisplayObject):void 
    102118            { 
    103119                var location:Location = locations[marker]; 
     
    140156            public function onMapPanned(event:MapEvent):void 
    141157            { 
    142                 x = starting.x + event.panDelta.x; 
    143                 y = starting.y + event.panDelta.y; 
     158                if (starting) { 
     159                    x = starting.x + event.panDelta.x; 
     160                    y = starting.y + event.panDelta.y; 
     161                } 
     162                else { 
     163                    x = event.panDelta.x; 
     164                    y = event.panDelta.y;                    
     165                } 
    144166            } 
    145167