geoman-io / leaflet-geoman

🍂🗺️ The most powerful leaflet plugin for drawing and editing geometry layers
https://geoman.io
MIT License
2.21k stars 433 forks source link

setButtonDisabled not working #1141

Closed satrock1 closed 2 years ago

satrock1 commented 2 years ago

Good afternoon, yesterday everything worked fine, the code did not change, but the error pops up. here is part of the code:

var optionsControl = {
        position: 'topleft', // toolbar position, options are 'topleft', 'topright', 'bottomleft', 'bottomright'
        drawMarker: true,  // adds button to draw markers
        drawPolygon: false,  // adds button to draw a polygon
        drawPolyline: false,  // adds button to draw a polyline
        drawCircle: false,  // adds button to draw a cricle
        editPolygon: false,  // adds button to toggle global edit mode
        deleteLayer: true,   // adds a button to delete layers
        cutPolygon: false,
        rotateMode: false,
        drawRectangle: false,
        drawCircleMarker: false,
    };

map.pm.Toolbar.setButtonDisabled('drawMarker', true);

If you remove the line map.pm.Toolbar.setButtonDisabled('drawMarker', true);, then there is no error, but this function is necessary. The error is like this: Uncaught TypeError: Cannot read properties of undefined (reading 'children') leaflet-geoman.min.js:1 at i._updateDisabled (leaflet-geoman.min.js:1:67669) at i.disable (leaflet-geoman.min.js:1:64799) at i.setButtonDisabled (leaflet-geoman.min.js:1:79813) at (индекс):2717:16

Falke-Design commented 2 years ago

We released yesterday version 2.12 you should revert back to 2.11.4.

In the demo it is working fine, can you please change it so that the error happens: https://jsfiddle.net/4fw25e0b/

satrock1 commented 2 years ago

looked at your jsfiddle and there was a line map.pm.addControls(optionsControl); which I did not have, and before the update the code worked without it. After adding this line everything worked, thanks!

Falke-Design commented 2 years ago

Bug description:

If map.pm.addControls() is not called but setButtonDisabled, then the container is not existing and then an error is thrown. https://jsfiddle.net/n6vk8eto/

Falke-Design commented 2 years ago

If map.pm.addControls() is not called but setButtonDisabled, then the container is not existing and then an error is thrown. https://jsfiddle.net/n6vk8eto/

@vvlladd28 do you want to fix this?

vvlladd28 commented 2 years ago

Hi @Falke-Design, I will fix this problem