Removed executable flag from files which don't need it.
[potlatch2.git] / net / systemeD / potlatch2 / mapfeatures / MapFeatures.as
index 13428df1b01ee906f465280166f7db1f636f23f5..072d78a9a7660a4255042d0e684f7983e22e3893 100644 (file)
@@ -3,13 +3,15 @@ package net.systemeD.potlatch2.mapfeatures {
     import flash.events.EventDispatcher;
     import flash.events.Event;
     import flash.net.URLLoader;
-    import flash.net.URLRequest;
 
        import flash.system.Security;
        import flash.net.*;
 
-    import net.systemeD.halcyon.connection.*;
+       import mx.core.UIComponent;
+       import mx.controls.DataGrid;
 
+    import net.systemeD.halcyon.connection.*;
+       import net.systemeD.halcyon.DebugURLRequest;
 
        public class MapFeatures extends EventDispatcher {
         private static var instance:MapFeatures;
@@ -22,17 +24,17 @@ package net.systemeD.potlatch2.mapfeatures {
             return instance;
         }
 
-
-
         private var xml:XML = null;
         private var _features:Array = null;
         private var _categories:Array = null;
+//             private var _keys:Array = null;
+               private var _tags:Object = null;
 
         protected function loadFeatures():void {
-            var request:URLRequest = new URLRequest("map_features.xml?"+Math.random());
+            var request:DebugURLRequest = new DebugURLRequest("map_features.xml");
             var loader:URLLoader = new URLLoader();
             loader.addEventListener(Event.COMPLETE, onFeatureLoad);
-            loader.load(request);
+            loader.load(request.request);
         }
 
         internal function get definition():XML {
@@ -40,12 +42,22 @@ package net.systemeD.potlatch2.mapfeatures {
         }
         
         private function onFeatureLoad(event:Event):void {
+                       var f:Feature;
+
             xml = new XML(URLLoader(event.target).data);
-            
-            _features = new Array();
+            _features = [];
+                       _tags = { relation:{}, way:{}, node:{} };
+
             for each(var feature:XML in xml.feature) {
-                _features.push(new Feature(this, feature));
+                f=new Feature(this,feature);
+                               _features.push(f);
+                               for each (var tag:Object in f.tags) {
+                                       if (f.isType('line') || f.isType('area')) { addToTagList('way',tag); }
+                                       if (f.isType('relation'))                                 { addToTagList('relation',tag); }
+                                       if (f.isType('point'))                                    { addToTagList('node',tag); }
+                               }
             }            
+
             _categories = new Array();
             for each(var catXML:XML in xml.category) {
                 if ( catXML.child("category").length() == 0 )
@@ -54,6 +66,12 @@ package net.systemeD.potlatch2.mapfeatures {
             dispatchEvent(new Event("featuresLoaded"));
         }
 
+               private function addToTagList(type:String,tag:Object):void {
+                       if (tag.v=='*') { return; }
+                       if (!_tags[type][tag.k]) { _tags[type][tag.k]=new Array(); }
+                       if (_tags[type][tag.k].indexOf(tag.v)==-1) { _tags[type][tag.k].push(tag.v); }
+               }
+
         public function hasLoaded():Boolean {
             return xml != null;
         }
@@ -129,6 +147,29 @@ package net.systemeD.potlatch2.mapfeatures {
             }
             return pois;
         }
+
+               [Bindable(event="featuresLoaded")]
+               public function getAutoCompleteKeys(type:String):Array {
+                       var list:Array=[];
+                       var a:Array=[];
+
+                       for (var k:String in _tags[type]) { list.push(k); }
+                       list.sort();
+
+                       for each (k in list) { a.push( { name: k } ); }
+                       return a;
+               }
+               
+               [Bindable(event="featuresLoaded")]
+               public function getAutoCompleteValues(type:String,key:String):Array {
+                       var a:Array=[];
+                       if (_tags[type][key]) {
+                               _tags[type][key].sort();
+                               for each (var v:String in _tags[type][key]) { a.push( { name: v } ); }
+                       }
+                       return a;
+               }
+               
     }
 
 }