Only add a new vector layer to the map once we know we have loaded
authorTom Hughes <tom@compton.nu>
Wed, 24 Nov 2010 21:14:21 +0000 (21:14 +0000)
committerTom Hughes <tom@compton.nu>
Wed, 24 Nov 2010 21:14:21 +0000 (21:14 +0000)
it successfully or it will keep reappearing in the dialog.

net/systemeD/potlatch2/VectorSourceDialog.mxml

index 1e8b244..cba7658 100644 (file)
                if (type=='gpx') { stylesheet="gpx.css"; }
                var vectorlayer:VectorLayer=new VectorLayer(name,map,stylesheet);
                vectorlayer.url=url;
-               map.addVectorLayer(vectorlayer);
+
+                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);
                                                            [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>