Get Halcyon working again
authorRichard Fairhurst <richard@systemeD.net>
Mon, 19 Mar 2012 12:03:54 +0000 (12:03 +0000)
committerRichard Fairhurst <richard@systemeD.net>
Mon, 19 Mar 2012 12:03:54 +0000 (12:03 +0000)
(still a few non-functional bits round the edges, but the core viewer is ok)

halcyon_viewer-config.xml
halcyon_viewer.as
resources/halcyon.html

index 4b4c2ed..a4cd4d8 100644 (file)
       <library-path append="true">
           <path-element>lib</path-element>
       </library-path>
+
+       
    </compiler>
+       <static-link-runtime-shared-libraries>true</static-link-runtime-shared-libraries>
 
    <metadata>
       <title>Halcyon</title>
index cbf3c91..3e8598c 100644 (file)
@@ -7,6 +7,7 @@ package {
        import flash.events.*;
        import flash.events.MouseEvent;
        import flash.display.*;
+       import flash.text.Font;
        import flash.text.TextField;
        import flash.external.*;
 //     import bustin.dev.Inspector;
@@ -18,30 +19,45 @@ package {
                function halcyon_viewer():void {
                        stage.align = StageAlign.TOP_LEFT;
                        stage.scaleMode = StageScaleMode.NO_SCALE;
-                       this.loaderInfo.addEventListener(Event.COMPLETE, init);
+                       this.loaderInfo.addEventListener(Event.COMPLETE, startInit);
                }
        
-               private function init(e:Event):void {
+               private function startInit(e:Event):void {
+                       var loader:Loader = new Loader();
+                       loader.contentLoaderInfo.addEventListener(Event.COMPLETE, startApp);
+                       loader.load(new URLRequest("FontLibrary.swf"));
+               }
+
+               private function startApp(event:Event):void {
+                       // Initialise font
+                       var FontLibrary:Class = event.target.applicationDomain.getDefinition("FontLibrary") as Class;
+                       Font.registerFont(FontLibrary.DejaVu);
+
+                       // Get parameters
+                       var params:Object={}; var k:String;
+                       for (k in this.loaderInfo.parameters) params[k]=this.loaderInfo.parameters[k];
+                       Globals.vars.flashvars = loaderInfo.parameters; // ** FIXME - not sure we should use flashvars anywhere in Halcyon/P2
 
-                       theMap = new Map(this.loaderInfo.parameters);
+                       // Initialise map
+                       theMap = new Map();
             theMap.updateSize(stage.stageWidth, stage.stageHeight);
                        addChild(theMap);
-                       Globals.vars.root=theMap;
-                       Globals.vars.nocache = loaderInfo.parameters['nocache'] == 'true';
 
-                       // add debug field
-                       var t:TextField=new TextField();
-                       t.width=400; t.height=100; t.x=400; t.border=true;
-                       t.multiline=true;
-                       addChild(t);
-                       Globals.vars.debug=t;
-            t.visible = loaderInfo.parameters["show_debug"] == 'true';
+                       // Add connection
+                       // ** FIXME - should get the stylesheet from parameters
+                       var conn:Connection = new XMLConnection("Main", params['api'], params['policy'], params);
+                       theMap.addLayer(conn, params['style'], false, true);
+                       theMap.init(params['lat'], params['lon'], params['zoom']);
+
+                       Globals.vars.root=theMap;       // ** FIXME - should no longer be necessary
+                       Globals.vars.nocache = loaderInfo.parameters['nocache'] == 'true';
 
                        stage.addEventListener(MouseEvent.MOUSE_UP, theMap.mouseUpHandler);
                        stage.addEventListener(MouseEvent.MOUSE_MOVE, theMap.mouseMoveHandler);
                        stage.addEventListener(MouseEvent.MOUSE_DOWN, theMap.mouseDownHandler);
 //                     Inspector.getInstance().init(stage);
 
+                       // Zoom buttons
                        var z1:Sprite=new Sprite();
                        z1.graphics.beginFill(0x0000FF); z1.graphics.drawRoundRect(0,0,20,20,5); z1.graphics.endFill();
                        z1.graphics.lineStyle(2,0xFFFFFF);
index 6f84375..5a076e7 100644 (file)
@@ -3,33 +3,26 @@
 <!-- Halcyon example embed script -->
 
 <head>
-<title>Halcyon</title>
-<script type="text/javascript" src="swfobject.js"></script>
-</head>
-
-<body>
-
-<div id="map" style="width:800px; height: 600px; border: 1px solid black; float:left; margin-right: 10px">
-</div>
 
-<script>
+       <title>Halcyon</title>
+       <script type="text/javascript" src="swfobject.js"></script>
 
-       function respond(event,object,id,attr) {
-               alert (event+": "+object+" "+id+", highway="+attr['highway']);
+    <script>
+       function getArgs() {
+               var args = new Object();
+               var query = location.search.substring(1);
+               var pairs = query.split("&");
+               for(var i = 0; i < pairs.length; i++) {
+                       var pos = pairs[i].indexOf('=');
+                       if (pos == -1) continue;
+                       var argname = pairs[i].substring(0,pos);
+                       var value = pairs[i].substring(pos+1);
+                       args[argname] = unescape(value);
+               }
+               return args;
        }
 
-       var fo = new SWFObject("halcyon_viewer.swf?d="+Math.round(Math.random()*1000), "mapswf", "100%", "100%", "9", "#FFFFFF");
-       fo.addVariable("lat",51.875);
-       fo.addVariable("lon",-1.482);
-       fo.addVariable("zoom",14);
-       fo.addVariable("api","http://www.openstreetmap.org/api/0.6/");
-       fo.addVariable("policy","http://www.openstreetmap.org/api/crossdomain.xml");
-       fo.addVariable("connection","AMF");
-       fo.addVariable("responder","respond");
-       fo.addVariable("tileurl","http://npe.openstreetmap.org/$z/$x/$y.png");
-       fo.addVariable("style","test.css?d="+Math.round(Math.random()*1000));
-       fo.addVariable("show_debug","false");
-       fo.write("map");
+       function respond(event,object,id,attr) { alert (event+": "+object+" "+id+", highway="+attr['highway']); }
 
        function refreshCSS() {
                if (document.getElementById("mapswf")) { 
                        document.getElementById("mapswf").jumpTo(document.getElementById("lat").value,document.getElementById("lon").value);
                }
        }
-       
+
+       var args = getArgs();
+       var lat;
+       var lon;
+       var zoom;
+       if (args.lat && args.lon) {
+               lat = parseFloat(args.lat);
+               lon = parseFloat(args.lon);
+       } else {
+               lat=51.875;
+               lon=-1.492;
+               args["lat"] = lat;
+               args["lon"] = lon;
+       }
+
+       if (args.zoom) {
+               zoom = parseInt(args.zoom);
+       } else {
+               zoom = 18;
+               args["zoom"] = 18;
+       }
+
+       args["api"] = "http://www.openstreetmap.org/api/0.6/";
+       args["policy"] = "http://www.openstreetmap.org/api/crossdomain.xml";
+       args["connection"] = "XML";     // or AMF
+       args["tileurl"]="http://npe.openstreetmap.org/$z/$x/$y.png";
+       args["style"]="stylesheets/potlatch.css";
+       args["responder"]="respond";
+
+       var params = false;
+
+       swfobject.embedSWF("halcyon_viewer.swf?d="+Math.round(Math.random()*1000), "mapHolder", "800px", "100%", "10.1.85", "expressInstall.swf", args, params, { id: "map", name: "map" });
+
 </script>
+</head>
+
+<body>
+
+<div id="mapHolder" style="width:800px; height: 100%; border: 1px solid black; float:left; margin-right: 10px;">
+       If you see this message you need to install Flash Player 10.1.85 or above, from Adobe, <a href="http://get.adobe.com/flashplayer/" target="_blank">available here</a> in order to use Potlatch 2
+</div>
+
 
-<div id="ui">
+<div id="ui" style="float:right">
 <p>Lat: <input id='lat' value='51.875' size='6'> Lon: <input id='lon' value='-1.482' size='6'>
 <input type='button' onClick='javascript:jumpTo();' value=" Go ">
 <p>