Local file vector import (not .shp yet)
authorRichard Fairhurst <richard@systemeD.net>
Sun, 25 Mar 2012 13:20:31 +0000 (14:20 +0100)
committerRichard Fairhurst <richard@systemeD.net>
Sun, 25 Mar 2012 13:20:31 +0000 (14:20 +0100)
net/systemeD/potlatch2/dialogs/VectorSourceDialog.mxml
net/systemeD/potlatch2/utils/Importer.as

index 6ba72e0..d8a275a 100644 (file)
        import mx.controls.Alert;
 
        private var map:Map;
+       private var localFileReference:FileReference;
 
        public function styleEdited(name:String,stylesheet:String):void {
                map.findLayer(name).setStyle(stylesheet);
        
        /** Present an 'Open File' dialogue. */
        private function loadFileLocal():void {
-               var file:FileReference=new FileReference(); 
+               // note scoping issues - http://blog.wrench.com.au/2010/06/16/filereferenceload-keep-it-in-scope/
+               localFileReference=new FileReference(); 
                var fileTypes:FileFilter=new FileFilter("*."+selectedType, "*."+selectedType); 
-               file.browse([fileTypes]); 
-               file.addEventListener(Event.SELECT, selectFileLocal);
+               localFileReference.browse([fileTypes]); 
+               localFileReference.addEventListener(Event.SELECT, selectFileLocal);
        }
        
        /** The user has chosen a file in the local 'Open File' dialogue. */
        private function selectFileLocal(event:Event):void {
-               var connection:Connection = new Connection(name, url, null, null, CSSTransform.getInstance());
+               var connection:Connection = new Connection(localFileReference.name, '', null, null, CSSTransform.getInstance());
                var importer:Importer = findImporter(connection);
-               importer.importFromLocalFile();
+               importer.importFromLocalFile(localFileReference);
        }
        
        /** Create an Importer object of the type selected by the user. */
index 4068072..d74b931 100644 (file)
@@ -31,7 +31,7 @@ package net.systemeD.potlatch2.utils {
                public function importFromRemoteFiles(filenames:Array):void {
                        this.filenames=filenames;
                        // Use forEach to avoid closure problem (http://stackoverflow.com/questions/422784/how-to-fix-closure-problem-in-actionscript-3-as3#3971784)
-                       filenames.forEach(function(file:*, index:int, array:Array):void {
+                       filenames.forEach(function(file:String, index:int, array:Array):void {
                                trace("requesting file "+index);
                                var loader:URLLoader = new URLLoader();
                                loader.dataFormat=URLLoaderDataFormat.BINARY;
@@ -44,11 +44,16 @@ package net.systemeD.potlatch2.utils {
                        });
                }
                
-               public function importFromLocalFiles():void {
-                       // ** FIXME: if it's a zip, do something clever
+               public function importFromLocalFile(file:FileReference):void {
+                       filenames=['local'];
+                       file.addEventListener(Event.COMPLETE, fileLoaded);
+                       file.addEventListener(IOErrorEvent.IO_ERROR,ioErrorHandler);
+                       file.addEventListener(SecurityErrorEvent.SECURITY_ERROR,securityErrorHandler);
+                       file.load();
+                       // ** FIXME: if it's a zip (e.g. shapefiles), do something really amazingly clever
                }
                
-               protected function fileLoaded(e:Event,filenum:uint):void {
+               protected function fileLoaded(e:Event,filenum:uint=0):void {
                        files[filenum]=e.target.data;
                        filesloaded++;
                        trace("loaded file "+filenum+" ("+filesloaded+"/"+filenames.length+")");