[07:46:05] | <mstenta[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. |
[07:46:38] | <mstenta[m]> | We don't have a `removeBehavior()` method, either (I don't think?) - so can't remove and re-add the `Edit` behavior. |
[07:47:29] | <mstenta[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). |
[07:51:54] | <mstenta[m]> | Or alternatively maybe we could just implement that in core. |
[09:50:45] | <symbioquine[m]> | <mstenta[m]> "symbioquine: Do you know if..." <- I think you could access it via `instance.edit.layer`... |
[09:51:09] | <symbioquine[m]> | https://github.com/farmOS/farmOS-map/blob/777758f7218499e2211c5d75c1faf3... |
[09:53:30] | <symbioquine[m]> | <mstenta[m]> "Use-case: USDA wants to be..." <- Yeah, I've thought it should work that way in general :) |
[10:13:10] | <mstenta[m]> | > I think you could access it via instance.edit.layer... |
[10:13:11] | <mstenta[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... |
[10:13:56] | <mstenta[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) |
[10:15:20] | <mstenta[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. |
[10:15:45] | <mstenta[m]> | So we may need to add some support for this in farmOS-map itself. |
[10:16:20] | <mstenta[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. |
[10:16:35] | <mstenta[m]> | But I admit I'm a bit rusty on all the map code, so I may be overlooking something obvious. |
[10:19:53] | <symbioquine[m]> | I think you can do it pretty easily... |
[10:21:38] | <symbioquine[m]> | Just; |
[10:21:38] | <symbioquine[m]> | 1. use the `instance.addWKTLayer` and then remove it from the map (but keep the layer reference) |
[10:21:39] | <symbioquine[m]> | 2. Remove all the existing features from the `instance.edit.layer` layer |
[10:21:39] | <symbioquine[m]> | 3. Add all the features from the temporary WKT layer to the `instance.edit.layer` layer |
[10:23:13] | <symbioquine[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 |
[10:24:09] | <symbioquine[m]> | You can remove the temporary WKT layer from the map with `instance.map.removeLayer`; https://openlayers.org/en/latest/apidoc/module-ol_PluggableMap-Pluggable... |
[11:10:49] | <mstenta[m]> | Thanks symbioquine let me give that a try... |
[11:28:32] | <mstenta[m]> | symbioquine: working great!! |
[11:28:48] | <mstenta[m]> | Only one small (and strange) issue... |
[11:29:08] | <mstenta[m]> | `instance.map.removeLayer(layer)` doesn't seem to work (to remove the temporary WKT layer) |
[11:29:34] | <mstenta[m]> | no error or anything... but the layer still shows in the layer switcher and can still be toggled on |
[11:29:46] | <mstenta[m]> | Here's the full code, in case you see anything wrong... |
[11:29:49] | <mstenta[m]> | ACTION sent a code block: https://libera.ems.host/_matrix/media/r0/download/libera.chat/1a1313c600... |
[11:30:21] | <mstenta[m]> | * (function () {... (full message at https://libera.ems.host/_matrix/media/r0/download/libera.chat/1647c07372...) |
[11:30:44] | <mstenta[m]> | * ```... (full message at https://libera.ems.host/_matrix/media/r0/download/libera.chat/1ea7f5a3ad...) |
[11:31:35] | <symbioquine[m]> | If you call `instance.map.getLayers()` is it still in there? |
[11:32:18] | <symbioquine[m]> | Maybe that `removeLayer` function can't remove it from within a group? |
[11:32:49] | <mstenta[m]> | Checking... |
[11:32:53] | <mstenta[m]> | It's not in a group |
[11:32:58] | <symbioquine[m]> | oh, ok |
[11:33:28] | <mstenta[m]> | hmm trying to remember how to read these structures to see if hte layer is still there... |
[11:35:11] | <symbioquine[m]> | try `instance.map.getLayers().getArray()` |
[11:37:50] | <mstenta[m]> | ahh... no it does get removed from that list |
[11:38:02] | <mstenta[m]> | but it's still in the map 🤔 |
[11:39:00] | <symbioquine[m]> | When you say still in the map... how can you tell? |
[11:39:07] | <symbioquine[m]> | Just from the layer switcher? |
[11:39:17] | <symbioquine[m]> | I wonder if we're running into some sort of bug there... |
[11:39:21] | <mstenta[m]> | it still shows in the layerswitcher and can be toggled on/off (i set it to `invisible: false` in `addLayer()`) |
[11:39:33] | <mstenta[m]> | OH WAIT |
[11:39:55] | <mstenta[m]> | hold on... this time when i toggled it in the layer switcher it disappeared from the layer switcher |
[11:40:01] | <mstenta[m]> | testing more... |
[11:40:43] | <mstenta[m]> | ok hmmm ... yea nevermind - it IS basically working... it just seems that the layerswitcher is not being updated |
[11:40:53] | <mstenta[m]> | until you try to enable the layer, then it disappears from the layerswitcher list |
[11:41:20] | <symbioquine[m]> | https://github.com/walkermatt/ol-layerswitcher/issues/98 |
[11:41:29] | <symbioquine[m]> | https://github.com/walkermatt/ol-layerswitcher/issues/357 |
[11:42:02] | <symbioquine[m]> | https://github.com/walkermatt/ol-layerswitcher/issues/16 |
[11:42:21] | <mstenta[m]> | ah interesting! |
[11:42:23] | <symbioquine[m]> | Kinda dancing around the problem, but related |
[11:42:25] | <mstenta[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.` |
[11:42:32] | <mstenta[m]> | s/`/> /, s/.`/./ |
[11:42:36] | <symbioquine[m]> | yeah |
[11:42:41] | <mstenta[m]> | lemme try that... |
[11:44:00] | <symbioquine[m]> | Something like `instance.map.getControls().getArray().find(c => typeof c.renderPanel === 'function').renderPanel()`? |
[11:44:15] | <mstenta[m]> | wow you're brilliant |
[11:44:24] | <mstenta[m]> | many steps ahead of me |
[11:44:25] | <mstenta[m]> | :-) |
[11:44:30] | <symbioquine[m]> | 🦆 typing to the rescue :) |
[11:45:27] | <mstenta[m]> | `instance.map.getControls().getArray().find(...)` |
[11:45:49] | <mstenta[m]> | * `instance.map.getControls().getArray().find(...) is undefined` |
[11:46:26] | <symbioquine[m]> | Weird |
[11:46:43] | <symbioquine[m]> | hmmm |
[11:47:05] | <symbioquine[m]> | symbioquine[m]: Could break if there's multiple/no controls with a `renderPanel` method. Might be better to do; |
[11:47:05] | <symbioquine[m]> | ```js |
[11:47:05] | <symbioquine[m]> | instance.map.getControls().getArray().filter(c => typeof c.renderPanel === 'function').forEach(c => c.renderPanel()); |
[11:47:05] | <symbioquine[m]> | ``` |
[11:48:18] | <mstenta[m]> | no error with that, but still no dice |
[11:48:31] | <mstenta[m]> | meh this is pretty good by itself though - maybe doesn't need to be perfect |
[11:48:34] | <mstenta[m]> | i gotta run |
[11:48:54] | <mstenta[m]> | thanks so much for your help symbioquine |
[11:49:19] | <symbioquine[m]> | ACTION uploaded an image: (81KiB) < https://libera.ems.host/_matrix/media/r0/download/matrix.org/stMWSzqrhPZ... > |
[11:50:00] | <symbioquine[m]> | Maybe the issue is that when the layer switcher is in the side-panel it isn't registered with OpenLayers as a Control? |
[11:51:32] | <symbioquine[m]> | I think we should change [this](https://github.com/farmOS/farmOS-map/blob/777758f7218499e2211c5d75c1faf3...) to honor more kinds of layer changes... |
[11:55:19] | <symbioquine[m]> | Opened https://github.com/farmOS/farmOS-map/issues/174 |
[11:59:09] | <mstenta[m]> | Ah |