Merge branch 'localfile'
authorRichard Fairhurst <richard@systemeD.net>
Sun, 25 Mar 2012 15:24:09 +0000 (16:24 +0100)
committerRichard Fairhurst <richard@systemeD.net>
Sun, 25 Mar 2012 15:24:09 +0000 (16:24 +0100)
14 files changed:
l10n/map/LocalizationMap.mxml
net/systemeD/potlatch2/BackgroundSelector.mxml
net/systemeD/potlatch2/StyleSelector.mxml
net/systemeD/potlatch2/collections/VectorBackgrounds.as
net/systemeD/potlatch2/dialogs/BackgroundDialog.mxml [moved from net/systemeD/potlatch2/BackgroundDialog.mxml with 87% similarity]
net/systemeD/potlatch2/dialogs/MyGpxDialog.mxml [moved from net/systemeD/potlatch2/mygpx/MyGpxDialog.mxml with 100% similarity]
net/systemeD/potlatch2/dialogs/OptionsDialog.mxml [moved from net/systemeD/potlatch2/options/OptionsDialog.mxml with 100% similarity]
net/systemeD/potlatch2/dialogs/VectorSourceDialog.mxml [moved from net/systemeD/potlatch2/VectorSourceDialog.mxml with 52% similarity]
net/systemeD/potlatch2/utils/GpxImporter.as
net/systemeD/potlatch2/utils/Importer.as
net/systemeD/potlatch2/utils/KmlImporter.as
net/systemeD/potlatch2/utils/OsmImporter.as
net/systemeD/potlatch2/utils/ShpImporter.as
potlatch2.mxml

index b88785431b66f679203cb2fd18fbb15e96c9e485..c96738c0f9a0e37b31cbc97184ba345c61401bb6 100644 (file)
@@ -22,7 +22,7 @@
       import net.systemeD.potlatch2.save.OAuthPanel;
       import net.systemeD.potlatch2.save.SaveDialog;
 
-      import net.systemeD.potlatch2.options.OptionsDialog;
+      import net.systemeD.potlatch2.dialogs.OptionsDialog;
 
       private function onLocaleChanged(event:Event):void {
           var rMngr : IResourceManager = ResourceManager.getInstance();
index 4b339d0e115b70c3519d5eb60ab3ece6ba48397c..9ae7f763804a1ed37fd390acb08ecef2202cbd15 100644 (file)
@@ -27,6 +27,7 @@
                import net.systemeD.halcyon.*;
                import net.systemeD.halcyon.connection.*;
                import net.systemeD.potlatch2.*;
+               import net.systemeD.potlatch2.dialogs.*;
                import net.systemeD.potlatch2.collections.Imagery;
                import mx.core.*;
                import mx.collections.ArrayCollection;
index 057e6f817730232910f6ef0b85d1e6f134f9dd7c..331dd04c8dd9ca75764c63aff95b616c9ae26b31 100644 (file)
@@ -18,6 +18,7 @@
                import net.systemeD.halcyon.connection.*;
                import net.systemeD.potlatch2.*;
                import net.systemeD.potlatch2.collections.Stylesheets;
+               import net.systemeD.potlatch2.dialogs.*;
                import mx.core.*;
     ]]></fx:Script>
 </mx:VBox>
