permit GPS tracks to be cleared from the usual menu. Fixes #3492
authorRichard Fairhurst <richard@systemed.net>
Tue, 8 Mar 2011 14:09:46 +0000 (14:09 +0000)
committerTom Hughes <tom@compton.nu>
Wed, 9 Mar 2011 11:28:01 +0000 (11:28 +0000)
net/systemeD/halcyon/Map.as
net/systemeD/potlatch2/VectorSourceDialog.mxml
net/systemeD/potlatch2/utils/TrackLoader.as
potlatch2.mxml

index eb3b154..793ea83 100644 (file)
@@ -386,6 +386,20 @@ package net.systemeD.halcyon {
                        vectorlayers[layer.name]=layer;
                        vectorbg.addChild(layer.paint);
                }
+               
+               public function removeVectorLayer(layer:VectorLayer):void {
+                       if (!layer) return;
+                       layer.blank();
+                       vectorbg.removeChild(layer.paint);
+                       delete vectorlayers[layer.name];
+               }
+               
+               public function findVectorLayer(name:String):VectorLayer {
+                       for each (var layer:VectorLayer in vectorlayers) {
+                               if (layer.name==name) { return layer; }
+                       }
+                       return null;
+               }
 
                // ------------------------------------------------------------------------------------------
                // Redraw all items, zoom in and out
index 776753a..ba04157 100644 (file)
        }
 
        private function removeVectorLayer():void {
-               var a:String=dataGrid.selectedItem.name;
-               map.vectorlayers[a].blank();
-               delete map.vectorlayers[a];
+               map.removeVectorLayer(map.vectorlayers[dataGrid.selectedItem.name]);
                dispatchEvent(new Event("layers_changed"));
        }
     
index 7dee3cf..d4bc6ec 100644 (file)
@@ -17,7 +17,6 @@ package net.systemeD.potlatch2.utils {
                private var top:Number=0;
                private var bottom:Number=0;
                private var page:uint=0;
-               private var _layer:VectorLayer;
 
                private var map:Map;
                private var apiBaseURL:String;
@@ -75,14 +74,13 @@ package net.systemeD.potlatch2.utils {
                        layer.paint.updateEntityUIs(layer.getObjectsByBbox(left,right,top,bottom), false, false);
                }
 
-               
                private function get layer():VectorLayer {
-                       if (!_layer) {
-                               var n:String='GPS tracks';
-                               _layer=new VectorLayer(n,map,STYLESHEET);
-                               map.addVectorLayer(_layer);
+                       var vl:VectorLayer=map.findVectorLayer('GPS tracks');
+                       if (!vl) {
+                               vl=new VectorLayer('GPS tracks',map,STYLESHEET);
+                               map.addVectorLayer(vl);
                        }
-                       return _layer;
+                       return vl;
                }
                
                private function greatCircle(lat1:Number,lon1:Number,lat2:Number,lon2:Number):Number {
index 200408a..c8b210b 100644 (file)
         <mx:PopUpButton id="styleButton" label="Map Style" openAlways="true" styleName="appBarButton"
             creationComplete="styleButton.popUp = new StyleSelector();"/>
                <mx:PopUpMenuButton id="gpsButton" styleName="appBarButton"
-                   itemClick="if (event.index==0) { trackLoader.load(); } else { new MyGpxDialog().init(); }">
+                   itemClick="if (event.index==0) { trackLoader.load(); } 
+                         else if (event.index==1) { new MyGpxDialog().init(); } 
+                                             else { mx.controls.Menu(gpsButton.popUp).selectedIndex=0; 
+                                                    mx.controls.Menu(gpsButton.popUp).selectedIndex=0; /* Yes, we do need to call it twice */
+                                                    theMap.removeVectorLayer(theMap.findVectorLayer('GPS tracks')); }">
                        <mx:dataProvider>
                                <mx:Array>
                                        <mx:Object label="GPS data" />
                                        <mx:Object label="My tracks" />
+                                       <mx:Object label="Clear" />
                                </mx:Array>
                        </mx:dataProvider>
                </mx:PopUpMenuButton>