load imagery from XML file
authorRichard Fairhurst <richard@systemed.net>
Fri, 11 Jun 2010 15:24:38 +0000 (15:24 +0000)
committerRichard Fairhurst <richard@systemed.net>
Fri, 11 Jun 2010 15:24:38 +0000 (15:24 +0000)
TODO.txt
net/systemeD/potlatch2/BackgroundSelector.mxml
potlatch2.mxml
resources/imagery.xml [new file with mode: 0644]

index 43632c9..deb3275 100644 (file)
--- a/TODO.txt
+++ b/TODO.txt
@@ -41,15 +41,14 @@ Potlatch 2: main outstanding issues
 * Ability to specify that a node should be a point in a way, for example for crossings
 * Ability to say that it's unlikely/impossible to have a way that is a bridge and a tunnel at the same time.
 
-
 == UI ==
 
 ** Potlatch 1-style "floaty warnings"
 ** Toolbox fixes (see comments in file)
 ** Should remember which background imagery layer you had previously selected
-** Background imagery layers should match those of p1
 ** Dialog for adding custom imagery url
-** onDataComplete fires the first time a map call has returned - but multiple calls might have been made, so really we should count them and only reset dataWorking when it's back to 0 again
+* B keypress for background source tag
+* Bbox-sensitive menu for background imagery
 * Mouse wheel zooming
 * CSS editing
 * Quick-search on add-relations-to-way dialog (RelationSelectPanel)
@@ -60,7 +59,6 @@ Potlatch 2: main outstanding issues
 
 * Remove created_by=* tags from any data touched
 
-
 == Rendering (Halcyon) ==
 
 ** Changing style, and then back again, doesn't redraw everything
index 0a28e3b..1e899a7 100644 (file)
@@ -4,22 +4,8 @@
        paddingTop="10" paddingLeft="10" paddingRight="10" paddingBottom="10"
        horizontalAlign="left" backgroundColor="white" borderStyle="inset">
        
-       <mx:List width="100%" height="100%" id="background" change="updateBackground();" verticalScrollPolicy="on"> 
-           <!-- This should be pulled in from an XML file rather than sitting in the source -->
-           <mx:dataProvider>
-               <mx:Object label="None" data="" />
-               <mx:Object label="Yahoo!" data="yahoo" />
-            <mx:Object label="OSM - Mapnik" data="http://tile.openstreetmap.org/$z/$x/$y.png" />
-            <mx:Object label="OSM - Osmarender" data="http://tah.openstreetmap.org/Tiles/tile/$z/$x/$y.png" />
-            <mx:Object label="OSM - Maplint (errors)" data="http://tah.openstreetmap.org/Tiles/maplint/$z/$x/$y.png" />
-            <mx:Object label="OpenCycleMap" data="http://andy.sandbox.cloudmade.com/tiles/cycle/$z/$x/$y.png" />
-                       <mx:Object label="UK: OS StreetView" data="http://os.openstreetmap.org/sv/$z/$x/$y.png" />
-            <mx:Object label="UK historic: 1:25k" data="http://ooc.openstreetmap.org/os1/$z/$x/$y.png" />
-            <mx:Object label="UK historic: 7th" data="http://ooc.openstreetmap.org/os7/$z/$x/$y.png" />
-            <mx:Object label="UK historic: NPE" data="http://ooc.openstreetmap.org/npe/$z/$x/$y.png" />
-            <mx:Object label="Australia: NearMap" data="http://www.nearmap.com/maps/nml=Vert&amp;zxy=$z,$x,$y" />
-           </mx:dataProvider>
-       </mx:List>
+       <mx:List width="100%" height="100%" id="background" change="updateBackground();" verticalScrollPolicy="on" 
+                dataProvider="{_layers}" />
        <mx:CheckBox width="100%" label="Dim background" selected="true" id="dim"
            change="Globals.vars.root.tileset.setDimming(dim.selected); Globals.vars.yahoo.alpha = dim.selected ? 0.5 : 1" />
 
                import net.systemeD.halcyon.connection.*;
                import net.systemeD.potlatch2.*;
                import mx.core.*;
+               import mx.collections.ArrayCollection;
                import mx.managers.PopUpManager;