index 446799b5537c9aeb0fa4ae6db0ac6f127ce3f4c5..0a8d61086548fd4d982f9a6800b0942e89a2952d 100644 (file)
@@ -72,13 +72,14 @@ package net.systemeD.potlatch2.collections {
                                                                                var gpx_url:String = String(set.url);
 
                                                                                var connection:Connection = new Connection(name, gpx_url, null, null);
-                                                                               var gpx:GpxImporter=new GpxImporter(connection, _map, [gpx_url],
+                                                                               var gpx:GpxImporter=new GpxImporter(connection, _map, 
                                                                                function(success:Boolean,message:String=null):void {
                                                                                        if (!success) return;
                                                                                        var paint:MapPaint = _map.addLayer(connection, "stylesheets/gpx.css");
                                                                                        paint.updateEntityUIs(false, false);
                                                                                        dispatchEvent(new Event("layers_changed"));
                                                                                }, false);
+                                                                               gpx.importFromRemoteFiles([gpx_url]);
                                                                        } else {
                                                                        trace("VectorBackgrounds: configured but not loaded isn't supported yet");
                                                                        }
similarity index 87%
rename from net/systemeD/potlatch2/BackgroundDialog.mxml
rename to net/systemeD/potlatch2/dialogs/BackgroundDialog.mxml
index 4c21149bcf385a106e9b8996a4d71ab64a4a8e97..dfca76ed40c6866a21c5e9698917dc5aa46ce112 100644 (file)
         <mx:DataGridColumn editable="false" headerText="Key" width="70">
                        <mx:itemRenderer>
                                <fx:Component>
-                               <mx:ComboBox
-                                       selectedItem="{FunctionKeyManager.instance().getKeyFor(outerDocument.title,data.name)}"
-                                   dataProvider="{FunctionKeyManager.fkeysCollection}"
-                                       change="FunctionKeyManager.instance().setKeyFromFString(selectedItem as String,outerDocument.title,data.name)" />
+                                       <mx:ComboBox
+                                               selectedItem="{FunctionKeyManager.instance().getKeyFor(outerDocument.title,data.name)}"
+                                           dataProvider="{FunctionKeyManager.fkeysCollection}"
+                                               change="FunctionKeyManager.instance().setKeyFromFString(selectedItem as String,outerDocument.title,data.name)">
+                                               <fx:Script><![CDATA[ import net.systemeD.potlatch2.FunctionKeyManager; ]]></fx:Script>
+                                       </mx:ComboBox>
                                </fx:Component>
                        </mx:itemRenderer>
                </mx:DataGridColumn>
similarity index 52%
rename from net/systemeD/potlatch2/VectorSourceDialog.mxml
rename to net/systemeD/potlatch2/dialogs/VectorSourceDialog.mxml
index 5f49e1042bf228653404cb851e4605f5549ad78c..615bd36df5b05726a84da333ff0a13fa02945b3a 100644 (file)
@@ -2,9 +2,10 @@
 <mx:TitleWindow
         xmlns:fx="http://ns.adobe.com/mxml/2009"
         xmlns:mx="library://ns.adobe.com/flex/mx"
+               xmlns:s="library://ns.adobe.com/flex/spark"
         layout="vertical" showCloseButton="true"
         horizontalAlign="center" title="Load vector file"
-        width="500" height="450" verticalGap="0">
+        width="630" height="450" verticalGap="0">
 
        <mx:DataGrid editable="true" width="100%" height="100%" id="dataGrid" 
                dataProvider="{vectorLayers}" itemEditEnd="dataEdited(event)">
                <mx:LinkButton label="Delete" click="removeLayer()" enabled="{dataGrid.selectedItem != null &amp;&amp; dataGrid.selectedItem.isBackground}"/>
        </mx:HBox>
 
-       <mx:VBox width="100%" paddingTop="10">
-               <mx:HRule width="100%" />
-               <!-- ** FIXME: this looks horrid - make into a nicely laid out form -->
-               <mx:Label text="Add new vector layer" fontSize="12" fontWeight="bold" />
-               <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:HBox>
-               <mx:HBox>
-                       <mx:Label text="Shapefile projection:" />
-                       <mx:ComboBox id="projection"> 
-                               <mx:ArrayCollection>
-                                       <fx:Object label="Lat/long" data="" />
+       <fx:Declarations>
+               <s:RadioButtonGroup id="filetype" />
+       </fx:Declarations>
+       <s:Form id="addlayer" width="100%">
+               <s:FormHeading label="Add new vector layer" />
+
+               <s:FormItem label="File type:">
+                       <s:HGroup>
+                               <s:RadioButton groupName="filetype" value="gpx" id="gpx" label="GPX" selected="true" />
+                               <s:RadioButton groupName="filetype" value="kml" id="kml" label="KML" />
+                               <s:RadioButton groupName="filetype" value="osm" id="osm" label="OSM" />
+                               <s:RadioButton groupName="filetype" value="shp" id="shp" label="Shapefile" />
+                       </s:HGroup>
+                       <s:helpContent><s:Label text="Type of data to load"/></s:helpContent>
+               </s:FormItem>
+
+               <s:FormItem label="Projection:">
+                       <s:DropDownList id="projection" selectedIndex="0" width="200"> 
+                               <s:ArrayCollection>
+                                       <fx:Object label="Lat/long (EPSG:4326)" data="" />
                                        <fx:Object label="Ordnance Survey GB" data="EPSG:27700" />
                                        <fx:Object label="NAD83" data="EPSG:4269" />
-                               </mx:ArrayCollection>
-                       </mx:ComboBox>
-                       <mx:CheckBox width="100%" label="Simplify paths" id="simplify" />
-               </mx:HBox>
-               <mx:HBox>
-                       <mx:Text text="URL:"/>
-                       <mx:TextInput width="100%" id="src" text="" change="selectByExtension()" />
-                       <mx:Button label="Load" click="loadFiles(src.text, filetype.selectedValue.toString(), simplify.selected, projection.selectedItem.data);" enabled="{src.text == '' ? false : true}"/>
-               </mx:HBox>
-               <mx:HBox>
-                       <mx:Text text="Tag transform:"/>
-                       <mx:TextInput width="100%" id="transformsrc" text="{CSSTransform.getInstance().url}"/>
-                       <mx:Button label="Load" click="loadTransform(transformsrc.text);" enabled="{transformsrc.text == '' ? false : true}"/>
-                       <mx:Button label="Clear" click="clearTransform();" enabled="{transformsrc.text == '' ? false : true}"/>
-               </mx:HBox>
-       </mx:VBox>
+                               </s:ArrayCollection>
+                       </s:DropDownList>
+                       <s:helpContent><s:Label text="Shapefiles only"/></s:helpContent>
+               </s:FormItem>
+
+               <s:FormItem label="Simplify:">
+                       <s:CheckBox label="Enabled" id="simplify" />
+                       <s:helpContent><s:Label text="Reduce points in paths"/></s:helpContent>
+               </s:FormItem>
+
+        <s:FormItem label="File:">
+                       <s:HGroup>
+                               <s:Button label="Open..." click="loadFileLocal()" />
+                               <s:Rect width="20" height="1" />
+                   <s:TextInput id="src" text="" change="selectByExtension()" />
+                               <s:Button label="Fetch" click="loadFiles(src.text);" enabled="{src.text == '' ? false : true}"/>
+                       </s:HGroup>
+            <s:helpContent><s:Label text="URL of file to load" /></s:helpContent>
+        </s:FormItem>
+
+        <s:FormItem label="Tag transform:">
+                       <s:HGroup>
+                               <s:Button label="Open..." click="loadTransformLocal()" />
+                               <s:Rect width="20" height="1" />
+                               <s:TextInput id="transformsrc" text="{CSSTransform.getInstance().url}"/>
+                               <s:Button label="Fetch" click="loadTransform(transformsrc.text);" enabled="{transformsrc.text == '' ? false : true}"/>
+                               <s:Button label="Clear" click="clearTransform();"                 enabled="{transformsrc.text == '' ? false : true}"/>
+                       </s:HGroup>
+            <s:helpContent><s:Label text="MapCSS transformation file" /></s:helpContent>
+        </s:FormItem>
+
+       </s:Form>
 
   <fx:Script><![CDATA[
 
        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);
                return v;
        }
        
+       private function get selectedType():String {
+               return filetype.selectedValue.toString();
+       }
+       
        private function toggleVisibility(event:Event):void {
                map.findLayer(dataGrid.selectedItem.name).visible = !map.findLayer(dataGrid.selectedItem.name).visible;
        }
         PopUpManager.removePopUp(this);
     }
 
