From 7d0b613680d0a7eadeadd0a93165536e5b2e34a3 Mon Sep 17 00:00:00 2001 From: Richard Fairhurst Date: Sat, 9 Jan 2010 15:51:49 +0000 Subject: [PATCH] split ways by pressing X (needs a shiny button!) --- TODO.txt | 6 ++-- net/systemeD/halcyon/connection/Way.as | 7 +++++ .../potlatch2/controller/SelectedWayNode.as | 30 +++++++++++++++++++ 3 files changed, 41 insertions(+), 2 deletions(-) diff --git a/TODO.txt b/TODO.txt index 2c31e1e7..dd57efa0 100644 --- a/TODO.txt +++ b/TODO.txt @@ -1,5 +1,4 @@ Potlatch 2: main outstanding issues -(last updated 30th November 2009) ----------------------------------- == Code tidying == @@ -11,7 +10,7 @@ Potlatch 2: main outstanding issues == Core geometry == * Delete points and ways -* Split and merge ways +* Merge ways * Drag-and-drop POIs * Undo/redo * Reverse way direction @@ -26,6 +25,8 @@ Potlatch 2: main outstanding issues == Server interaction == +* Should redraw members of a relation when the relation is loaded + == UI == @@ -44,3 +45,4 @@ Potlatch 2: main outstanding issues (difficult because styles are decided before drawing) * Shields * Complete MapCSS support +* Would be useful to be able to 'suspend' redrawing diff --git a/net/systemeD/halcyon/connection/Way.as b/net/systemeD/halcyon/connection/Way.as index 735284c0..1abcbc3d 100644 --- a/net/systemeD/halcyon/connection/Way.as +++ b/net/systemeD/halcyon/connection/Way.as @@ -64,6 +64,13 @@ package net.systemeD.halcyon.connection { // ** we should send an event to delete the entire way } + public function sliceNodes(start:int,end:int):Array { + return nodes.slice(start,end); + } + + public function deleteNodesFrom(start:int):void { + nodes.splice(start); + } /** diff --git a/net/systemeD/potlatch2/controller/SelectedWayNode.as b/net/systemeD/potlatch2/controller/SelectedWayNode.as index c21e7722..fc151859 100644 --- a/net/systemeD/potlatch2/controller/SelectedWayNode.as +++ b/net/systemeD/potlatch2/controller/SelectedWayNode.as @@ -67,6 +67,13 @@ package net.systemeD.potlatch2.controller { return this; } + override public function processKeyboardEvent(event:KeyboardEvent):ControllerState { + switch (event.keyCode) { + case 88: return splitWay(); + } + return this; + } + override public function enterState():void { selectNode(initWay,initNode); Globals.vars.root.addDebug("**** -> "+this); @@ -90,5 +97,28 @@ package net.systemeD.potlatch2.controller { else return new DrawWay(selectedWay, isLast, true); } + + public function splitWay():ControllerState { + // abort if start or end + if (selectedWay.getNode(0 ) == selectedNode) { return this; } + if (selectedWay.getNode(selectedWay.length-1) == selectedNode) { return this; } + Globals.vars.root.addDebug("splitting way at "+selectedWay.indexOfNode(selectedNode)); + + // create new way + var newWay:Way = controller.connection.createWay( + selectedWay.getTagsCopy(), + selectedWay.sliceNodes(selectedWay.indexOfNode(selectedNode),selectedWay.length)); + selectedWay.deleteNodesFrom(selectedWay.indexOfNode(selectedNode)+1); + + // copy relations + for each (var r:Relation in selectedWay.parentRelations) { + // ** needs to copy roles as well + r.appendMember(new RelationMember(newWay, '')); + } + controller.map.ways[newWay.id].redraw(); + + return new SelectedWay(selectedWay); + } + } } -- 2.36.1