Changeset 670
- Timestamp:
- 09/06/08 18:35:00 (3 months ago)
- Files:
-
- trunk/as3/lib/com/modestmaps/core/MapExtent.as (modified) (2 diffs)
- trunk/as3/lib/com/modestmaps/core/MarkerClip.as (modified) (2 diffs)
- trunk/as3/lib/com/modestmaps/core/PolygonClip.as (modified) (2 diffs)
- trunk/as3/lib/com/modestmaps/core/PolygonMarker.as (modified) (3 diffs)
- trunk/as3/lib/com/modestmaps/extras/MapCopyright.as (modified) (1 diff)
- trunk/as3/lib/com/modestmaps/extras/VirtualEarthCopyright.as (modified) (1 diff)
- trunk/as3/lib/com/modestmaps/Map.as (modified) (6 diffs)
- trunk/as3/lib/com/modestmaps/TweenMap.as (modified) (4 diffs)
- trunk/as3/swc/bin/ModestMapsSWC.swc (modified) (previous)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
trunk/as3/lib/com/modestmaps/core/MapExtent.as
r647 r670 150 150 } 151 151 152 public static function fromLocations(locations:Array):MapExtent 153 { 154 var minLat:Number = Number.POSITIVE_INFINITY; 155 var minLon:Number = Number.POSITIVE_INFINITY; 156 var maxLat:Number = Number.NEGATIVE_INFINITY; 157 var maxLon:Number = Number.NEGATIVE_INFINITY; 158 for each (var location:Location in locations) 159 { 160 if (!location) continue; 161 minLat = Math.min(minLat, location.lat); 162 maxLat = Math.max(maxLat, location.lat); 163 minLon = Math.min(minLon, location.lon); 164 maxLon = Math.max(maxLon, location.lon); 165 } 166 return new MapExtent(maxLat, minLat, maxLon, minLon); 167 } 168 169 // TODO: decide which of fromLocationArray and fromLocations gets to stay! 170 public static function fromLocationArray(locations:Array):MapExtent 152 /** calculate the north/south/east/west extremes of the given array of locations */ 153 public static function fromLocations(locations:Array):MapExtent 171 154 { 172 155 if (!locations || locations.length == 0) return new MapExtent(); … … 174 157 var first:Location = locations[0] as Location; 175 158 var extent:MapExtent = new MapExtent(first.lat, first.lat, first.lon, first.lon); 176 for (var i:int = 1; i < locations.length; i++)159 for each (var location:Location in locations.slice(1)) 177 160 { 178 extent.enclose(locations[i]); 161 if (location) { 162 extent.enclose(location); 163 } 179 164 } 180 165 return extent; 181 166 } 182 167 168 public static function fromLocationProperties(objects:Array, locationProp:String='location'):MapExtent 169 { 170 return fromLocations(objects.map(function(obj:Object, ...rest):Location { return obj[locationProp] as Location })); 171 } 172 183 173 } 184 174 } trunk/as3/lib/com/modestmaps/core/MarkerClip.as
r647 r670 204 204 205 205 //var t:int = flash.utils.getTimer(); 206 var w:Number = map.getWidth() * 2;207 var h:Number = map.getHeight() * 2;208 206 var doSort:Boolean = false; 209 207 for each (marker in markers) 210 208 { 211 // TODO: note, hidden markers are not updated, so when 212 // revealing markers using visible=true, they may end up in the wrong spot ? 213 if (marker.visible) 214 { 215 updateClip(marker); 216 if (markerInBounds(marker, w, h)) 217 { 218 if (!contains(marker)) 219 { 220 addChild(marker); 221 doSort = true; 222 } 223 } 224 else if (contains(marker)) 225 { 226 removeChild(marker); 227 doSort = true; 228 } 229 } 209 doSort = updateClip(marker) || doSort; // wow! bad things did happen when this said doSort ||= updateClip(marker); 230 210 } 231 211 … … 266 246 } 267 247 268 public function updateClip(marker:DisplayObject):void 269 { 270 // this method previously used the location of the marker 271 // but map.locationPoint hands off to grid to grid.coordinatePoint 272 // in the end so we may as well cache the first step 273 var point:Point = map.grid.coordinatePoint(coordinates[marker], this); 274 marker.x = snapToPixels ? Math.round(point.x) : point.x; 275 marker.y = snapToPixels ? Math.round(point.y) : point.y; 248 /** returns true if the marker was added or removed from the stage, so that updateClips can sort the markers */ 249 public function updateClip(marker:DisplayObject):Boolean 250 { 251 if (marker.visible) 252 { 253 // this method previously used the location of the marker 254 // but map.locationPoint hands off to grid to grid.coordinatePoint 255 // in the end so we may as well cache the first step 256 var point:Point = map.grid.coordinatePoint(coordinates[marker], this); 257 marker.x = snapToPixels ? Math.round(point.x) : point.x; 258 marker.y = snapToPixels ? Math.round(point.y) : point.y; 259 260 var w:Number = map.getWidth() * 2; 261 var h:Number = map.getHeight() * 2; 262 263 if (markerInBounds(marker, w, h)) 264 { 265 if (!contains(marker)) 266 { 267 addChild(marker); 268 return true; 269 } 270 } 271 else if (contains(marker)) 272 { 273 removeChild(marker); 274 return true; 275 } 276 } 277 278 return false; 276 279 } 277 280 trunk/as3/lib/com/modestmaps/core/PolygonClip.as
r647 r670 11 11 { 12 12 super(map); 13 this.scaleZoom = true;13 //this.scaleZoom = true; 14 14 this.markerSortFunction = null 15 15 } … … 17 17 override protected function markerInBounds(marker:DisplayObject, w:Number, h:Number):Boolean 18 18 { 19 return true; 20 /* var rect:Rectangle = new Rectangle(-map.width/2, -map.height/2, map.width, map.height); 21 return rect.intersects(marker.getBounds(this)); */ 19 var rect:Rectangle = new Rectangle(-w, -h, w*2, h*2); 20 return rect.intersects(marker.getBounds(this)); 22 21 } 23 22 trunk/as3/lib/com/modestmaps/core/PolygonMarker.as
r647 r670 12 12 { 13 13 protected var map:Map; 14 protected var drawZoom:Number; 14 15 15 public var coordinates:Array = []; 16 public var locations:Array; 17 public var extent:MapExtent; 16 18 public var location:Location; 17 19 … … 25 27 public var fillAlpha:Number = 0.2; 26 28 27 public function PolygonMarker(map:Map, coordinates:Array)29 public function PolygonMarker(map:Map, locations:Array) 28 30 { 29 31 this.map = map; 30 32 this.mouseEnabled = false; 31 33 32 map.addEventListener(MapEvent.EXTENT_CHANGED, redraw); 34 map.addEventListener(MapEvent.EXTENT_CHANGED, rescale); 35 map.addEventListener(MapEvent.ZOOMED_BY, rescale); 33 36 map.addEventListener(MapEvent.STOP_ZOOMING, redraw); 34 37 35 this.coordinates = coordinates; 36 location = coordinates[0] as Location; 38 if (locations && locations.length > 0) { 39 this.locations = locations; 40 this.extent = MapExtent.fromLocations(locations); 41 this.location = locations[0] as Location; 42 } 43 } 44 45 public function rescale(event:Event=null):void 46 { 47 scaleX = scaleY = Math.pow(2, map.grid.zoomLevel - drawZoom); 37 48 } 38 49 39 50 public function redraw(event:Event=null):void 40 51 { 52 drawZoom = map.grid.zoomLevel; 53 scaleX = scaleY = 1; 54 41 55 var firstPoint:Point = map.locationPoint(location) 42 56 graphics.clear(); … … 51 65 } 52 66 graphics.moveTo(0, 0); 53 for each (var loc:Location in coordinates.slice(1)) {67 for each (var loc:Location in locations.slice(1)) { 54 68 var p:Point = map.locationPoint(loc); 55 69 graphics.lineTo(p.x-firstPoint.x, p.y-firstPoint.y); trunk/as3/lib/com/modestmaps/extras/MapCopyright.as
r647 r670 78 78 this.google.copyright('&t=h', cenLat, cenLon, maxLat-minLat, maxLon-minLon, zoom); 79 79 break; 80 81 // TODO: GOOGLE_TERRAIN 80 82 81 83 case 'YAHOO_ROAD': trunk/as3/lib/com/modestmaps/extras/VirtualEarthCopyright.as
r647 r670 20 20 public var offsetY:Number = 10; 21 21 22 public function VirtualEarthCopyright(map:Map, offsetX:Number=undefined, offsetY:Number=undefined) :void22 public function VirtualEarthCopyright(map:Map, offsetX:Number=undefined, offsetY:Number=undefined) 23 23 { 24 24 super(map); trunk/as3/lib/com/modestmaps/Map.as
r666 r670 220 220 { 221 221 if (!fitWidth) fitWidth = mapWidth; 222 if (!fit Width) fitWidth= mapHeight;222 if (!fitHeight) fitHeight = mapHeight; 223 223 224 224 var TL:Coordinate = mapProvider.locationCoordinate(locations[0]); … … 247 247 248 248 // multiplication factor between vertical span and map height 249 var vFactor:Number = (BR.row - TL.row) / (fit Width/ mapProvider.tileHeight);249 var vFactor:Number = (BR.row - TL.row) / (fitHeight / mapProvider.tileHeight); 250 250 251 251 // multiplication factor expressed as base-2 logarithm, for zoom difference … … 497 497 498 498 /** zoom in or out by zoomDelta, keeping the requested point in the same place */ 499 public function zoomByAbout(zoomDelta: int, targetPoint:Point=null, duration:Number=-1):void499 public function zoomByAbout(zoomDelta:Number, targetPoint:Point=null, duration:Number=-1):void 500 500 { 501 501 if (!targetPoint) targetPoint = new Point(mapWidth/2, mapHeight/2); … … 649 649 } 650 650 651 public function removeAllMa kers():void {651 public function removeAllMarkers():void { 652 652 markerClip.removeAllMarkers() 653 653 } … … 693 693 public function onDoubleClick(event:MouseEvent):void 694 694 { 695 if (!__draggable) return; 696 695 697 var p:Point = grid.globalToLocal(new Point(event.stageX, event.stageY)); 696 698 if (event.shiftKey) { … … 713 715 } 714 716 } 715 } 717 } 716 718 717 719 } trunk/as3/lib/com/modestmaps/TweenMap.as
r647 r670 16 16 import com.modestmaps.mapproviders.IMapProvider; 17 17 18 import flash.events.MouseEvent; 18 19 import flash.geom.Matrix; 19 20 import flash.geom.Point; 21 import flash.utils.clearTimeout; 22 import flash.utils.setTimeout; 20 23 21 24 import gs.TweenLite; … … 36 39 /** time to pan and zoom using, uh, panAndZoom */ 37 40 public var panAndZoomDuration:Number = 0.3; 41 42 protected var mouseWheelingIn:Boolean = false; 43 protected var mouseWheelingOut:Boolean = false; 38 44 39 45 /* … … 98 104 99 105 /** zoom in or out by zoomDelta, keeping the requested point in the same place */ 100 override public function zoomByAbout(zoomDelta: int, targetPoint:Point=null, duration:Number=-1):void106 override public function zoomByAbout(zoomDelta:Number, targetPoint:Point=null, duration:Number=-1):void 101 107 { 102 108 if (duration < 0) duration = panAndZoomDuration; 103 109 if (!targetPoint) targetPoint = new Point(mapWidth/2, mapHeight/2); 104 110 105 if (grid.zoomLevel + zoomDelta < grid.minZoom) { 106 zoomDelta = grid.minZoom - grid.zoomLevel; 107 } 108 else if (grid.zoomLevel + zoomDelta > grid.maxZoom) { 109 zoomDelta = grid.maxZoom - grid.zoomLevel; 111 var constrainedDelta:Number = zoomDelta; 112 113 if (grid.zoomLevel + constrainedDelta < grid.minZoom) { 114 constrainedDelta = grid.minZoom - grid.zoomLevel; 115 } 116 else if (grid.zoomLevel + constrainedDelta > grid.maxZoom) { 117 constrainedDelta = grid.maxZoom - grid.zoomLevel; 110 118 } 111 119 112 120 // round the zoom delta up or down so that we end up at a power of 2 113 var preciseZoomDelta:Number = zoomDelta + (Math.round(grid.zoomLevel) - grid.zoomLevel) 121 var preciseZoomDelta:Number; 122 123 if (mouseWheelingIn || mouseWheelingOut) { 124 preciseZoomDelta = constrainedDelta; 125 } 126 else { 127 preciseZoomDelta = constrainedDelta + (Math.round(grid.zoomLevel) - grid.zoomLevel); 128 } 114 129 115 130 var sc:Number = Math.pow(2, preciseZoomDelta); … … 224 239 } 225 240 241 protected var wheeltimer:uint; 242 243 /** zooms in or out of mouse-wheeled location */ 244 public function onMouseWheel(event:MouseEvent):void 245 { 246 if (!__draggable) return; 247 248 var p:Point = grid.globalToLocal(new Point(event.stageX, event.stageY)); 249 if (event.delta < 0) { 250 if (grid.zoomLevel > grid.minZoom) { 251 mouseWheelingOut = true; 252 mouseWheelingIn = false; 253 zoomByAbout(Math.min(-1,event.delta/20.0), p, 0.0); 254 } 255 else { 256 panBy(mapWidth/2 - p.x, mapHeight/2 - p.y); 257 } 258 } 259 else if (event.delta > 0) { 260 if (grid.zoomLevel < grid.maxZoom) { 261 mouseWheelingIn = true; 262 mouseWheelingOut = false; 263 zoomByAbout(Math.max(1,event.delta/20.0), p, 0.0); 264 } 265 else { 266 panBy(mapWidth/2 - p.x, mapHeight/2 - p.y); 267 } 268 } 269 270 if (wheeltimer) { 271 clearTimeout(wheeltimer); 272 } 273 274 if (mouseWheelingIn || mouseWheelingOut) { 275 wheeltimer = setTimeout(doneMouseWheeling, 100); 276 } 277 } 278 279 protected function doneMouseWheeling():void 280 { 281 if (mouseWheelingIn) { 282 zoomByAbout(Math.ceil(grid.zoomLevel) - grid.zoomLevel, new Point(grid.mouseX, grid.mouseY), 0.05); // round off to whole value up 283 } 284 else if (mouseWheelingOut) { 285 zoomByAbout(Math.floor(grid.zoomLevel) - grid.zoomLevel, new Point(grid.mouseX, grid.mouseY), 0.05); // round off to whole value down 286 } 287 mouseWheelingOut = false; 288 mouseWheelingIn = false; 289 } 290 226 291 } 227 292 }