-       private function loadFiles(url:String,type:String,simplify:Boolean,projection:String=""):void {
+       /** Launch importer for remotely hosted files. */
+       private function loadFiles(url:String):void {
                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 connection:Connection = new Connection(name, url, null, null, CSSTransform.getInstance());
-
-               var filesLoaded:Function = function(success:Boolean,message:String=null):void {
-                       if (success) {
-                               var paint:MapPaint = map.addLayer(connection, stylesheet);
-                               paint.updateEntityUIs(false, false);
-                               dispatchEvent(new Event("layers_changed"));
-                       } else {
-                               Alert.show(message, 'Error', mx.controls.Alert.OK);
-                       }
+               var importer:Importer = findImporter(connection);
+               if (selectedType=='shp') {
+                       var re:RegExp=/.shp$/i; url=url.replace(re,'');
+                       importer.importFromRemoteFiles([url+".shp",url+".shx",url+".dbf"]);
+               } else {
+                       importer.importFromRemoteFiles([url]);
                }
+       }
+       
+       /** Present an 'Open File' dialogue. */
+       private function loadFileLocal():void {
+               // note scoping issues - http://blog.wrench.com.au/2010/06/16/filereferenceload-keep-it-in-scope/
+               localFileReference=new FileReference(); 
+               var fileTypes:String=selectedType=='shp' ? "*.zip" : ("*.zip;*."+selectedType);
+               localFileReference.browse([new FileFilter(fileTypes,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(localFileReference.name, '', null, null, CSSTransform.getInstance());
+               var importer:Importer = findImporter(connection);
+               importer.importFromLocalFile(localFileReference);
+       }
+       
+       /** Create an Importer object of the type selected by the user. */
+       private function findImporter(connection:Connection):Importer {
+               var simplifyPath:Boolean=simplify.selected;
+               var reproject:String=projection.selectedItem.data;
+               var stylesheet:String="stylesheets/potlatch.css"; if (selectedType=='gpx') { stylesheet="stylesheets/gpx.css"; }
 
-               if (type=='gpx') {
-                       var gpx:GpxImporter=new GpxImporter(connection, map, [url], filesLoaded, simplify);
-               } else if (type=='kml') {
-                       var kml:KmlImporter=new KmlImporter(connection, map, [url], filesLoaded, simplify);
-               } else if (type=='osm') {
-                       var osm:OsmImporter=new OsmImporter(connection, map, [url], filesLoaded, simplify);
+               switch (selectedType) {
+                       case 'gpx':     return new GpxImporter(connection, map, filesLoaded, simplifyPath, { stylesheet: stylesheet });
+                       case 'kml':     return new KmlImporter(connection, map, filesLoaded, simplifyPath, { stylesheet: stylesheet });
+                       case 'osm': return new OsmImporter(connection, map, filesLoaded, simplifyPath, { stylesheet: stylesheet });
+                       case 'shp': return new ShpImporter(connection, map, filesLoaded, simplifyPath, { stylesheet: stylesheet, projection: reproject });
+               }
+               return null;
+       }
+       
+       /** Callback routine when import has completed. */
+       private function filesLoaded(connection:Connection,options:Object,success:Boolean,message:String=null):void {
+               if (success) {
+                       var paint:MapPaint = map.addLayer(connection, options['stylesheet']);
+                       paint.updateEntityUIs(false, false);
+                       dispatchEvent(new Event("layers_changed"));
                } else {
-                       /* FIXME: 
-                          we're currently hardcoding the projection values. We could populate this directly from 
-                          proj4as, or better still, parse the WKT in the .PRJ file:
-                                       http://trac.osgeo.org/proj4js/ticket/47
-                                       http://trac.osgeo.org/proj4js/changeset/1873
-                       */
-                       var re:RegExp=/.shp$/i; url=url.replace(re,'');
-                       var shp:ShpImporter=new ShpImporter(connection,
-                                                           map,
-                                                           [url+".shp",url+".shx",url+".dbf"], filesLoaded, simplify, projection);
+                       Alert.show(message, 'Error', mx.controls.Alert.OK);
                }
        }
        
+       /** Load CSS transformation file from remote URL. */
        private function loadTransform(url:String):void {
                CSSTransform.getInstance().loadFromUrl(url);
        }
+       /** Load CSS transformation file from local disc. */
+       private function loadTransformLocal():void {
+               localFileReference=new FileReference(); 
+               localFileReference.browse([new FileFilter("MapCSS file","*.css;*.mapcss")]); 
+               localFileReference.addEventListener(Event.SELECT, selectTransformLocal);
+       }
+       private function selectTransformLocal(event:Event):void {
+               localFileReference.addEventListener(Event.COMPLETE, transformFileLoaded);
+               localFileReference.load();
+       }
+       private function transformFileLoaded(event:Event):void {
+               CSSTransform.getInstance().loadFromUrl(event.target.data);
+       }
+       /** Cancel CSS transformation. */
        private function clearTransform():void {
                CSSTransform.getInstance().clear();
        }
index 5f0816c3cec636cae75cb5b07fc1e8d02947de8a..88dba75352d117206373d9d047a0e3ed535adb62 100644 (file)
@@ -12,8 +12,8 @@ package net.systemeD.potlatch2.utils {
     */
        public class GpxImporter extends Importer {
 
-               public function GpxImporter(connection:Connection, map:Map, filenames:Array, callback:Function=null, simplify:Boolean=false) {
-                       super(connection,map,filenames,callback,simplify);
+               public function GpxImporter(connection:Connection, map:Map, callback:Function=null, simplify:Boolean=false, options:Object=null) {
+                       super(connection,map,callback,simplify,options);
                }
 
                override protected function doImport(push:Function): void {
index 665e627f9d374921f94fc83f6bfae6611ffaa48d..c3ff6605073142c0177e2f67007ba08050641b0b 100644 (file)
@@ -7,6 +7,8 @@ package net.systemeD.potlatch2.utils {
        import flash.display.LoaderInfo;
        import flash.events.*;
        import flash.net.*;
+       import flash.utils.ByteArray;
+       import nochump.util.zip.*;
 
        public class Importer {
 
@@ -14,22 +16,25 @@ package net.systemeD.potlatch2.utils {
         protected var map:Map;                  // map being used - used only in Simplify calls
 
                public var files:Array=[];
-               protected var filenames:Array;
+               protected var filenames:Array;                  // array of filenames _or_ FileReference objects
                protected var filesloaded:uint=0;
                protected var callback:Function;
                protected var simplify:Boolean;
+               protected var options:Object;
 
-               public function Importer(connection:Connection, map:Map, filenames:Array, callback:Function, simplify:Boolean) {
+               public function Importer(connection:Connection, map:Map, callback:Function, simplify:Boolean, options:Object) {
                        this.connection = connection;
                        this.map = map;
-                       this.filenames=filenames;
                        this.callback=callback;
                        this.simplify=simplify;
-
+                       this.options=options;
+               }
+               
+               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(fn:String, index:int, array:Array):void {
+                       filenames.forEach(function(file:String, index:int, array:Array):void {
                                trace("requesting file "+index);
-                               var request:URLRequest = new URLRequest(fn);
                                var loader:URLLoader = new URLLoader();
                                loader.dataFormat=URLLoaderDataFormat.BINARY;
                                loader.addEventListener(Event.COMPLETE,function(e:Event):void { fileLoaded(e,index); });
@@ -37,27 +42,61 @@ package net.systemeD.potlatch2.utils {
                                        loader.addEventListener(SecurityErrorEvent.SECURITY_ERROR,      securityErrorHandler);
                                        loader.addEventListener(IOErrorEvent.IO_ERROR,                          ioErrorHandler);
                                }
-                               loader.load(request);
+                               loader.load(new URLRequest(file));
                        });
                }
                
-               protected function fileLoaded(e:Event,filenum:uint):void {
-                       files[filenum]=e.target.data;
-                       filesloaded++;
-                       trace("loaded file "+filenum+" ("+filesloaded+"/"+filenames.length+")"); 
-                       if (filesloaded==filenames.length) {
-                var action:CompositeUndoableAction = new CompositeUndoableAction("Import layer "+connection.name);
-                               doImport(action.push);
-                               action.doAction(); // just do it, don't add to undo stack
-                               if (callback!=null) { callback(true); }
+               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();
+               }
+               
+               protected function fileLoaded(e:Event,filenum:uint=0):void {
+                       var rawData:ByteArray=e.target.data;
+                       var firstFour:ByteArray=new ByteArray();
+                       rawData.readBytes(firstFour,0,4);
+                       rawData.position=0;
+                       
+                       if (firstFour.toString()=="PK"+String.fromCharCode(3)+String.fromCharCode(4)) {
+                               // Zip file (we assume there'll only be one of these...)
+                               var zip:ZipFile = new ZipFile(rawData);
+                               for (var i:uint=0; i<zip.entries.length; i++) {
+                                       filenames[i]=zip.entries[i].name;
+                                       files[i]=zip.getInput(zip.entries[i]);
+                                       filesloaded++;
+                               }
+                               runImporter();
+                       } else {
+                               // Standard file
+                               files[filenum]=rawData;
+                               filesloaded++;
+                               trace("loaded file "+filenum+" ("+filesloaded+"/"+filenames.length+")"); 
+                               if (filesloaded==filenames.length) { runImporter(); }
+                       }
+               }
+
+               private function runImporter():void {
+                       var action:CompositeUndoableAction = new CompositeUndoableAction("Import layer "+connection.name);
+                       doImport(action.push);
+                       action.doAction(); // just do it, don't add to undo stack
+                       if (callback!=null) { callback(connection,options,true); }
+               }
+
+               protected function getFileByName(regex:RegExp):* {
+                       for (var i:uint=0; i<filenames.length; i++) {
+                               if (filenames[i].match(regex)) { return files[i]; }
                        }
+                       return null;
                }
                
                protected function doImport(push:Function):void {
                }
 
-               protected function securityErrorHandler( event:SecurityErrorEvent ):void { callback(false,"You don't have permission to open that file."); }
-               protected function ioErrorHandler( event:IOErrorEvent ):void { callback(false,"The file could not be loaded."); }
+               protected function securityErrorHandler( event:SecurityErrorEvent ):void { callback(connection,options,false,"You don't have permission to open that file."); }
+               protected function ioErrorHandler( event:IOErrorEvent ):void { callback(connection,options,false,"The file could not be loaded."); }
 
        }
 }
index 302fa8f758bb357239d6592851a8cb8c00bbef8e..f5ebe5c14d148c89146eb550252967bed7b6c689 100644 (file)
@@ -13,8 +13,8 @@ package net.systemeD.potlatch2.utils {
      */
     public class KmlImporter extends Importer {
 
-        public function KmlImporter(connection:Connection, map:Map, filenames:Array, callback:Function=null, simplify:Boolean=false) {
-            super(connection, map, filenames, callback, simplify);
+        public function KmlImporter(connection:Connection, map:Map, callback:Function=null, simplify:Boolean=false, options:Object=null) {
+            super(connection, map, callback, simplify, options);
         }
 
         override protected function doImport(push:Function): void {
index 3e7b0c1a33d9eb4c356d996cacb35461effc4344..550024f5f84c0a1d5432cd0896a52a4bed5063ed 100644 (file)
@@ -6,8 +6,8 @@ package net.systemeD.potlatch2.utils {
 
        public class OsmImporter extends Importer {
 
-               public function OsmImporter(connection:Connection, map:Map, filenames:Array, callback:Function=null, simplify:Boolean=false) {
-                       super(connection,map,filenames,callback,simplify);
+               public function OsmImporter(connection:Connection, map:Map, callback:Function=null, simplify:Boolean=false, options:Object=null) {
+                       super(connection,map,callback,simplify,options);
                }
 
                override protected function doImport(push:Function):void {
index dd0cf6cee1a021af090aa35c9e5579dd34119d20..115ce404c24c7e4b51a819272f671f5ef8d47487 100644 (file)
@@ -8,20 +8,23 @@ package net.systemeD.potlatch2.utils {
        import net.systemeD.halcyon.connection.Node;
        import net.systemeD.halcyon.connection.Way;
        import net.systemeD.potlatch2.tools.Simplify;
+       import flash.utils.ByteArray;
 
        public class ShpImporter extends Importer {
 
                private var projection:String;
 
-               public function ShpImporter(connection:Connection, map:Map, filenames:Array, callback:Function=null, simplify:Boolean=false, projection:String="") {
-                       if (projection!='') this.projection=projection;
-                       super(connection,map,filenames,callback,simplify);
+               public function ShpImporter(connection:Connection, map:Map, callback:Function=null, simplify:Boolean=false, options:Object=null) {
+                       if (options[projection]) this.projection=options[projection];
+                       super(connection,map,callback,simplify,options);
                }
 
                override protected function doImport(push:Function): void {
                        // we load .shp as files[0], .shx as files[1], .dbf as files[2]
-                       var shp:ShpHeader=new ShpHeader(files[0]);
-                       var dbf:DbfHeader=new DbfHeader(files[2]);
+                       var shpFile:ByteArray=getFileByName(/.shp$/);
+                       var dbfFile:ByteArray=getFileByName(/.dbf$/);
+                       var shp:ShpHeader=new ShpHeader(shpFile);
+                       var dbf:DbfHeader=new DbfHeader(dbfFile);
 
                        if (projection) {
                                var proj:Proj4as=new Proj4as();
@@ -35,12 +38,12 @@ package net.systemeD.potlatch2.utils {
                        if (shp.shapeType==ShpType.SHAPE_POLYGON || shp.shapeType==ShpType.SHAPE_POLYLINE) {
 
                                // Loop through all polylines in the shape
-                               var polyArray:Array = ShpTools.readRecords(files[0]);
+                               var polyArray:Array = ShpTools.readRecords(shpFile);
                                for (var i:uint=0; i<polyArray.length; i++) {
 
                                        // Get attributes and create a tags hash
                                        // (note that dr.values is a Dictionary)
-                                       var dr:DbfRecord = DbfTools.getRecord(files[2], dbf, i);
+                                       var dr:DbfRecord = DbfTools.getRecord(dbfFile, dbf, i);
                                        var tags:Object={};
                                        for (key in dr.values) {
                                                v=dr.values[key];
index 32bc8d8a98143251e36bd9ea4e1943bf24b6b268..af5e5c4891e76f4c0ee4e53f8ec439e54822f128 100644 (file)
@@ -99,7 +99,7 @@
                import net.systemeD.potlatch2.collections.*;
                import net.systemeD.potlatch2.controller.*;
                import net.systemeD.potlatch2.help.*;
-               import net.systemeD.potlatch2.options.*;
+               import net.systemeD.potlatch2.dialogs.*;
                import net.systemeD.potlatch2.utils.*;
         import net.systemeD.potlatch2.mygpx.*;
                import net.systemeD.controls.FloatingAlert;
                 var gpx_url:String = loaderInfo.parameters['gpx_url'];
 
                 var connection:Connection = new Connection(name, gpx_url, null, null);
-                var gpx:GpxImporter=new GpxImporter(connection, theMap, [gpx_url],
+                var gpx:GpxImporter=new GpxImporter(connection, theMap,
                                                 function(success:Boolean,message:String=null):void {
                                                     if (!success) return;
                                                     var paint:MapPaint = theMap.addLayer(connection, "stylesheets/gpx.css");
                                                     paint.updateEntityUIs(false, false);
                                                     dispatchEvent(new Event("layers_changed"));
                                                 }, false);
+                               gpx.importFromRemoteFiles([gpx_url]);
                        }
 
                        // create GPS trackloader