I need to add locators dynamically to different sets.
With one set this works OK:
Manipulate[
Graphics[{Point@pts}, PlotRange -> {{0, 1}, {0, 1}}],
Control[{{pts, {RandomReal[1, 2]}}, ControlType -> Locator}],
Row[{
Button["Add L1", pts = pts~Join~{RandomReal[1, 2]}]}],
Dynamic@pts]
But when I try to use more than one set, it doesn't:
Manipulate[ (*fails*)
Graphics[{Point@pts, Point@ptsNA}, PlotRange -> {{0, 1}, {0, 1}}],
Control[{{pts, {RandomReal[1, 2]}}, ControlType -> Locator}],
Control[{{ptsNA, {RandomReal[1, 2]}}, ControlType -> Locator}],
Row[{
Button["Add L1", pts = pts~Join~{RandomReal[1, 2]}],
Button["Add LNA", ptsNA = ptsNA~Join~{RandomReal[1, 2]}]}],
Dynamic@pts, Dynamic@ptsNA]
I could work out my way by adding all locators to the same set and manually assigning them to one "set" or another, but in my real application I have to add a different number of locators to each set at a time and also be able to delete them, so that complicates the code.
Edit
Thanks to Sjoerd's comment in another question, I found this limitation is covered in the documentation:
Due to internal limitations, it is not possible to combine individual Locator variables with a variable that is a list of multiple Locator variables: you can have only one multipoint Locator variable in a Manipulate. However, in exchange, it is possible to add the option LocatorAutoCreate->True to that one Locator multivariable specification, and thereby allow you to create and destroy Locator points interactively (changing the length of the list of points stored in the variable).
So, no hope using Manipulate[]
, accepting jVincent's answer.
LocatorPane
, however nesting multiple locator panes won't work out, so it starts acting weird. $\endgroup$