< 262022-07-27⋎28 >

Topic for #farmOS is: farmOS (farmos.org) is a free and open source, web-based farm management system. User guide: farmos.org/guide/ - Forum: farmOS.discourse.groupSet by mstenta on 2021-06-15 at 12:52
11:46mstenta[m]symbioquine: Do you know if there's any way for one behavior to modify the "Drawing" layer (of the `Edit` control)? I did something similar (with a non-edit layer) by simply deleting and re-adding a new layer via `addLayer()` but it seems that approach won't work with the `Edit` control.
11:46mstenta[m]We don't have a `removeBehavior()` method, either (I don't think?) - so can't remove and re-add the `Edit` behavior.
11:47mstenta[m]Use-case: USDA wants to be able to manually edit/modify/delete/paste into the WKT text field below the map and have those changes show up on the map (this would be nice as a core feature perhaps, but for now I'm just trying to see if I can get it to work in a standalone behavior).
11:51mstenta[m]Or alternatively maybe we could just implement that in core.
13:50symbioquine[m]<mstenta[m]> "symbioquine: Do you know if..." <- I think you could access it via `instance.edit.layer`...
13:51symbioquine[m]github.com/farmOS/farmOS-map/blob/777758
13:53symbioquine[m]<mstenta[m]> "Use-case: USDA wants to be..." <- Yeah, I've thought it should work that way in general :)
14:13mstenta[m]> I think you could access it via instance.edit.layer...
14:13mstenta[m]Ah yea maybe... would need to make sure it gets wired up everywhere that's needed if the behavior deletes and recreates that layer though...
14:13mstenta[m]And I think that's the only way to replace the geometry with new WKT (given that we don't have public access to all the OL methods)
14:15mstenta[m]Implementing this in core might not be any easier, though... unless we're talking about changes to both farmOS core and farmOS-map itself. In farmOS core it would still need to be possible to do this within a behavior, since the `wkt` and `input` behaviors are the main options we have to work with.
14:15mstenta[m]So we may need to add some support for this in farmOS-map itself.
14:16mstenta[m]And maybe that would be in the form of some general-purpose helpers for modifying the geometry in a layer. Then we wouldn't need to delete/recreate layers in general. Which would help in the other case I worked on, and in this case with the drawing layer.
14:16mstenta[m]But I admit I'm a bit rusty on all the map code, so I may be overlooking something obvious.
14:19symbioquine[m]I think you can do it pretty easily...
14:21symbioquine[m]Just;
14:21symbioquine[m]1. use the `instance.addWKTLayer` and then remove it from the map (but keep the layer reference)
14:21symbioquine[m]2. Remove all the existing features from the `instance.edit.layer` layer
14:21symbioquine[m]3. Add all the features from the temporary WKT layer to the `instance.edit.layer` layer
14:23symbioquine[m]might need to do something to avoid an infinite loop where the layer changes triggers the text box to change which triggers the layer to change
14:24symbioquine[m]You can remove the temporary WKT layer from the map with `instance.map.removeLayer`; openlayers.org/en/latest/apidoc/module-o
15:10mstenta[m]Thanks symbioquine let me give that a try...
15:28mstenta[m]symbioquine: working great!!
15:28mstenta[m]Only one small (and strange) issue...
15:29mstenta[m]`instance.map.removeLayer(layer)` doesn't seem to work (to remove the temporary WKT layer)
15:29mstenta[m]no error or anything... but the layer still shows in the layer switcher and can still be toggled on
15:29mstenta[m]Here's the full code, in case you see anything wrong...
15:29*sent a code block: libera.ems.host/_matrix/media/r0/downloa
15:30mstenta[m] * (function () {... (full message at libera.ems.host/_matrix/media/r0/downloa)
15:30mstenta[m] * ```... (full message at libera.ems.host/_matrix/media/r0/downloa)
15:31symbioquine[m]If you call `instance.map.getLayers()` is it still in there?
15:32symbioquine[m]Maybe that `removeLayer` function can't remove it from within a group?
15:32mstenta[m]Checking...
15:32mstenta[m]It's not in a group
15:32symbioquine[m]oh, ok
15:33mstenta[m]hmm trying to remember how to read these structures to see if hte layer is still there...
15:35symbioquine[m]try `instance.map.getLayers().getArray()`
15:37mstenta[m]ahh... no it does get removed from that list
15:38mstenta[m]but it's still in the map 🤔
15:39symbioquine[m]When you say still in the map... how can you tell?
15:39symbioquine[m]Just from the layer switcher?
15:39symbioquine[m]I wonder if we're running into some sort of bug there...
15:39mstenta[m]it still shows in the layerswitcher and can be toggled on/off (i set it to `invisible: false` in `addLayer()`)
15:39mstenta[m]OH WAIT
15:39mstenta[m]hold on... this time when i toggled it in the layer switcher it disappeared from the layer switcher
15:40mstenta[m]testing more...
15:40mstenta[m]ok hmmm ... yea nevermind - it IS basically working... it just seems that the layerswitcher is not being updated
15:40mstenta[m]until you try to enable the layer, then it disappears from the layerswitcher list
15:41symbioquine[m]github.com/walkermatt/ol-layerswitcher/i
15:41symbioquine[m]github.com/walkermatt/ol-layerswitcher/i
15:42symbioquine[m]github.com/walkermatt/ol-layerswitcher/i
15:42mstenta[m]ah interesting!
15:42symbioquine[m]Kinda dancing around the problem, but related
15:42mstenta[m]`If for some reason you need to force the layer switcher to refresh after making changes to the layers you can call `renderPanel` on your layer switcher instance.`
15:42mstenta[m]s/`/> /, s/.`/./
15:42symbioquine[m]yeah
15:42mstenta[m]lemme try that...
15:44symbioquine[m]Something like `instance.map.getControls().getArray().find(c => typeof c.renderPanel === 'function').renderPanel()`?
15:44mstenta[m]wow you're brilliant
15:44mstenta[m]many steps ahead of me
15:44mstenta[m]:-)
15:44symbioquine[m]🦆 typing to the rescue :)
15:45mstenta[m]`instance.map.getControls().getArray().find(...)`
15:45mstenta[m] * `instance.map.getControls().getArray().find(...) is undefined`
15:46symbioquine[m]Weird
15:46symbioquine[m]hmmm
15:47symbioquine[m]symbioquine[m]: Could break if there's multiple/no controls with a `renderPanel` method. Might be better to do;
15:47symbioquine[m]```js
15:47symbioquine[m]instance.map.getControls().getArray().filter(c => typeof c.renderPanel === 'function').forEach(c => c.renderPanel());
15:47symbioquine[m]```
15:48mstenta[m]no error with that, but still no dice
15:48mstenta[m]meh this is pretty good by itself though - maybe doesn't need to be perfect
15:48mstenta[m]i gotta run
15:48mstenta[m]thanks so much for your help symbioquine
15:49*uploaded an image: (81KiB) < libera.ems.host/_matrix/media/r0/downloa >
15:50symbioquine[m]Maybe the issue is that when the layer switcher is in the side-panel it isn't registered with OpenLayers as a Control?
15:51symbioquine[m]I think we should change [this](github.com/farmOS/farmOS-map/blob/777758) to honor more kinds of layer changes...
15:55symbioquine[m]Opened github.com/farmOS/farmOS-map/issues/174
15:59mstenta[m]Ah

< 262022-07-27⋏28 >