Partial refactoring of VectorSourceDialog. Not happy with iterating over Map.paintCon...
authorAndy Allan <andy@gravitystorm.co.uk>
Tue, 24 May 2011 11:27:20 +0000 (12:27 +0100)
committerAndy Allan <andy@gravitystorm.co.uk>
Tue, 24 May 2011 11:27:20 +0000 (12:27 +0100)
net/systemeD/potlatch2/VectorSourceDialog.mxml

index ba04157..5f6b85b 100644 (file)
@@ -56,8 +56,9 @@
   <mx:Script><![CDATA[
 
        import net.systemeD.halcyon.Map;
+       import net.systemeD.halcyon.MapPaint;
        import net.systemeD.halcyon.Globals;
-       import net.systemeD.halcyon.VectorLayer;
+       import net.systemeD.halcyon.connection.Connection;
        import net.systemeD.potlatch2.utils.Importer;
        import net.systemeD.potlatch2.utils.GpxImporter;
        import net.systemeD.potlatch2.utils.KmlImporter;
@@ -74,8 +75,7 @@
        private var map:Map;
 
        public function styleEdited(name:String,stylesheet:String):void {
-               map.vectorlayers[name].style=stylesheet;
-               map.vectorlayers[name].redrawFromCSS(stylesheet)
+               map.findLayer(name).setStyle(stylesheet);
        }
 
 
 
        [Bindable(event="layers_changed")]
        private function get vectorLayers():Array {
-               var v:Array=[];
-               for (var a:String in map.vectorlayers) {
-                       var vl:VectorLayer=map.vectorlayers[a];
-                       v.push( { name:a, visible:vl.paint.visible, url:vl.url, style:vl.style } );
+        var v:Array=[];
+        for (var i:uint = 0; i < map.paintContainer.numChildren; i++) { //nasty
+            var a:MapPaint = MapPaint(map.paintContainer.getChildAt(i));
+            if (a.isBackground) {
+                v.push( { name:a.connection.name, visible:a.visible, url:a.connection.apiBase, style:a.style } );
+            }
                }
                return v;
        }
        
        private function toggleVisibility(event:Event):void {
-               map.vectorlayers[dataGrid.selectedItem.name].paint.visible = !map.vectorlayers[dataGrid.selectedItem.name].paint.visible;
+               map.findLayer[dataGrid.selectedItem.name].visible = !map.findLayer[dataGrid.selectedItem.name].visible;
        }
        
        private function dataEdited(event:DataGridEvent):void {
                        // Rename field
                        var a:String=dataGrid.selectedItem.name;
                        var b:String=dataGrid.itemEditorInstance['text'];       // this is, unbelievably, how you get data within an itemEditEnd event
-                       if (a==b || map.vectorlayers[b]) {
+                       if (a==b || map.findLayer(b)) {
                                event.preventDefault();
                        } else {
-                               map.vectorlayers[b]=map.vectorlayers[a];
-                               delete map.vectorlayers[a];
+                               map.findLayer(a).connection.name = b;
                        }
                        dispatchEvent(new Event("layers_changed"));
                }
        }
 
        private function removeVectorLayer():void {
-               map.removeVectorLayer(map.vectorlayers[dataGrid.selectedItem.name]);
+               map.removeLayerByName(dataGrid.selectedItem.name);
                dispatchEvent(new Event("layers_changed"));
        }
     
                var names:Array=url.split('/'); var name:String=names[names.length-1];
                var stylesheet:String="stylesheets/potlatch.css";
                if (type=='gpx') { stylesheet="stylesheets/gpx.css"; }
-               var vectorlayer:VectorLayer=new VectorLayer(name,map,stylesheet);
-               vectorlayer.url=url;
-
-                var filesLoaded:Function = function(success:Boolean,message:String=null):void {
-                        if (success) {
-                                map.addVectorLayer(vectorlayer);
-                                dispatchEvent(new Event("layers_changed"));
-                        } else {
-                                Alert.show(message, 'Error', mx.controls.Alert.OK);
-                        }
-                }
-
-               if (type=='gpx') {
-                       var gpx:GpxImporter=new GpxImporter(vectorlayer, vectorlayer.paint, [url], filesLoaded, simplify);
-               } else if (type=='kml') {
-                       var kml:KmlImporter=new KmlImporter(vectorlayer, vectorlayer.paint, [url], filesLoaded, simplify);
-               } else if (type=='osm') {
-                       var osm:OsmImporter=new OsmImporter(vectorlayer, vectorlayer.paint, [url], filesLoaded, simplify);
-               } else {
-                       var re:RegExp=/.shp$/i; url=url.replace(re,'');
-                       var shp:ShpImporter=new ShpImporter(vectorlayer,
-                                                           vectorlayer.paint,
-                                                           [url+".shp",url+".shx",url+".dbf"], filesLoaded, simplify);
-               }
+
+               var connection:Connection = new Connection(name, url, null, null);
+               var mp:MapPaint = map.addLayer(connection, stylesheet);
+
+// REFACTOR this. commented out to let docs compile.
+        trace("loadFiles not implemented");
+//                var filesLoaded:Function = function(success:Boolean,message:String=null):void {
+//                        if (success) {
+//                                map.addVectorLayer(vectorlayer);
+//                                dispatchEvent(new Event("layers_changed"));
+//                        } else {
+//                                Alert.show(message, 'Error', mx.controls.Alert.OK);
+//                        }
+//                }
+
+//             if (type=='gpx') {
+//                     var gpx:GpxImporter=new GpxImporter(vectorlayer, vectorlayer.paint, [url], filesLoaded, simplify);
+//             } else if (type=='kml') {
+//                     var kml:KmlImporter=new KmlImporter(vectorlayer, vectorlayer.paint, [url], filesLoaded, simplify);
+//             } else if (type=='osm') {
+//                     var osm:OsmImporter=new OsmImporter(vectorlayer, vectorlayer.paint, [url], filesLoaded, simplify);
+//             } else {
+//                     var re:RegExp=/.shp$/i; url=url.replace(re,'');
+//                     var shp:ShpImporter=new ShpImporter(vectorlayer,
+//                                                         vectorlayer.paint,
+//                                                         [url+".shp",url+".shx",url+".dbf"], filesLoaded, simplify);
+//             }
        }
 
               ]]>