Permalink
Browse files

start of vector import support

  • Loading branch information...
1 parent 2d2525a commit e574c1968a88f0086df6ddc4c4f99915254a9f9b @systemed committed Dec 17, 2009
@@ -0,0 +1,19 @@
+package net.systemeD.halcyon {
+
+ /*
+ === ExtendedURLLoader ===
+
+ This simply allows us to store arbitrary data (e.g. a filename) in the URLLoader object,
+ so that the responder knows which image has just been loaded.
+
+ */
+
+ import flash.events.*;
+ import flash.net.*;
+ import flash.display.*;
+
+ public class ExtendedURLLoader extends URLLoader {
+ public var info:Object=new Object();
+ }
+
+}
@@ -1,19 +0,0 @@
-package net.systemeD.halcyon {
-
- /*
- === ImageLoader ===
-
- This simply allows us to store a filename in the URLLoader object,
- so that the responder knows which image has just been loaded.
-
- */
-
- import flash.events.*;
- import flash.net.*;
- import flash.display.*;
-
- public class ImageURLLoader extends URLLoader {
- public var filename:*;
- }
-
-}
@@ -17,7 +17,7 @@ package net.systemeD.halcyon {
import net.systemeD.halcyon.connection.EntityEvent;
import net.systemeD.halcyon.styleparser.*;
import net.systemeD.halcyon.Globals;
-
+
// for experimental export function:
// import flash.net.FileReference;
// import com.adobe.images.JPGEncoder;
@@ -5,8 +5,6 @@ package net.systemeD.halcyon {
import flash.net.*;
import flash.system.LoaderContext;
- import net.systemeD.halcyon.ImageURLLoader;
-
public class TileSet extends Sprite {
public var tile_l:int;
@@ -10,6 +10,7 @@ package net.systemeD.halcyon.connection {
private var modified:Boolean = false;
private var _loaded:Boolean = true;
private var parents:Dictionary = new Dictionary();
+ private var locked:Boolean = false;
public function Entity(id:Number, version:uint, tags:Object, loaded:Boolean) {
this._id = id;
@@ -3,7 +3,7 @@ package net.systemeD.halcyon.styleparser {
import flash.events.*;
import flash.net.*;
import net.systemeD.halcyon.Map;
- import net.systemeD.halcyon.ImageURLLoader;
+ import net.systemeD.halcyon.ExtendedURLLoader;
import net.systemeD.halcyon.connection.Entity;
import net.systemeD.halcyon.connection.*;
@@ -82,9 +82,9 @@ package net.systemeD.halcyon.styleparser {
iconsToLoad++;
var request:URLRequest=new URLRequest(filename);
- var loader:ImageURLLoader=new ImageURLLoader();
+ var loader:ExtendedURLLoader=new ExtendedURLLoader();
loader.dataFormat=URLLoaderDataFormat.BINARY;
- loader.filename=filename;
+ loader.info['filename']=filename;
loader.addEventListener(Event.COMPLETE, loadedImage, false, 0, true);
loader.addEventListener(HTTPStatusEvent.HTTP_STATUS, httpStatusHandler, false, 0, true);
loader.addEventListener(SecurityErrorEvent.SECURITY_ERROR, securityErrorHandler, false, 0, true);
@@ -97,7 +97,7 @@ package net.systemeD.halcyon.styleparser {
// data handler
private function loadedImage(event:Event):void {
- images[event.target.filename]=event.target.data;
+ images[event.target.info['filename']]=event.target.data;
iconsToLoad--;
if (iconsToLoad==0 && iconCallback!=null) { iconCallback(); }
}
@@ -0,0 +1,53 @@
+package net.systemeD.potlatch2.utils {
+
+ import net.systemeD.halcyon.Map;
+ import net.systemeD.halcyon.ExtendedURLLoader;
+ import flash.display.LoaderInfo;
+ import flash.events.*;
+ import flash.net.*;
+
+ import net.systemeD.halcyon.Globals;
+
+ public class Importer {
+
+ protected var map:Map;
+ protected var files:Array=[];
+ protected var filenames:Array;
+ protected var filesloaded:uint=0;
+
+ public function Importer(map:Map, filenames:Array) {
+ Globals.vars.root.addDebug("starting importer");
+ this.map = map;
+ this.filenames=filenames;
+
+ var sp:uint=0;
+ for each (var fn:String in filenames) {
+ Globals.vars.root.addDebug("requesting file "+fn);
+
+ var loader:ExtendedURLLoader = new ExtendedURLLoader();
+ loader.info['file']=sp;
+ loader.dataFormat=URLLoaderDataFormat.BINARY;
+ loader.addEventListener(Event.COMPLETE, fileLoaded, false, 0, true);
+ loader.addEventListener(HTTPStatusEvent.HTTP_STATUS, httpStatusHandler, false, 0, true);
+ loader.addEventListener(SecurityErrorEvent.SECURITY_ERROR, securityErrorHandler, false, 0, true);
+ loader.addEventListener(IOErrorEvent.IO_ERROR, ioErrorHandler, false, 0, true);
+ loader.load(new URLRequest(fn));
+ sp++;
+ }
+ }
+
+ protected function fileLoaded(e:Event):void {
+ Globals.vars.root.addDebug("loaded file "+e.target.info['file']);
+ files[e.target.info['file']]=e.target.data;
+ filesloaded++;
+ if (filesloaded==filenames.length) { doImport(); }
+ }
+
+ protected function doImport():void { }
+
+ protected function httpStatusHandler( event:HTTPStatusEvent ):void { }
+ protected function securityErrorHandler( event:SecurityErrorEvent ):void { Globals.vars.root.addDebug("securityerrorevent"); }
+ protected function ioErrorHandler( event:IOErrorEvent ):void { Globals.vars.root.addDebug("ioerrorevent"); }
+
+ }
+}
@@ -0,0 +1,60 @@
+package net.systemeD.potlatch2.utils {
+
+ import net.systemeD.halcyon.Map;
+ import net.systemeD.halcyon.connection.*;
+ import org.vanrijkom.shp.*;
+ import org.vanrijkom.dbf.*;
+
+ import net.systemeD.halcyon.Globals;
+
+ // SHP class docs and examples:
+ // http://vanrijkom.org/shp/index.html
+ // http://www.boxshapedworld.com/blog/post/Shapefiles-Actionscript-30-and-Google-Maps.aspx
+ // http://web.archive.org/web/20071119113250rn_1/vanrijkom.org/samples/fsd-mexico/srcview/
+ // we load .shp as files[0], .shx as files[1], .dbf as files[2]
+
+ // See http://www.actionscript.org/forums/showthread.php3?t=185320 for tips on avoiding time-outs with big files -
+ // probably needs to be asynchronous
+
+ public class ShpImporter extends Importer {
+
+ public function ShpImporter(map:Map, filenames:Array) {
+ super(map, filenames);
+ }
+
+ // All data is loaded, so do the import
+
+ override protected function doImport():void {
+ Globals.vars.root.addDebug("importing");
+ var shp:ShpHeader=new ShpHeader(files[0]);
+ var dbf:DbfHeader=new DbfHeader(files[2]);
+
+ 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]);
+ for (var i:uint=0; i<Math.min(polyArray.length,50); i++) {
+
+ // Get attributes like this:
+ // var dr:DbfRecord = DbfTools.getRecord(files[2], dbf, i);
+ // var xsID:String = dr.values[idFieldName];
+
+ // Do each ring in turn, then each point in the ring
+ for (var j:int=0; j < Math.min(polyArray[i].shape.rings.length,50); j++) {
+ var nodes:Array=[];
+ var points:Array = polyArray[i].shape.rings[j];
+ if (points!=null) {
+ for (var k:int=0; k < Math.min(points.length,50); k++) {
+ var p:ShpPoint = ShpPoint(points[k]);
+ var node:Node = map.connection.createNode({}, p.y, p.x);
+ nodes.push(node);
+ Globals.vars.root.addDebug("point "+p.x+","+p.y);
+ }
+ }
+ if (nodes.length>0) { var way:Way = map.connection.createWay({}, nodes); }
+ }
+ }
+ }
+ }
+ }
+}
@@ -0,0 +1,45 @@
+/* ************************************************************************ */
+/* */
+/* DBF (XBase File Reader) */
+/* Copyright (c)2007 Edwin van Rijkom */
+/* http://www.vanrijkom.org */
+/* */
+/* This library is free software; you can redistribute it and/or */
+/* modify it under the terms of the GNU Lesser General Public */
+/* License as published by the Free Software Foundation; either */
+/* version 2.1 of the License, or (at your option) any later version. */
+/* */
+/* This library is distributed in the hope that it will be useful, */
+/* but WITHOUT ANY WARRANTY; without even the implied warranty of */
+/* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU */
+/* Lesser General Public License or the LICENSE file for more details. */
+/* */
+/* ************************************************************************ */
+
+package org.vanrijkom.dbf
+{
+
+/**
+ * Instances of the DbfError class are thrown from the DBF library classes
+ * on encountering errors.
+ * @author Edwin van Rijkom
+ *
+ */
+public class DbfError extends Error
+{
+ /**
+ * Defines the identifier value of an undefined error.
+ */
+ public static const ERROR_UNDEFINED : int = 0;
+ /**
+ * Defines the identifier value of a 'out of bounds' error, which is thrown
+ * when an invalid item index is passed.
+ */
+ public static const ERROR_OUTOFBOUNDS : int = 1;
+
+ public function DbfError(msg: String, id: int=0) {
+ super(msg,id);
+ }
+}
+
+} // package
@@ -0,0 +1,101 @@
+/* ************************************************************************ */
+/* */
+/* DBF (XBase File Reader) */
+/* Copyright (c)2007 Edwin van Rijkom */
+/* http://www.vanrijkom.org */
+/* */
+/* This library is free software; you can redistribute it and/or */
+/* modify it under the terms of the GNU Lesser General Public */
+/* License as published by the Free Software Foundation; either */
+/* version 2.1 of the License, or (at your option) any later version. */
+/* */
+/* This library is distributed in the hope that it will be useful, */
+/* but WITHOUT ANY WARRANTY; without even the implied warranty of */
+/* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU */
+/* Lesser General Public License or the LICENSE file for more details. */
+/* */
+/* ************************************************************************ */
+
+package org.vanrijkom.dbf
+{
+
+import flash.utils.ByteArray;
+import flash.utils.Endian;
+
+/**
+ * The DbfField class parses a field definition from a DBF file loaded to a
+ * ByteArray.
+ * @author Edwin van Rijkom
+ *
+ */
+public class DbfField
+{
+ /**
+ * Field name.
+ */
+ public var name: String;
+ /**
+ * Field type.
+ */
+ public var type: uint;
+ /**
+ * Field address.
+ */
+ public var address: uint;
+ /**
+ * Field lenght.
+ */
+ public var length: uint;
+ /**
+ * Field decimals.
+ */
+ public var decimals: uint;
+ /**
+ * Field id.
+ */
+ public var id: uint;
+ /**
+ * Field set flag.
+ */
+ public var setFlag: uint;
+ /**
+ * Field index flag.
+ */
+ public var indexFlag: uint;
+
+ /**
+ * Constructor.
+ * @param src
+ * @return
+ *
+ */
+ public function DbfField(src: ByteArray) {
+
+ name = DbfTools.readZeroTermANSIString(src);
+
+ // fixed length: 10, so:
+ src.position += (10-name.length);
+
+ type = src.readUnsignedByte();
+ address = src.readUnsignedInt();
+ length = src.readUnsignedByte();
+ decimals = src.readUnsignedByte();
+
+ // skip 2:
+ src.position += 2;
+
+ id = src.readUnsignedByte();
+
+ // skip 2:
+ src.position += 2;
+
+ setFlag = src.readUnsignedByte();
+
+ // skip 7:
+ src.position += 7;
+
+ indexFlag = src.readUnsignedByte();
+ }
+}
+
+} // package
Oops, something went wrong.

0 comments on commit e574c19

Please sign in to comment.