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

Remove only custom button #771

Closed arshdoda closed 3 years ago

arshdoda commented 3 years ago

Hi,

I want to show the custom button if layer geometry is "polygon" and remove if layer geometry is "linestring"

Is there any function to remove the customButton.

I tried following:

const customButton = {
        name: 'custom',
        title: 'Custom',
        className: 'control-icon leaflet-pm-icon-edit',
        onClick: () => { 
        },
        afterClick: (e, obj) => {
        },
        doToggle: true,
        toggleStatus: false,
        disableOtherButtons: true,
        tool: 'custom',
        block: 'edit',
        actions: ['finishMode'],
    };

map.pm.Toolbar.createCustomControl(customButton) //Adding the button

map.pm.Toolbar.getButtons()['custom'].remove(); // It is not removing the button
Falke-Design commented 3 years ago

You can remove it like that:

map.pm.addControls({
  custom: false
})

And showing it again with:

map.pm.addControls({
  custom: true
})
arshdoda commented 3 years ago

map.pm.addControls({ custom: false })

Not Working

Falke-Design commented 3 years ago

Look into this example: https://jsfiddle.net/falkedesign/pk2jyg71/

It should work.

Change between custom: false and custom: true

arshdoda commented 3 years ago

Look into this example: https://jsfiddle.net/falkedesign/pk2jyg71/

It should work.

Change between custom: false and custom: true

Still not working. May be issue with npm package

Falke-Design commented 3 years ago

In the demo it is working how you expecting?

Do you use the latest version of Geoman 2.9.0 and Leaflet 1.7.1?

arshdoda commented 3 years ago

Yes, i am using the latest ones

Falke-Design commented 3 years ago

You also use the same name as in your shared code? name: custom

arshdoda commented 3 years ago

You also use the same name as in your shared code? name: custom

Yes.

I tried locally. Issue with npm package

Falke-Design commented 3 years ago

Hmmm Typescript, vanilla, or which framework you are using?

arshdoda commented 3 years ago

using reactjs

Falke-Design commented 3 years ago

Can you please create a demo like this: https://codesandbox.io/s/elated-villani-q0gei?file=/src/map/MapWithGeoman.tsx

tobilg commented 3 years ago

I have a similar issue with #796