+               import net.systemeD.halcyon.Globals;
+
+               [Bindable] private var _layers:Array=new Array(
+                       { label: "None", data: "" },
+                       { label: "Yahoo", data: "yahoo" } );
+
+               public function populate(xml:XML):void {
+            for each(var set:XML in xml.set) {
+                _layers.push({ label:set.child("name"), data:set.child("url") });
+            }           
+               }
 
                private function updateBackground():void {
             var theMap:Map = Globals.vars.root;
@@ -43,7 +41,6 @@
                                Globals.vars.yahoo.hide();
                        }
                }
-               
 
     ]]></mx:Script>    
 </mx:VBox>
index b2ff679..8395adb 100755 (executable)
         public var theMap:Map;
         public var theController:EditController;
 
+               private var savecount:uint=0;
+               private var loadcount:uint=0;
+
                private function initApp():void {
 
                        Globals.vars.map_area = map_area;
                        _root.addChild(s);
                        theMap.mask=s;
 
-                       // add crosshair
-                       /*s=new Sprite();
-                       s.graphics.lineStyle(2,0);
-                       s.graphics.moveTo(stage.stageWidth/2-20,stage.stageHeight/2);
-                       s.graphics.lineTo(stage.stageWidth/2+20,stage.stageHeight/2);
-                       s.graphics.moveTo(stage.stageWidth/2,stage.stageHeight/2-20);
-                       s.graphics.lineTo(stage.stageWidth/2,stage.stageHeight/2+20);
-                       _root.addChild(s);*/
-
                        // mouse-up handler attached to stage, so the user can release outside the map
                        stage.addEventListener(MouseEvent.MOUSE_UP, theMap.mouseUpHandler);
                        Globals.vars.map_area.addEventListener(MouseEvent.MOUSE_MOVE, theMap.mouseMoveHandler);
                        // keyboard event attached to stage
                        stage.addEventListener(KeyboardEvent.KEY_UP, theMap.keyUpHandler);
 
-                       // example listener event
-                       var myListenerObj:Object = new Object();
-                       myListenerObj.mapHandler=function(event:MapEvent):void {
-                               Globals.vars.debug.appendText("Download event fired - "+event.params.minlat+","+event.params.minlon+"\n");
-                       };
-                       theMap.addEventListener(MapEvent.DOWNLOAD, myListenerObj.mapHandler);
+                       // load imagery XML
+               var request:URLRequest = new URLRequest("imagery.xml?"+Math.random());
+               var loader:URLLoader = new URLLoader();
+               loader.addEventListener(Event.COMPLETE, onImageryLoad);
+               loader.load(request);
 
                        // add debug field
                        var t:TextField=new TextField();
             var conn:Connection = Connection.getConnectionInstance();
             conn.addEventListener(Connection.LOAD_STARTED, onDataStart);
             conn.addEventListener(Connection.LOAD_COMPLETED, onDataComplete);
-
-                       // and to import a shapefile...
-//                     var importer:ShpImporter = new ShpImporter(theMap, ["http://127.0.0.1/~richard/shp/wildrnp020.shp","http://127.0.0.1/~richard/shp/wildrnp020.shx","http://127.0.0.1/~richard/shp/wildrnp020.dbf"]);
+            conn.addEventListener(Connection.SAVE_STARTED, onDataStart);
+            conn.addEventListener(Connection.SAVE_COMPLETED, onDataComplete);
                }
 
         public function onResizeMap():void {
         }
 
         private function onDataStart(event:Event):void {
-            dataWorking.text = event.type == Connection.LOAD_STARTED ? "Loading data..." : "Saving Data...";
-            dataWorking.visible = true;
+                       switch (event.type) {
+                               case Connection.LOAD_STARTED:   loadcount++; break;
+                               case Connection.SAVE_STARTED:   savecount++; break;
+                       }
+                       updateDataWorking();
         }
         private function onDataComplete(event:Event):void {
-            dataWorking.visible = false;
+                       switch (event.type) {
+                               case Connection.LOAD_COMPLETED: loadcount--; break;
+                               case Connection.SAVE_COMPLETED: savecount--; break;
+                       }
+            updateDataWorking();
         }
+               private function updateDataWorking():void {
+                       if (loadcount>0 && savecount>0) { dataWorking.text="Loading/saving..."; }
+                       else if (loadcount>0)           { dataWorking.text="Loading data..."; }
+                       else if (savecount>0)           { dataWorking.text="Saving data..."; }
+                       else                            { dataWorking.text=""; }
+                       dataWorking.visible=(dataWorking.text!="");
+               }
         
