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

controlsVisible shows false when draw control is showing #965

Closed gmarshall56 closed 3 years ago

gmarshall56 commented 3 years ago

Hello:

In my code, when it is determined that the Leaftlet map is present, I set map the map draw control on the map but set it to hidden as such: map.pm.addControls( mapOptions ); map.pm.toggleControls(); //Toggle Draw control to hide

Eventually in my code I toggle the draw control so that it shows.

Also, later in my code I will disable all but one draw control button.

Now I noticed, after this activity when I query map.pm.controlsVisible(), it returns false, while the draw control is showing on the map. See here: geomanDrawCtlVisibleFalse

Could this be happening because I have disabled some of the draw control buttons?

Thank you for your time.

UPDATE: Yes, that is what appears to be happening:

  1. Put the draw tool on the map with all buttons enabled.
  2. console.info(map.pm.controlsVisible()); => returns "true:
  3. Disable a draw tool drawing button with this code as an example: map.pm.Toolbar.setButtonDisabled('drawMarker', false);
  4. console.info(map.pm.controlsVisible()); => returns "false"

Is there a way to determine if the draw tool is showing on the map even if there are buttons in the draw tool that have been disabled?

Thank you

Falke-Design commented 3 years ago

Thanks for reporting this issue. This will be already fixed with #956

As workaround you can use this:

var visible = map.pm.controlsVisible();
map.pm.Toolbar.setButtonDisabled('drawMarker', false);
map.pm.Toolbar.isVisible= visible;
gmarshall56 commented 3 years ago

To expand on this issue:

Currently when the Draw Polyline button is selected my React js code will put a buffer around the line drawn. This results in two layers placed in the getGeomanLayers array. I would like to replace the Draw Polyline button with a button that when selected will execute code that will take the lat/lngs from a line drawn on the map and create a buffered line ( I think geoman refers to this as a Feature) on the map. I think by doing this then when the user decides to remove the drawing, there will only be one item to remove from the map, versus what we have currently, where the user would have to click twice to remove everything: the first click removes the buffer (the feature), the second click removes the line that was drawn.

To start with this, when the map is present on the page I:

  1. Add the draw control on the map
  2. Run a copyDrawControl to replace the Draw Polyline button

I have put console. info statements before and after step 1 as well as before and after step 2. First, this is my code: geomanDrawVisibleIssue

This is what we get: BEFORE addControls:: map.pm.controlsVisible() => returns false <== OK! AFTER addControls:: map.pm.controlsVisible() => returns true <== OK! AFTER copyDrawControl:: map.pm.controlsVisible() => returns false <== NO! Control is visible on the map!

So just for your further information. Perhaps this scenario will be covered as you mentioned unt #956.

BTW: Am I copying to customize the behavior of the Draw Polyline button correctly?

Thank you

Falke-Design commented 3 years ago

Fixed with Release 2.11.3

CAIAG-D commented 1 year ago

And how to switch to active the edit button in the toolbar from code?