Giter Site home page Giter Site logo

clavijojuan / l.cascadebuttons Goto Github PK

View Code? Open in Web Editor NEW
4.0 2.0 5.0 26 KB

A leaflet plugin to create cascade buttons like controls

Home Page: https://vibrant-perlman-43d7a4.netlify.app/

License: MIT License

JavaScript 80.13% CSS 19.87%
leaflet leaflet-control button webgis javascript map

l.cascadebuttons's Introduction

L.cascadeButtons

A leaflet plugin to create cascade buttons.

image


Requirements

  • Leaflet
  • Some Font Icons

Install

NPM

npm i leaflet-cascade-buttons

Usage Example

Easy way to implements buttons with cascade subgroup buttons where each one can have it functionality.

new L.cascadeButtons([
    {icon: 'fas fa-home', ignoreActiveState:true , command: () =>{console.log('test') }},
    {icon: 'fas fa-home', items:[
        {icon: 'fas fa-home', command: () =>{console.log('hola')}},
        {icon: 'fas fa-home', command: () =>{console.log('hola')}},
        {icon: 'fas fa-globe', command: () =>{console.log('hola')}},
    ]},
    {icon: 'fas fa-home', items: [
        {icon: 'fas fa-home', command: () =>{console.log('hola')}},
        {icon: 'fas fa-globe', command: () =>{console.log('hola')}},
    ]},
], {position:'topright', direction:'horizontal'}).addTo(map);

L.cascadeButtons receives two arguments:

  • The first is an array that contains every parent button and it children's.
  • The second is an object with control options

Parent properties

Property Type Default Description
icon String null Icon class of Font Icon
ignoreActiveState Boolean false Flag boolean to ignore clicked button style
command Function null or (expand or collapse if button has childs) Function to execute when button is clicked
items Child properties[] null Array of child properties

Child properties

Property Type Default Description
icon String null Icon class of Font Icon
command Function null or (expand or collapse if button has childs) Function to execute when button is clicked

Options

Option Type Default Description
position String 'bottomright' Position of the control. Options: leaflet control positions
direction String 'horizontal' Stacked direction. Options: 'Vertical' and 'Horizontal'
className String '' className to customize control

Font Icons

Can be used with any font icon / custom library like:

  • font awesome
  • boostrap icons
  • primeIcons
  • custom

l.cascadebuttons's People

Contributors

clavijojuan avatar

Stargazers

 avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

l.cascadebuttons's Issues

Add event object to item command function

Hello,

I would like to suggest a small modification to the Leaflet Cascade Buttons plugin that allows passing the event object to the item command functions. This change can be useful when accessing event properties (such as the event target) within the command functions.

Currently, the command functions for items are called directly without passing any arguments:

childButton.addEventListener('click', () => item.command());

I propose changing this line to the following:

childButton.addEventListener('click', (e) => item.command(e));

With this change, you can define command functions that accept the event object as a parameter, like this:

{
  icon: 'fas fa-home',
  command: (e) => {
    console.log('Button clicked:', e.target);
  }
}

This allows for more flexibility when handling item click events.

Thank you for considering this suggestion. I believe this small change can be helpful for developers who want to access event properties within their command functions.

Best regards,

Justin

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.