Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Additional Custom Control Methods #1295

Merged
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -1056,6 +1056,9 @@ The following methods are available on `map.pm.Toolbar`:
| createCustomControl(`options`) | - | To add a custom Control to the Toolbar. [Details](#adding-newcustom-controls) |
| copyDrawControl(`instance`, `options`) | `Object` | Creates a copy of a draw Control. Returns the `drawInstance` and the `control`. |
| changeActionsOfControl(`name`, `actions`) | - | Change the actions of an existing button. |
| getButtons() | `Object` | Get an object of the current buttons button. |
TurtIeSocks marked this conversation as resolved.
Show resolved Hide resolved
| controlExists(`name`) | `Boolean` | Checks whether a button has been mounted button. |
| getCustomControls()) | `Object` | Gets an object of the custom controls that are mounted button. |

#### Customize Controls

Expand Down
9 changes: 9 additions & 0 deletions leaflet-geoman.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -646,6 +646,15 @@ declare module 'leaflet' {
position: L.ControlPosition
): void;

/** Returns all of the active buttons */
getButtons(): Record<string, L.Control>

/** Checks whether a button has been mounted */
controlExists(name: string): boolean;

/** Returns all of the custom, active buttons */
getCustomControls(): Record<string, L.Control>

/** Returns a Object with the positions for all blocks */
getBlockPositions(): BlockPositions;

Expand Down
11 changes: 10 additions & 1 deletion src/js/Toolbar/L.PM.Toolbar.js
Original file line number Diff line number Diff line change
Expand Up @@ -563,7 +563,16 @@ const Toolbar = L.Class.extend({
this.changeControlOrder();
return control;
},

controlExists(name) {
return Boolean(this.getButtons()[name]);
Falke-Design marked this conversation as resolved.
Show resolved Hide resolved
},
TurtIeSocks marked this conversation as resolved.
Show resolved Hide resolved
getCustomControls() {
return Object.fromEntries(
Object.entries(this.getButtons()).filter(
([, v]) => v._button.tool === 'custom'
)
);
},
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let us make this more general:

Suggested change
getCustomControls() {
return Object.fromEntries(
Object.entries(this.getButtons()).filter(
([, v]) => v._button.tool === 'custom'
)
);
},
getButtonsInBlock(name) {
const buttonsInBlock = {};
if(name){
for(const buttonName in map.pm.Toolbar.getButtons()){
const button = map.pm.Toolbar.getButtons()[buttonName];
// draw controls doesn't have a block
if(button._button.tool === name || (name === 'draw' && !button._button.tool)){
buttonsInBlock[buttonName] = button;
}
}
}
return buttonsInBlock;
}

changeControlOrder(order = []) {
const shapeMapping = this._shapeMapping();

Expand Down