support GPX 1.1 too
[potlatch2.git] / net / systemeD / potlatch2 / VectorSourceDialog.mxml
index ca092057aeff552f3862de41e316e4df9c395ff7..ea11ab44fa142caec7eca23163a14eea3ab9e837 100644 (file)
@@ -24,8 +24,9 @@
                                        <mx:Component>
                                        <mx:ComboBox
                                                        selectedItem="{outerDocument.whichStyle(data)}"
-                                               change="outerDocument.styleEdited(data.name,selectedItem.data)"
-                                               dataProvider="{outerDocument.styles}" />
+                                               change="outerDocument.styleEdited(data.name,selectedItem.url)"
+                                               dataProvider="{outerDocument.styles}" 
+                                                       labelField="name" />
                                        </mx:Component>
                                </mx:itemRenderer>
                        </mx:DataGridColumn>
@@ -40,6 +41,7 @@
                <mx:HBox>
                        <mx:RadioButtonGroup id="filetype" />
                        <mx:RadioButton width="100%" groupName="filetype" value="gpx" id="gpx" label="GPX" selected="true" />
+                       <mx:RadioButton width="100%" groupName="filetype" value="kml" id="kml" label="KML" />
                        <mx:RadioButton width="100%" groupName="filetype" value="osm" id="osm" label="OSM" />
                        <mx:RadioButton width="100%" groupName="filetype" value="shp" id="shp" label="Shapefile" />
                        <mx:CheckBox width="100%" label="Simplify paths" selected="true" id="simplify" />
        import net.systemeD.halcyon.VectorLayer;
        import net.systemeD.potlatch2.utils.Importer;
        import net.systemeD.potlatch2.utils.GpxImporter;
+       import net.systemeD.potlatch2.utils.KmlImporter;
        import net.systemeD.potlatch2.utils.ShpImporter;
        import net.systemeD.potlatch2.utils.OsmImporter;
+       import net.systemeD.potlatch2.collections.Stylesheets;
     import mx.managers.PopUpManager;
     import mx.events.DataGridEvent;
     import mx.events.CloseEvent;
 
        public function whichStyle(item:Object):Object {
                for each (var style:Object in styles) {
-                       if (style.data==item.style) { return style; }
+                       if (style.url==item.style) { return style; }
                }
                return {};
        }
 
        [Bindable(event="bogus")]
        public function get styles():ArrayCollection {
-               return new ArrayCollection(Application.application.theController.stylesheets);
+               return new ArrayCollection(Stylesheets.instance().collection);
        }
 
        [Bindable(event="layers_changed")]
     }
 
        private function loadFiles(url:String,type:String,simplify:Boolean):void {
-               var vectorlayer:VectorLayer=new VectorLayer(url,map,"potlatch.css");
+               var names:Array=url.split('/'); var name:String=names[names.length-1];
+               var stylesheet:String="potlatch.css";
+               if (type=='gpx') { stylesheet="gpx.css"; }
+               var vectorlayer:VectorLayer=new VectorLayer(name,map,stylesheet);
                vectorlayer.url=url;
-               map.vectorlayers[url]=vectorlayer;
-               map.vectorbg.addChild(vectorlayer.paint);
+
+                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 {
                                                            [url+".shp",url+".shx",url+".dbf"], filesLoaded, simplify);
                }
        }
-       
-       public function filesLoaded(success:Boolean,message:String=null):void {
-               if (success) {
-                       dispatchEvent(new Event("layers_changed"));
-               } else {
-                       Alert.show(message, 'Error', mx.controls.Alert.OK);
-               }
-       }
 
               ]]>
   </mx:Script>