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