+        private function onImageryLoad(event:Event):void {
+                       var imagery:XML = new XML(URLLoader(event.target).data);
+                       BackgroundSelector(bgButton.popUp).populate(imagery);
+               }
 
         
         private function dragEnterHandler(event:DragEvent):void {
diff --git a/resources/imagery.xml b/resources/imagery.xml
new file mode 100644 (file)
index 0000000..79652df
--- /dev/null
@@ -0,0 +1,91 @@
+<?xml version="1.0" encoding="UTF-8" ?>
+
+<imagery>
+       <set>
+               <name>OSM - Mapnik</name>
+               <type>900913</type>
+               <url>http://tile.openstreetmap.org/$z/$x/$y.png</url>
+       </set>
+       <set>
+               <name>OSM - Osmarender</name>
+               <type>900913</type>
+               <url>http://tah.openstreetmap.org/Tiles/tile/$z/$x/$y.png</url>
+       </set>
+\7f      <set>
+               <name>OSM - Maplint (errors)</name>
+               <type>900913</type>
+               <url>http://tah.openstreetmap.org/Tiles/maplint/$z/$x/$y.png</url>
+       </set>
+       <set>
+               <name>OS OpenData Streetview</name>
+               <type>900913</type>
+               <url>http://os.openstreetmap.org/sv/$z/$x/$y.png</url>
+               <sourcetag>OS OpenData StreetView</sourcetag>
+       </set>
+       <set>
+               <name>OS OpenData Locator</name>
+               <type>900913</type>
+               <url>http://tiles.itoworld.com/os_locator/$z/$x/$y.png</url>
+               <sourcetag>OS OpenData Locator</sourcetag>
+       </set>
+       <set>
+               <name>OS 1:25k historic</name>
+               <type>900913</type>
+               <url>http://ooc.openstreetmap.org/os1/$z/$x/$y.png</url>
+               <sourcetag>OS 1:25k</sourcetag>
+       </set>
+       <set>
+               <name>OS 7th Series historic</name>
+               <type>900913</type>
+               <url>http://ooc.openstreetmap.org/os7/$z/$x/$y.png</url>
+               <sourcetag>OS7</sourcetag>
+       </set>
+       <set>
+               <name>OS New Popular Edition historic</name>
+               <type>900913</type>
+               <url>http://ooc.openstreetmap.org/npe/$z/$x/$y.png</url>
+               <sourcetag>NPE</sourcetag>
+       </set>
+       <set>
+               <name>OS Scottish Popular historic</name>
+               <type>900913</type>
+               <url>http://gibin.geog.ucl.ac.uk/~ollie/scotland/tiles/$z/$x/$y.jpg</url>
+               <sourcetag>NPE</sourcetag>
+       </set>
+       <set>
+               <name>Surrey aerial</name>
+               <type>900913</type>
+               <url>http://gravitystorm.dev.openstreetmap.org/surrey/$z/$x/$y.png</url>
+               <sourcetag>Surrey aerial</sourcetag>
+       </set>
+       <set>
+               <name>NearMap aerial</name>
+               <type>900913</type>
+               <url>http://www.nearmap.com/maps/nml=Vert&amp;zxy=$z,$x,$y</url>
+               <sourcetag>NearMap</sourcetag>
+       </set>
+       <set>
+               <name>Haiti - GeoEye Jan 13</name>
+               <type>900913</type>
+               <url>http://gravitystorm.dev.openstreetmap.org/imagery/haiti/$z/$x/$y.jpg</url>
+               <sourcetag>Haiti GeoEye</sourcetag>
+       </set>
+       <set>
+               <name>Haiti - GeoEye Jan 13+</name>
+               <type>900913</type>
+               <url>http://maps.nypl.org/tilecache/1/geoeye/$z/$x/$y.jpg</url>
+               <sourcetag>Haiti GeoEye</sourcetag>
+       </set>
+       <set>
+               <name>Haiti - DigitalGlobe</name>
+               <type>900913</type>
+               <url>http://maps.nypl.org/tilecache/1/dg_crisis/$z/$x/$y.jpg</url>
+               <sourcetag>Haiti DigitalGlobe</sourcetag>
+       </set>
+       <set>
+               <name>Haiti - Street names</name>
+               <type>900913</type>
+               <url>http://hypercube.telascience.org/tiles/1.0.0/haiti-city/$z/$x/$y.jpg</url>
+               <sourcetag>Haiti streetnames</sourcetag>
+       </set>
+</imagery>