Open paul121 opened 2 years ago
I feel that we should follow the patterns that OpenLayers has established and keep farmOS-map's behavior as unsurprising as possible when OL functionality is used programmatically.
In practice I think that means you're highlighting some real issues here @paul121.
IMHO we should;
interaction.setActive(false)
and set instance.edit.drawInteraction
to null
when finishing/cancelling drawingactive
property and honor programmatic changes to it
Right now I'm not sure if there is an easy way to determine if any of the edit interactions are currently "active". This would be useful when adding custom behaviors that should/should not do certain things when a user is using interactions from the edit control, like drawing on the map.
An interaction object is added to
instance.edit
the first time it is turned on, but is never removed. This can be used to see if an interaction has been used by looking on theinstance.edit
control eg:instance.edit.drawInteraction
orinstance.edit.modifyInteraction
, but because it is never removed, it cannot be used to determine if the interaction is "active".Interestingly, interaction objects do have a
getActive()
method, but our edit control does not use this: https://openlayers.org/en/latest/apidoc/module-ol_interaction_Interaction-Interaction.html#getActive Instead of making the interaction "inactive" it removes the interaction from the map, but keeps the interaction object itself atinstance.edit.*
. The interaction object continues to reportgetActive() == true
even after the interaction was removed from the map.After a quick look at this I see two possible approaches:
Remove the interaction object from
instance.edit
after removing the interaction from the map. This way the presence of the interaction object can be used to determine if it is active. https://github.com/farmOS/farmOS-map/blob/65f13b2cd9a36f4b211ec9211e2532b4fcf29d48/src/control/Edit/Edit.js#L423-L444Refactor the edit control to use the "active" state of interactions instead of adding/removing interactions from the map. At first glance it seems like this might be feasible, but I'm not 100% sure. See also #183
Finally, it would be nice if the edit control provided some helper methods to determine if any part of the edit control "is active". This could be a convenience method wrapped around one of the approaches described above. For example: