Open mstenta opened 4 years ago
Dug into this, and it basically comes down to: there is only one layer
variable defined in the measure.js
behavior code: https://github.com/farmOS/farmOS-map/blob/d50daf5014039cda75345bd0ce34adc4475e1f5c/src/behavior/measure.js#L16
So whenever addBehavior('measure', { layer });
runs, it replaces the layer
that the behavior is looking at: https://github.com/farmOS/farmOS-map/blob/d50daf5014039cda75345bd0ce34adc4475e1f5c/src/behavior/measure.js#L128
Then, specifically, whenever stopMeasure()
runs, it goes through and removes any measure overlays with IDs that are not found in the layer. So because layer
gets overridden, it doesn't find any of the measures in the first layer, and removes them all: https://github.com/farmOS/farmOS-map/blob/d50daf5014039cda75345bd0ce34adc4475e1f5c/src/behavior/measure.js#L116
Similarly, I don't think the measure behavior would work with multiple maps, for the same reason.
If you try to add the measure behavior to multiple layers (eg: in the "current location" and "new location" layers in the animal move quick form map: https://www.drupal.org/project/farm/issues/3156713), it works at first (both layers show their measurements), but if you then try to edit a layer then the other one disappears.