compile fixes
[potlatch2.git] / net / systemeD / potlatch2 / utils / ShpImporter.as
index 88229aebf9c67e67fe392463d4f02aea1c970e53..bc3e742290de58adb709ffbde85f92ce7389f377 100644 (file)
@@ -1,31 +1,21 @@
 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.MapPaint;
        import net.systemeD.halcyon.Globals;
+       import net.systemeD.halcyon.connection.Node;
+       import net.systemeD.halcyon.connection.Way;
+       import net.systemeD.potlatch2.tools.Simplify;
 
-       // 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 class ShpImporter extends Importer {
 
-               public function ShpImporter(map:Map, filenames:Array) {
-                       super(map, filenames);
+               public function ShpImporter(container:*, paint:MapPaint, filenames:Array, callback:Function=null, simplify:Boolean=false) {
+                       super(container,paint,filenames,callback,simplify);
                }
-               
-               // All data is loaded, so do the import
 
-               override protected function doImport():void {
-                       Globals.vars.root.addDebug("importing");
+               override protected function doImport(): 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]);
 
@@ -33,28 +23,31 @@ package net.systemeD.potlatch2.utils {
 
                                // 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++) {
+                               for (var i:uint=0; i<polyArray.length; 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=[];
+                                       for (var j:int=0; j < polyArray[i].shape.rings.length; j++) {
+                                               var way:Way;
+                                               var nodestring:Array=[];
                                                var points:Array = polyArray[i].shape.rings[j];
                                                if (points!=null) {
-                                                       for (var k:int=0; k < Math.min(points.length,50); k++) {
+                                                       for (var k:int=0; k < points.length; 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);
+                                                               nodestring.push(container.createNode({}, p.y, p.x));
                                                        }
                                                }
-                                               if (nodes.length>0) { var way:Way = map.connection.createWay({}, nodes); }
+                                               if (nodestring.length>0) {
+                                                       way=container.createWay({}, nodestring);
+                                                       if (simplify) { Simplify.simplify(way, paint.map, false); }
+                                               }
                                        }
                                }
                        }
                }
+
        }
 }