Permalink
Browse files

Merge branch 'localfile'

  • Loading branch information...
2 parents 9ae8cb6 + 05ae3de commit 582accb4f2ee3a7d50f4b48129be62c2d54fef46 @systemed systemed committed Mar 25, 2012
@@ -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();
@@ -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;
@@ -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>
@@ -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");
}
@@ -13,10 +13,12 @@
<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>
@@ -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)">
@@ -49,40 +50,60 @@
<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[
@@ -102,6 +123,7 @@
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);
@@ -139,6 +161,10 @@
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;
}
@@ -177,46 +203,79 @@
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();
}
@@ -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 {
Oops, something went wrong.

0 comments on commit 582accb

Please sign in to comment.