ADD reporting of lat/long of mouse cursor when you press L. This is in response to...
authorSteve Bennett <stevagewp@gmail.com>
Sat, 5 Feb 2011 13:44:56 +0000 (13:44 +0000)
committerSteve Bennett <stevagewp@gmail.com>
Sat, 5 Feb 2011 13:44:56 +0000 (13:44 +0000)
net/systemeD/halcyon/Map.as
net/systemeD/halcyon/MapEvent.as
potlatch2.mxml

index 65b5c57..492b57e 100644 (file)
@@ -100,6 +100,9 @@ package net.systemeD.halcyon {
                /** VectorLayer objects */
                public var vectorlayers:Object={};  
                
+               /** Should the position of mouse cursor be shown to the user? */
+               private var showingLatLon:Boolean=false;  
+               
                // ------------------------------------------------------------------------------------------
                /** Map constructor function */
         public function Map(initparams:Object) {
@@ -435,6 +438,11 @@ package net.systemeD.halcyon {
                private function reportPosition():void {
                        addDebug("lon "+coord2lon(mouseX)+", lat "+coord2lat(mouseY));
                }
+
+        private function toggleReportPosition():void {
+            showingLatLon = !showingLatLon;
+            this.dispatchEvent(new MapEvent(MapEvent.TOGGLE_LATLON, {latlon: showingLatLon}));
+        }
                
                /** Switch to new MapCSS. */
                public function setStyle(url:String):void {
@@ -521,7 +529,10 @@ package net.systemeD.halcyon {
                /** Respond to mouse movement, dragging the map if tolerance threshold met. */
                public function mouseMoveHandler(event:MouseEvent):void {
                        if (!_draggable) { return; }
-                       if (dragstate==NOT_DRAGGING) { return; }
+                       if (dragstate==NOT_DRAGGING) { 
+                          this.dispatchEvent(new MapEvent(MapEvent.MOUSEOVER, { x: coord2lon(mouseX), y: coord2lat(mouseY) }));
+               return; 
+            }
                        
                        if (dragstate==NOT_MOVED) {
                                if (new Date().getTime()-downTime<300) {
@@ -557,7 +568,7 @@ package net.systemeD.halcyon {
                                case Keyboard.UP:       moveMap(0,mapheight/2); break;           // up cursor
                                case Keyboard.RIGHT:    moveMap(-mapwidth/2,0); break;   // right cursor
                                case Keyboard.DOWN:     moveMap(0,-mapheight/2); break;      // down cursor
-//                             case 76:        reportPosition(); break;                        // L - report lat/long
+                               case 76:        toggleReportPosition(); break;                  // L - report lat/long
                        }
                }
 
index da51402..a51473f 100644 (file)
@@ -19,6 +19,8 @@ package net.systemeD.halcyon {
         public static const INITIALISED:String = "initialized";
                /** Backrgound imagery has changed to one with attribution that must not be obscured. */
                public static const BUMP:String = "bump";
+               public static const MOUSEOVER:String="mouseover";
+               public static const TOGGLE_LATLON:String="toggle_latlon";
                public static const ERROR:String = "error";                             // ** FIXME - this should be a dedicated ErrorEvent class
 
                /** Event-specific parameters. */
index 81dfce4..b0861e2 100644 (file)
@@ -68,6 +68,8 @@
         <mx:TextArea id="dataWorking" text="" right="20" top="3" disabledColor="black" backgroundDisabledColor="0xFFFFEA" height="18"
             enabled="false" borderThickness="0"
             showEffect="{wipeIn}" hideEffect="{wipeOut}"/>
+        <mx:TextArea id="coordsbox" left="0" top="0" disabledColor="black" backgroundDisabledColor="0xFFFFEA" height="33"
+            width="57" enabled="false" borderThickness="0" visible="false"/>
 
     </mx:Canvas>
 
             theController = new EditController(theMap, tagViewer, toolbox);
             theController.setActive();
             
+            theMap.addEventListener(MapEvent.MOUSEOVER, mouseoverHandler);
+            theMap.addEventListener(MapEvent.TOGGLE_LATLON, togglelatlonHandler);
+            
             var conn:Connection = Connection.getConnectionInstance();
             conn.addEventListener(Connection.LOAD_STARTED, onDataStart);
             conn.addEventListener(Connection.LOAD_COMPLETED, onDataComplete);
                        trace("showing alert with "+buttons);
                        Alert.show(mapEvent.params.message, 'Error', buttons, null, function(closeEvent:CloseEvent):void { 
                                switch (closeEvent.detail) {
-                                       case mx.controls.Alert.CANCEL:  mapEvent.params.cancel(); break;
+                                       case mx.controls.Alert.CANCEL:  mapEvent.params.cancel(); break; //fixme? this gets called if user presses escape, even if there's no cancel button.
                                        case mx.controls.Alert.YES:             mapEvent.params.yes(); break;
                                        case mx.controls.Alert.NO:              mapEvent.params.no(); break;
                                        default:                                                if (mapEvent.params.ok) mapEvent.params.ok();
                        }
                }
 
+        private function mouseoverHandler(e:MapEvent):void {
+            if (coordsbox.visible) {
+                coordsbox.text= Number(e.params.x).toFixed(5) + "\n " + Number(e.params.y).toFixed(5); // Not sure if 5 dp's really required.
+            }
+        }
+
+        private function togglelatlonHandler(e:MapEvent):void {
+            coordsbox.visible = e.params.latlon;
+        }
+
+
         private function onDataStart(event:Event):void {
                        switch (event.type) {
                                case Connection.LOAD_STARTED:   loadcount++; break;