don't bother redrawing EntityUIs that are offscreen
[potlatch2.git] / net / systemeD / potlatch2 / utils / Importer.as
1 package net.systemeD.potlatch2.utils {
2
3         import net.systemeD.halcyon.MapPaint;
4         import net.systemeD.halcyon.ExtendedURLLoader;
5         import flash.net.URLLoader;
6         import flash.display.LoaderInfo;
7         import flash.events.*;
8         import flash.net.*;
9
10         import net.systemeD.halcyon.Globals;
11
12         public class Importer {
13
14                 protected var container:Object;                         // destination object for way/node/relations data
15                 protected var paint:MapPaint;                           // destination sprite for WayUIs/NodeUIs
16
17                 public var files:Array=[];
18                 protected var filenames:Array;
19                 protected var filesloaded:uint=0;
20                 protected var callback:Function;
21                 protected var simplify:Boolean;
22
23                 public function Importer(container:*, paint:MapPaint, filenames:Array, simplify:Boolean) {
24                         Globals.vars.root.addDebug("starting importer"); 
25                         Globals.vars.root.addDebug("container is "+container);
26                         Globals.vars.root.addDebug("paint is "+paint);
27                         this.container = container;
28                         this.paint = paint;
29                         this.filenames=filenames;
30                         this.simplify=simplify;
31
32                         var sp:uint=0;
33                         for each (var fn:String in filenames) {
34                                 Globals.vars.root.addDebug("requesting file "+fn); 
35
36                                 var loader:ExtendedURLLoader = new ExtendedURLLoader();
37                                 loader.info['file']=sp;
38                                 loader.dataFormat=URLLoaderDataFormat.BINARY;
39                                 loader.addEventListener(Event.COMPLETE,                                         fileLoaded);
40                                 loader.addEventListener(HTTPStatusEvent.HTTP_STATUS,            httpStatusHandler);
41                                 loader.addEventListener(SecurityErrorEvent.SECURITY_ERROR,      securityErrorHandler);
42                                 loader.addEventListener(IOErrorEvent.IO_ERROR,                          ioErrorHandler);
43                                 loader.load(new URLRequest(fn));
44                                 sp++;
45                         }
46                 }
47                 
48                 protected function fileLoaded(e:Event):void {
49                         Globals.vars.root.addDebug("loaded file "+e.target.info['file']); 
50                         files[e.target.info['file']]=e.target.data;
51                         filesloaded++;
52                         if (filesloaded==filenames.length) { 
53                                 doImport();
54                                 paint.updateEntityUIs(container.getObjectsByBbox(paint.map.edge_l, paint.map.edge_r, paint.map.edge_t, paint.map.edge_b), false, false);
55                         }
56                 }
57                 
58                 protected function doImport():void {
59                 }
60
61                 protected function httpStatusHandler( event:HTTPStatusEvent ):void { Globals.vars.root.addDebug("httpstatusevent"); }
62                 protected function securityErrorHandler( event:SecurityErrorEvent ):void { Globals.vars.root.addDebug("securityerrorevent"); }
63                 protected function ioErrorHandler( event:IOErrorEvent ):void { Globals.vars.root.addDebug("ioerrorevent"); }
64
65         }
66 }