package net.systemeD.halcyon {
- import flash.text.TextField;
- import flash.geom.Rectangle;
- import flash.display.DisplayObjectContainer;
import flash.display.Loader;
import flash.display.Sprite;
- import flash.display.Shape;
- import flash.display.Stage;
- import flash.display.BitmapData;
- import flash.display.LoaderInfo;
- import flash.text.Font;
- import flash.utils.ByteArray;
import flash.events.*;
+ import flash.external.ExternalInterface;
+ import flash.geom.Rectangle;
import flash.net.*;
- import flash.external.ExternalInterface;
-
- import net.systemeD.halcyon.connection.*;
- import net.systemeD.halcyon.connection.EntityEvent;
- import net.systemeD.halcyon.styleparser.*;
- import net.systemeD.halcyon.Globals;
+ import flash.text.Font;
+ import flash.text.TextField;
import flash.ui.Keyboard;
+
+ import net.systemeD.halcyon.connection.*;
+ import net.systemeD.halcyon.styleparser.*;
// for experimental export function:
// import flash.net.FileReference;
updateEntityUIs(false,false);
download();
}
+
+ /** Recentre map at given lat/lon, if that point is currently outside the visible area. */
+ public function scrollIfNeeded(lat:Number,lon:Number): void{
+ if (lat> edge_t || lat < edge_b || lon < edge_l || lon > edge_r) {
+ moveMapFromLatLon(lat, lon);
+ }
+
+ }
// Co-ordinate conversion functions
controller.map.setHighlight(nextNode, { selectedway: true });
// recentre the map if the new lat/lon is offscreen
- if (nextNode.lat > controller.map.edge_t ||
- nextNode.lat < controller.map.edge_b ||
- nextNode.lon < controller.map.edge_l ||
- nextNode.lon > controller.map.edge_r) {
- controller.map.moveMapFromLatLon(nextNode.lat, nextNode.lon);
- }
+ controller.map.scrollIfNeeded(nextNode.lat,nextNode.lon);
}
override public function enterState():void {
package net.systemeD.potlatch2.controller {
import flash.events.*;
- import flash.display.DisplayObject;
- import flash.ui.Keyboard;
import flash.geom.Point;
- import net.systemeD.potlatch2.EditController;
- import net.systemeD.potlatch2.tools.Parallelise;
- import net.systemeD.potlatch2.tools.Quadrilateralise;
- import net.systemeD.potlatch2.tools.Simplify;
- import net.systemeD.halcyon.connection.*;
- import net.systemeD.halcyon.MapPaint;
- import net.systemeD.halcyon.WayUI;
+ import flash.ui.Keyboard;
+
import net.systemeD.halcyon.Globals;
+ import net.systemeD.halcyon.WayUI;
+ import net.systemeD.halcyon.connection.*;
+ import net.systemeD.potlatch2.tools.Quadrilateralise;
+ import net.systemeD.potlatch2.tools.Simplify;
/** Behaviour that takes place while a way is selected includes: adding a node to the way, straightening/reshaping the way, dragging it. */
public class SelectedWay extends ControllerState {
protected var initWay:Way;
private var clicked:Point; // did the user enter this state by clicking at a particular point?
private var wayList:Array; // list of ways to cycle through with '/' keypress
+ private var initIndex: int; // index of last selected node if entered from SelectedWayNode
/**
* @param way The way that is now selected.
* @param point The location that was clicked.
* @param ways An ordered list of ways sharing a node, to make "way cycling" work. */
- public function SelectedWay(way:Way, point:Point=null, ways:Array=null) {
+ public function SelectedWay(way:Way, point:Point=null, ways:Array=null, index:int=0) {
initWay = way;
clicked = point;
wayList = ways;
+ initIndex=index;
}
private function updateSelectionUI(e:Event):void {
case 191: /* / */ return cycleWays();
case Keyboard.BACKSPACE:
case Keyboard.DELETE: if (event.shiftKey) { return deleteWay(); } break;
+ case 188: /* , */ return new SelectedWayNode(initWay, initIndex); // allows navigating from one way to another by keyboard
+ case 190: /* . */ return new SelectedWayNode(initWay, initIndex); // using <, > and /
+
}
var cs:ControllerState = sharedKeyboardEvents(event);
return cs ? cs : this;
}
}
wayList=wayList.slice(1).concat(wayList[0]);
- return new SelectedWay(wayList[0], clicked, wayList);
+ // Find the new way's index of the currently "selected" node, to facilitate keyboard navigation
+ var newindex:int = Way(wayList[0]).indexOfNode(initWay.getNode(initIndex));
+ return new SelectedWay(wayList[0], clicked, wayList, newindex);
}
/** Perform deletion of currently selected way. */
case 74: if (event.shiftKey) { return unjoin() }; return join();// 'J'
case Keyboard.BACKSPACE: return deleteNode();
case Keyboard.DELETE: return deleteNode();
+ case 188: /* , */ return stepNode(-1);
+ case 190: /* . */ return stepNode(+1);
}
var cs:ControllerState = sharedKeyboardEvents(event);
return cs ? cs : this;
public function get selectedNode():Node {
return parentWay.getNode(selectedIndex);
}
-
-
+
private function cycleWays():ControllerState {
var wayList:Array=firstSelected.parentWays;
if (wayList.length==1) { return this; }
wayList.splice(wayList.indexOf(parentWay),1);
+ // find index of this node in the newly selected way, to maintain state for keyboard navigation
+ var newindex:int = Way(wayList[0]).indexOfNode(parentWay.getNode(initIndex));
return new SelectedWay(wayList[0],
new Point(controller.map.lon2coord(Node(firstSelected).lon),
controller.map.latp2coord(Node(firstSelected).latp)),
- wayList.concat(parentWay));
+ wayList.concat(parentWay),
+ newindex);
}
override public function enterState():void {
map.connection.dispatchEvent(new AttentionEvent(AttentionEvent.ALERT, null, msg));
return new SelectedWayNode(n.parentWays[0], Way(n.parentWays[0]).indexOfNode(n));
}
+
+ /** Move the selection one node further up or down this way, looping if necessary. */
+ public function stepNode(delta:int):ControllerState {
+ var ni:int = (selectedIndex + delta + parentWay.length) % parentWay.length
+ controller.map.scrollIfNeeded(parentWay.getNode(ni).lat,parentWay.getNode(ni).lon);
+ return new SelectedWayNode(parentWay, ni);
+ }
+
}
+
+
}