add more ways to control the viewer from JavaScript
[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.TextField;
11         import flash.external.*;
12 //      import bustin.dev.Inspector;
13
14         public class halcyon_viewer extends Sprite {
15
16                 public var theMap:Map;
17
18                 function halcyon_viewer():void {
19                         stage.align = StageAlign.TOP_LEFT;
20                         stage.scaleMode = StageScaleMode.NO_SCALE;
21                         this.loaderInfo.addEventListener(Event.COMPLETE, init);
22                 }
23         
24                 private function init(e:Event):void {
25
26                         theMap = new Map(this.loaderInfo.parameters);
27             theMap.updateSize(stage.stageWidth, stage.stageHeight);
28                         addChild(theMap);
29                         Globals.vars.root=theMap;
30
31                         // add debug field
32                         var t:TextField=new TextField();
33                         t.width=400; t.height=100; t.x=400; t.border=true;
34                         t.multiline=true;
35                         addChild(t);
36                         Globals.vars.debug=t;
37             t.visible = loaderInfo.parameters["show_debug"] == 'true';
38
39                         stage.addEventListener(MouseEvent.MOUSE_UP, theMap.mouseUpHandler);
40                         stage.addEventListener(MouseEvent.MOUSE_MOVE, theMap.mouseMoveHandler);
41                         stage.addEventListener(MouseEvent.MOUSE_DOWN, theMap.mouseDownHandler);
42 //                      Inspector.getInstance().init(stage);
43
44                         var z1:Sprite=new Sprite();
45                         z1.graphics.beginFill(0x0000FF); z1.graphics.drawRoundRect(0,0,20,20,5); z1.graphics.endFill();
46                         z1.graphics.lineStyle(2,0xFFFFFF);
47                         z1.graphics.moveTo(5,10); z1.graphics.lineTo(15,10);
48                         z1.graphics.moveTo(10,5); z1.graphics.lineTo(10,15);
49                         z1.x=5; z1.y=5; z1.buttonMode=true;
50                         z1.addEventListener(MouseEvent.CLICK, zoomInHandler, false, 1);
51                         addChild(z1);
52
53                         var z2:Sprite=new Sprite();
54                         z2.graphics.beginFill(0x0000FF); z2.graphics.drawRoundRect(0,0,20,20,5); z2.graphics.endFill();
55                         z2.graphics.lineStyle(2,0xFFFFFF);
56                         z2.graphics.moveTo(5,10); z2.graphics.lineTo(15,10);
57                         z2.x=5; z2.y=30; z2.buttonMode=true;
58                         z2.addEventListener(MouseEvent.CLICK, zoomOutHandler, false, 1);
59                         addChild(z2);
60
61                         if (this.loaderInfo.parameters.hasOwnProperty('responder')) {
62                 var controller:JSController = new JSController(theMap, loaderInfo.parameters['responder']);
63                                 controller.setActive();
64                         }
65
66                         ExternalInterface.addCallback('refreshCSS', onRefreshCSS);
67                         ExternalInterface.addCallback('jumpTo', onJumpTo);
68                 }
69
70                 private function onRefreshCSS(str:String):void {
71                         theMap.ruleset.loadFromCSS(str);
72                         theMap.redraw();
73                 }               
74                 private function onJumpTo(lat:Number,lon:Number):void {
75                         theMap.init(lat,lon);
76                 }
77
78                 private function zoomInHandler(e:MouseEvent):void  { e.stopPropagation(); theMap.zoomIn(); }
79                 private function zoomOutHandler(e:MouseEvent):void { e.stopPropagation(); theMap.zoomOut(); }
80
81
82         }
83 }