Open rabbl opened 6 months ago
I'm facing a similar issue, for me the onCreate handler is called twice for every shape that is added (including the first one). I'm not updating any state in the onCreate callback. I've tried with just logging out whenever the onCreate is called and it is still called twice.
Dear Derick, I am experiencing a strange and for me unwanted issue that I'd like to understand better and debug deeper.
Background: I am using Leaflet and Geoman to draw Geojson-Element on the map and sending them after creation via an API-Call to the server to do stuff there. After creating one element, the Geoman-Controls are not rendered until the user clicks a button to add another Shape. After drawing a shape, the "Geoman-Cache" should be cleared.
Bug description: For the first element it works as expected. When I'm adding another element, the onCreate-Handler ist executed multiple times with the same Layer Information.
Here is a screenshot of the console. The first element triggers once. Every next element triggers multiple times.
Reproduction of this bug: To reproduce this bug, this example can be used. I removed all handlers except onCreate.
Using the onCreate handler of
<GeomanControls>
creating the first Shape (e.g. a polygon), the handler will be called once. Creating the next element, the handler will be called twice, but with the same information.After debugging some more time, I found that when I remove
setGeojson(newGeo)
it triggers only once. It seems, that changes in the geojson also trigger geoman-handlers somehow.Side Note: In our implementation it triggers the onChange handler as much as I have added Shapes. So, on adding the 30th shape, the handler will be executed 30 times.
Can you give me an idea, further information or a link how to debug and understand this issue better? Possibly there is a conceptual misunderstanding from my side here.
My main questions here are:
How can I prevent to trigger the onChange Handler multiple times? How it's possible in my implementation that onChange is triggered "the total number of added shapes" times? Is is possible to debug this more deeply?
I appreciate a lot your help here :). Best regards, Ralf