Choose whether layers are interactive (i.e. objects can be selected). After all,...
authorRichard Fairhurst <richard@systemeD.net>
Wed, 15 Jun 2011 10:45:54 +0000 (11:45 +0100)
committerRichard Fairhurst <richard@systemeD.net>
Wed, 15 Jun 2011 10:45:54 +0000 (11:45 +0100)
net/systemeD/halcyon/Map.as
net/systemeD/halcyon/MapPaint.as
net/systemeD/potlatch2/VectorSourceDialog.mxml
net/systemeD/potlatch2/controller/ControllerState.as
net/systemeD/potlatch2/utils/BugLoader.as

index 9dcb118ac6b408c374700c2b7e0b2f6267f42c77..5054ac1609379291326a149bda19a5e403c5061d 100644 (file)
@@ -245,10 +245,11 @@ package net.systemeD.halcyon {
                // ------------------------------------------------------------------------------------------
                // Add layers
                
-               public function addLayer(connection:Connection, styleurl:String, backgroundlayer:Boolean=true):MapPaint {
+               public function addLayer(connection:Connection, styleurl:String, backgroundlayer:Boolean=true, interactive:Boolean=false):MapPaint {
                        var paint:MapPaint=new MapPaint(this, connection, styleurl, -5, 5);
                        paintContainer.addChild(paint);
                        paint.isBackground=backgroundlayer;
+                       paint.interactive=interactive;
                        return paint;
                }
 
index 8206aefe252ae5e049203bd2fd94d85f5be8e7d7..c1fb5a6e84b2f9bc47123549318f36cf6bb3fa26 100644 (file)
@@ -31,6 +31,8 @@ package net.systemeD.halcyon {
         private var markeruis:Object=new Object();
         /** Is this a background layer or the core paint object? */
                public var isBackground:Boolean = true;
+               /** Can the user select entities in this layer? */
+               public var interactive:Boolean = false;
                /** Hash of index->position */
                public var sublayerIndex:Object={};
 
index f2ee64c566a54207485d2da4ff26c3a91c0c2122..42a61d0017f120397659649642e9c93cb5bad8e9 100644 (file)
@@ -3,12 +3,12 @@
         xmlns:mx="http://www.adobe.com/2006/mxml" 
         layout="vertical" showCloseButton="true"
         horizontalAlign="center" title="Load vector file"
-        width="400" height="350" verticalGap="0">
+        width="500" height="350" verticalGap="0">
 
        <mx:DataGrid editable="true" width="100%" height="100%" id="dataGrid" 
                dataProvider="{vectorLayers}" itemEditEnd="dataEdited(event)">
            <mx:columns>
-               <mx:DataGridColumn editable="false" dataField="visible" headerText="Show" width="45">
+               <mx:DataGridColumn editable="false" dataField="visible" headerText="Show?" width="45">
                                <mx:itemRenderer>
                                        <mx:Component>
                                                <mx:CheckBox selectedField="isSelected"
                                        </mx:Component>
                                </mx:itemRenderer>
                        </mx:DataGridColumn>
+               <mx:DataGridColumn editable="false" dataField="interactive" headerText="Select?" width="45">
+                               <mx:itemRenderer>
+                                       <!-- There should really be a way to hide this for the editable layer. See
+                                            http://stackoverflow.com/questions/6329895/how-do-i-change-the-style-of-one-individual-cell-in-a-flex-datagrid 
+                                            Leave it as a FIXME until we move to Flex 4 -->
+                                       <mx:Component>
+                                               <mx:CheckBox selectedField="isInteractive"
+                                                                        click="data.isInteractive=!data.isInteractive; this.parent.parent.dispatchEvent(new Event('interactive_changed'));" 
+                                                            paddingLeft="5"/>
+                                       </mx:Component>
+                               </mx:itemRenderer>
+                       </mx:DataGridColumn>
                <mx:DataGridColumn editable="true"  dataField="name"  headerText="Name"/>
                <mx:DataGridColumn editable="false" dataField="url"   headerText="URL"/>
                <mx:DataGridColumn editable="false" dataField="style" headerText="Style">
         PopUpManager.centerPopUp(this);
         this.addEventListener(CloseEvent.CLOSE, vectorDialog_close);
                dataGrid.addEventListener("visibility_changed", toggleVisibility);
+               dataGrid.addEventListener("interactive_changed", toggleInteractive);
                map = Globals.vars.root;
                dispatchEvent(new Event("layers_changed"));
     }
        private function get vectorLayers():Array {
         var v:Array=[];
         for each (var a:MapPaint in map.getLayers() ) {
-            v.push( { name:a.connection.name, visible:a.visible, url:a.connection.apiBase, style:a.style, isBackground:a.isBackground } );
+            v.push( { name:a.connection.name, visible:a.visible, interactive:a.interactive, url:a.connection.apiBase, style:a.style, isBackground:a.isBackground } );
         }
                return v;
        }
        private function toggleVisibility(event:Event):void {
                map.findLayer(dataGrid.selectedItem.name).visible = !map.findLayer(dataGrid.selectedItem.name).visible;
        }
+
+       private function toggleInteractive(event:Event):void {
+               map.findLayer(dataGrid.selectedItem.name).interactive = !map.findLayer(dataGrid.selectedItem.name).interactive;
+       }
        
        private function dataEdited(event:DataGridEvent):void {
                if (event.dataField=='name') {
index f6f00a9c7c5d69a76174c735a86b0caa419b49dd..ad8ac7f45d6a664190e3e80c1c20a3e6469a770f 100644 (file)
@@ -99,11 +99,10 @@ package net.systemeD.potlatch2.controller {
                                        var newEntity:Entity=paint.pullThrough(entity,editableLayer);
                                        if      (entity is Way ) { return new SelectedWay(newEntity as Way); }
                                        else if (entity is Node) { return new SelectedPOINode(newEntity as Node); }
-                } else if (event.type == MouseEvent.MOUSE_DOWN && entity is Marker) {
-                    return new SelectedMarker(entity as Marker, paint);
-                } else if (event.type == MouseEvent.MOUSE_DOWN) {
-                    if      (entity is Way ) { return new SelectedBackgroundWay(entity as Way); }
-                    else if (entity is Node) { return new SelectedBackgroundNode(entity as Node, paint); }
+                } else if (event.type == MouseEvent.MOUSE_DOWN && paint.interactive) {
+                    if      (entity is Way   ) { return new SelectedBackgroundWay(entity as Way); }
+                    else if (entity is Node  ) { return new SelectedBackgroundNode(entity as Node, paint); }
+                                       else if (entity is Marker) { return new SelectedMarker(entity as Marker, paint); }
                                } else if ( event.type == MouseEvent.MOUSE_UP ) {
                                        return (this is NoSelection) ? null : new NoSelection();
                                } else { return null; }
index 7cb6bf40e2997009bf8903fe9be0268a8d5a808a..4c6f08bb12eebc200a23a2761c9c2fd38173e178 100644 (file)
@@ -31,7 +31,7 @@ package net.systemeD.potlatch2.utils {
 
         public function load():void {
             if (!_layer) {
-                _layer = map.addLayer(connection, STYLESHEET);
+                _layer = map.addLayer(connection, STYLESHEET, true, true);
             }
             connection.loadBbox(map.edge_l, map.edge_r, map.edge_t, map.edge_b);
         }