Removed executable flag from files which don't need it.
[potlatch2.git] / net / systemeD / potlatch2 / mapfeatures / MapFeatures.as
index d9f64e5c99778655d059fd5d252e64fd7a7f7cdb..072d78a9a7660a4255042d0e684f7983e22e3893 100644 (file)
@@ -7,6 +7,9 @@ package net.systemeD.potlatch2.mapfeatures {
        import flash.system.Security;
        import flash.net.*;
 
+       import mx.core.UIComponent;
+       import mx.controls.DataGrid;
+
     import net.systemeD.halcyon.connection.*;
        import net.systemeD.halcyon.DebugURLRequest;
 
@@ -21,11 +24,11 @@ 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:DebugURLRequest = new DebugURLRequest("map_features.xml");
@@ -39,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 )
@@ -53,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;
         }
@@ -128,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;
+               }
+               
     }
 
 }