Improve way improving
[potlatch2.git] / halcyon_viewer.as
1 package {
2
3         import net.systemeD.halcyon.*;
4         import net.systemeD.halcyon.connection.*;
5         import flash.system.Security;
6         import flash.net.*;
7         import flash.events.*;
8         import flash.events.MouseEvent;
9         import flash.display.*;
10         import flash.text.Font;
11         import flash.text.TextField;
12         import flash.external.*;
13 //      import bustin.dev.Inspector;
14
15         public class halcyon_viewer extends Sprite {
16
17                 public var theMap:Map;
18
19                 function halcyon_viewer():void {
20                         stage.align = StageAlign.TOP_LEFT;
21                         stage.scaleMode = StageScaleMode.NO_SCALE;
22                         this.loaderInfo.addEventListener(Event.COMPLETE, startInit);
23                 }
24         
25                 private function startInit(e:Event):void {
26                         var loader:Loader = new Loader();
27                         loader.contentLoaderInfo.addEventListener(Event.COMPLETE, startApp);
28                         loader.load(new URLRequest("FontLibrary.swf"));
29                 }
30
31                 private function startApp(event:Event):void {
32                         // Initialise font
33                         var FontLibrary:Class = event.target.applicationDomain.getDefinition("FontLibrary") as Class;
34                         Font.registerFont(FontLibrary.DejaVu);
35
36                         // Get parameters
37                         var params:Object={}; var k:String;
38                         for (k in this.loaderInfo.parameters) params[k]=this.loaderInfo.parameters[k];
39                         Globals.vars.flashvars = loaderInfo.parameters; // ** FIXME - not sure we should use flashvars anywhere in Halcyon/P2
40
41                         // Initialise map
42                         theMap = new Map();
43             theMap.updateSize(stage.stageWidth, stage.stageHeight);
44                         addChild(theMap);
45
46                         // Add connection
47                         // ** FIXME - should get the stylesheet from parameters
48                         var conn:Connection = new XMLConnection("Main", params['api'], params['policy'], params);
49                         theMap.addLayer(conn, params['style'], false, true);
50                         theMap.init(params['lat'], params['lon'], params['zoom']);
51
52                         Globals.vars.root=theMap;       // ** FIXME - should no longer be necessary
53                         Globals.vars.nocache = loaderInfo.parameters['nocache'] == 'true';
54
55                         stage.addEventListener(MouseEvent.MOUSE_UP, theMap.mouseUpHandler);
56                         stage.addEventListener(MouseEvent.MOUSE_MOVE, theMap.mouseMoveHandler);
57                         stage.addEventListener(MouseEvent.MOUSE_DOWN, theMap.mouseDownHandler);
58 //                      Inspector.getInstance().init(stage);
59
60                         // Zoom buttons
61                         var z1:Sprite=new Sprite();
62                         z1.graphics.beginFill(0x0000FF); z1.graphics.drawRoundRect(0,0,20,20,5); z1.graphics.endFill();
63                         z1.graphics.lineStyle(2,0xFFFFFF);
64                         z1.graphics.moveTo(5,10); z1.graphics.lineTo(15,10);
65                         z1.graphics.moveTo(10,5); z1.graphics.lineTo(10,15);
66                         z1.x=5; z1.y=5; z1.buttonMode=true;
67                         z1.addEventListener(MouseEvent.CLICK, zoomInHandler, false, 1);
68                         addChild(z1);
69
70                         var z2:Sprite=new Sprite();
71                         z2.graphics.beginFill(0x0000FF); z2.graphics.drawRoundRect(0,0,20,20,5); z2.graphics.endFill();
72                         z2.graphics.lineStyle(2,0xFFFFFF);
73                         z2.graphics.moveTo(5,10); z2.graphics.lineTo(15,10);
74                         z2.x=5; z2.y=30; z2.buttonMode=true;
75                         z2.addEventListener(MouseEvent.CLICK, zoomOutHandler, false, 1);
76                         addChild(z2);
77
78                         if (this.loaderInfo.parameters.hasOwnProperty('responder')) {
79                 var controller:JSController = new JSController(theMap, loaderInfo.parameters['responder']);
80                                 controller.setActive();
81                         }
82
83                         ExternalInterface.addCallback('refreshCSS', onRefreshCSS);
84                         ExternalInterface.addCallback('jumpTo', onJumpTo);
85                 }
86
87                 private function onRefreshCSS(str:String):void {
88                         theMap.editableLayer.setStyle(str);
89                 }               
90                 private function onJumpTo(lat:Number,lon:Number):void {
91                         theMap.init(lat,lon);
92                 }
93
94                 private function zoomInHandler(e:MouseEvent):void  { e.stopPropagation(); theMap.zoomIn(); }
95                 private function zoomOutHandler(e:MouseEvent):void { e.stopPropagation(); theMap.zoomOut(); }
96
97
98         }
99 }