Changeset 358
- Timestamp:
- 10/26/07 00:03:10 (1 year ago)
- Files:
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
trunk/as3/lib/com/modestmaps/extras/GreatCircleOverlay.as
r355 r358 21 21 { 22 22 super(map); 23 this.filters = [ new DropShadowFilter(2,90,0x000000,0.35,8,8,2,1,false,false,false) ];23 //this.filters = [ new DropShadowFilter(2,90,0x000000,0.35,8,8,2,1,false,false,false) ]; 24 24 } 25 25 … … 35 35 for each (var location:Location in line.slice(1)) { 36 36 var thickness:Number = Math.min(1,1-Math.abs(i-(line.length/2))/(line.length/3)) 37 if (i % 4 == 0 && i != line.length-1) {37 /* if (i % 4 == 0 && i != line.length-1) { 38 38 sprite.graphics.lineStyle(); 39 39 } 40 40 else { 41 41 lineStyle.apply(sprite.graphics, 1+thickness); 42 } 42 } */ 43 lineStyle.apply(sprite.graphics, 1+thickness); 43 44 p = map.locationPoint(location, sprite); 44 45 if (prev && (Math.abs(prev.lat-location.lat) > 10 || Math.abs(prev.lon-location.lon) > 10)) { … … 71 72 bearing = bearing < 0 ? 360 + bearing : bearing; 72 73 73 var numSegments:int = int( 10 + (200 * Distance.approxDistance(start,end) / (Math.PI * 2 * 6378000)));74 var numSegments:int = int(40 + (400 * Distance.approxDistance(start,end) / (Math.PI * 2 * 6378000))); 74 75 for (var n:int = 0 ; n < numSegments; n++ ) { 75 76 var f:Number = (1/(numSegments-1)) * n; trunk/as3/lib/com/modestmaps/extras/MapControls.as
r355 r358 1 1 package com.modestmaps.extras 2 2 { 3 import com.modestmaps.Map; 4 5 import flash.display.CapsStyle; 6 import flash.display.JointStyle; 3 7 import flash.display.Sprite; 4 8 import flash.events.Event; 5 import com.modestmaps.Map;6 9 import flash.events.KeyboardEvent; 7 import flash.ui.Keyboard;8 10 import flash.events.MouseEvent; 9 11 import flash.geom.ColorTransform; 12 import flash.ui.Keyboard; 10 13 11 14 public class MapControls extends Sprite … … 19 22 public var outButton:Sprite = new Sprite(); 20 23 24 public var fullScreenButton:FullScreenButton = new FullScreenButton(); 25 21 26 private var map:Map; 22 27 private var keyboard:Boolean; 23 24 public function MapControls(map:Map, keyboard:Boolean=true) 28 private var fullScreen:Boolean; 29 30 private var overTransform:ColorTransform = new ColorTransform(1,1,1); 31 private var outTransform:ColorTransform = new ColorTransform(1,1,0); 32 33 private var buttons:Array; 34 35 public function MapControls(map:Map, keyboard:Boolean=true, fullScreen:Boolean=false) 25 36 { 26 37 this.map = map; 27 38 this.keyboard = keyboard; 28 29 var buttons:Sprite = new Sprite(); 30 addChild(buttons); 31 32 var onButtonMouseOver:Function = function(event:MouseEvent):void { 33 var b:Sprite = (event.target as Sprite); 34 b.transform.colorTransform = new ColorTransform(); 35 b.scaleX = b.scaleY = 1.1; 36 }; 37 var onButtonMouseOut:Function = function (event:MouseEvent):void { 38 var b:Sprite = (event.target as Sprite); 39 b.transform.colorTransform = new ColorTransform(0.9,0.9,0.8); 40 b.scaleX = b.scaleY = 1.0; 41 }; 39 this.fullScreen = fullScreen; 40 41 var buttonSprite:Sprite = new Sprite(); 42 addChild(buttonSprite); 42 43 43 44 var actions:Array = [ map.panLeft, map.panRight, map.panUp, map.panDown, map.zoomIn, map.zoomOut ]; 44 45 for each (var button:Sprite in [leftButton, rightButton, upButton, downButton, inButton, outButton]) { 45 buttons = [leftButton, rightButton, upButton, downButton, inButton, outButton]; 46 47 if (fullScreen) { 48 buttons.push(fullScreenButton); 49 actions.push(fullScreenButton.toggleFullScreen); 50 } 51 52 for each (var button:Sprite in buttons) { 46 53 button.addEventListener(MouseEvent.CLICK, actions.shift()); 47 54 button.useHandCursor = true; … … 57 64 button.graphics.beginFill(0xdddddd); 58 65 button.graphics.drawRoundRect(-9, -9, 18, 18, 9, 9); 59 button.transform.colorTransform = new ColorTransform(0.9,0.9,0.8);66 button.transform.colorTransform = outTransform; 60 67 button.addEventListener(MouseEvent.MOUSE_OVER, onButtonMouseOver); 61 68 button.addEventListener(MouseEvent.MOUSE_OUT, onButtonMouseOut); 62 button s.addChild(button);69 buttonSprite.addChild(button); 63 70 } 64 71 … … 89 96 90 97 // draw plus... 91 inButton.graphics.lineStyle(2, 0x000000, 1.0, true); 98 inButton.graphics.lineStyle(2, 0x000000, 1.0, true); 92 99 inButton.graphics.moveTo(-3,0); 93 100 inButton.graphics.lineTo(3,0); … … 102 109 outButton.graphics.lineTo(3,0); 103 110 outButton.graphics.lineTo(-3,0); 104 111 105 112 addEventListener(Event.ADDED_TO_STAGE, onAddedToStage); 106 113 107 114 } 108 115 116 public function setButtonTransforms(overTransform:ColorTransform, outTransform:ColorTransform):void 117 { 118 this.overTransform = overTransform; 119 this.outTransform = outTransform; 120 121 for each (var button:Sprite in buttons) { 122 button.transform.colorTransform = outTransform; 123 } 124 } 125 109 126 private function onAddedToStage(event:Event):void 110 127 { 111 128 if (keyboard) stage.addEventListener(KeyboardEvent.KEY_UP, onStageKeyUp); 129 if (fullScreen) stage.addEventListener(FullScreenButton.FULL_SCREEN, onFullScreenEvent); 112 130 stage.addEventListener(Event.RESIZE, onStageResize); 113 131 onStageResize(null); 132 } 133 134 private function onButtonMouseOver(event:MouseEvent):void 135 { 136 var b:Sprite = (event.target as Sprite); 137 b.transform.colorTransform = overTransform; 138 b.scaleX = b.scaleY = 1.1; 139 } 140 private function onButtonMouseOut(event:MouseEvent):void 141 { 142 var b:Sprite = (event.target as Sprite); 143 b.transform.colorTransform = outTransform; 144 b.scaleX = b.scaleY = 1.0; 114 145 } 115 146 … … 160 191 outButton.y = 25; 161 192 inButton.y = 25; 162 } 193 194 fullScreenButton.x = w - 25; 195 fullScreenButton.y = 25; 196 } 197 198 public function onFullScreenEvent(event:Event):void 199 { 200 onStageResize(null); 201 } 202 163 203 164 204 } 165 205 } 206 207 208 import flash.display.Sprite; 209 import flash.events.ContextMenuEvent; 210 import flash.events.Event; 211 import flash.ui.ContextMenu; 212 import flash.ui.ContextMenuItem; 213 import flash.display.CapsStyle; 214 import flash.display.JointStyle; 215 import flash.display.Shape; 216 217 class FullScreenButton extends Sprite 218 { 219 // because StageDisplayState and FullScreenEvent seem to be missing from my 220 // build of Flex Builder: 221 public static const FULL_SCREEN:String = "fullScreen"; 222 public static const NORMAL:String = "normal"; 223 224 private var outIcon:Shape = new Shape(); 225 private var inIcon:Shape = new Shape(); 226 227 public function FullScreenButton() 228 { 229 // draw out arrows 230 outIcon.graphics.lineStyle(1, 0x000000, 1.0, true, "normal", CapsStyle.NONE, JointStyle.BEVEL); 231 outIcon.graphics.moveTo(-2,-5); 232 outIcon.graphics.lineTo(-6,-6); 233 outIcon.graphics.lineTo(-5,-2); 234 235 outIcon.graphics.moveTo(1,-5); 236 outIcon.graphics.lineTo(5,-6); 237 outIcon.graphics.lineTo(4,-2); 238 239 outIcon.graphics.moveTo(-2,4); 240 outIcon.graphics.lineTo(-6,5); 241 outIcon.graphics.lineTo(-5,1); 242 243 outIcon.graphics.moveTo(1,4); 244 outIcon.graphics.lineTo(5,5); 245 outIcon.graphics.lineTo(4,1); 246 addChild(outIcon); 247 248 // draw out arrows 249 inIcon.graphics.lineStyle(1, 0x000000, 1.0, true, "normal", CapsStyle.NONE, JointStyle.BEVEL); 250 inIcon.graphics.moveTo(-3,-6); 251 inIcon.graphics.lineTo(-2,-2); 252 inIcon.graphics.lineTo(-6,-3); 253 254 inIcon.graphics.moveTo(2,-6); 255 inIcon.graphics.lineTo(1,-2); 256 inIcon.graphics.lineTo(5,-3); 257 258 inIcon.graphics.moveTo(-3,5); 259 inIcon.graphics.lineTo(-2,1); 260 inIcon.graphics.lineTo(-6,2); 261 262 inIcon.graphics.moveTo(2,5); 263 inIcon.graphics.lineTo(1,1); 264 inIcon.graphics.lineTo(5,2); 265 //addChild(inIcon); 266 267 addEventListener(Event.ADDED_TO_STAGE, onAddedToStage); 268 } 269 270 private function onAddedToStage(event:Event):void 271 { 272 stage.addEventListener(FULL_SCREEN, onFullScreenEvent); 273 274 // create the context menu, remove the built-in items, 275 // and add our custom items 276 var fullScreenCM:ContextMenu = new ContextMenu(); 277 fullScreenCM.hideBuiltInItems(); 278 279 var fs:ContextMenuItem = new ContextMenuItem("Go Full Screen" ); 280 fs.addEventListener(ContextMenuEvent.MENU_ITEM_SELECT, goFullScreen); 281 fullScreenCM.customItems.push(fs); 282 283 var xfs:ContextMenuItem = new ContextMenuItem("Exit Full Screen"); 284 xfs.addEventListener(ContextMenuEvent.MENU_ITEM_SELECT, exitFullScreen); 285 fullScreenCM.customItems.push(xfs); 286 287 // finally, attach the context menu to the parent 288 this.parent.contextMenu = fullScreenCM; 289 } 290 291 public function toggleFullScreen(event:Event=null):void 292 { 293 if (stage.displayState == FULL_SCREEN) { 294 exitFullScreen(); 295 } 296 else { 297 goFullScreen(); 298 } 299 } 300 301 // functions to enter and leave full screen mode 302 public function goFullScreen(event:Event=null):void 303 { 304 try { 305 stage.displayState = FULL_SCREEN; 306 } 307 catch(err:Error) { 308 trace("Dang fullScreen is not allowed here"); 309 } 310 } 311 public function exitFullScreen(event:Event=null):void 312 { 313 try { 314 stage.displayState = NORMAL; 315 } 316 catch(err:Error) { 317 trace("Problem setting displayState to normal, sorry"); 318 } 319 } 320 321 // function to enable and disable the context menu items, 322 // based on what mode we are in. 323 public function onFullScreenEvent(event:Event):void 324 { 325 if (stage.displayState == FULL_SCREEN) 326 { 327 if (contains(outIcon)) { 328 removeChild(outIcon); 329 } 330 if (!contains(inIcon)) { 331 addChild(inIcon); 332 } 333 this.parent.contextMenu.customItems[0].enabled = false; 334 this.parent.contextMenu.customItems[1].enabled = true; 335 } 336 else 337 { 338 if (!contains(outIcon)) { 339 addChild(outIcon); 340 } 341 if (contains(inIcon)) { 342 removeChild(inIcon); 343 } 344 this.parent.contextMenu.customItems[0].enabled = true; 345 this.parent.contextMenu.customItems[1].enabled = false; 346 } 347 } 348 }
