[Potlatch-dev] Development note - selections, ControllerStates and event listeners

Richard Fairhurst richard at systemeD.net
Wed Nov 3 15:10:23 GMT 2010


This is here partly for Andy and Dave and anyone else who hacks on the  
P2 source, and partly for me as an aide-memoire. :)

I've refactored a bunch of the selection code in preparation for  
allowing multiple selection one day. (See  
http://trac.openstreetmap.org/changeset/24040/applications/editors/potlatch2  
.)

The ControllerStates now have a _selection property. This is an array  
containing all the selected objects. It replaces the previous  
selectedWay and selectedNode.

There are various setters and getters in ControllerState.as. In  
particular, for single object ControllerStates (which are all that  
exist right now), you will want to use the firstSelected getter, and  
cast it as a Node or Way if required.

So where previously you'd have used
     node = selectedNode
you now use
     node = firstSelected as Node
or alternatively
     node = Node(firstSelected)

There may be regressions as a result so let me know if you spot any.


Secondly, while working on this, I think I figured out a big P2 bug.  
There have been several reports of shift-click to insert a node  
stopping working, and of course we have the long-standing issue where  
WayUIs occasionally hang around between zoom levels.

This appears to be because WayUIs weren't being destroyed when they  
should be; and that's partly because event listeners need to be  
expressly removed, otherwise they prevent an object from being garbage  
collected. (You can also use setWeakReference when you do  
addEventListener, but it's neater to remove them manually.)

There were some other bugs that showed up too. But (and like I say,  
this is here as an aide-memoire for me as much as anything) make sure  
you remove any event listeners you've added!

cheers
Richard




More information about the Potlatch-dev mailing list