Git Product home page Git Product logo

leaflet.easybutton's Introduction

L.EasyButton

running demo

Demos and Docs Here


Boilerplate/Copy-Paste

make sure you have the source included:

<link rel="stylesheet" href="https://cdn.rawgit.com/CliffCloud/Leaflet.EasyButton/f3f3136bda3937aa813c80a1a6c8c921c6df06ed/src/easy-button.css" />
<script src="https://cdn.rawgit.com/CliffCloud/Leaflet.EasyButton/f3f3136bda3937aa813c80a1a6c8c921c6df06ed/src/easy-button.js"></script>

and for the examples, remember to change YOUR_LEAFLET_MAP to the varable name of your map

Hello World

open a popup

<script>
  var helloPopup = L.popup().setContent('Hello World!');

  L.easyButton('fa-globe', function(btn, map){
    helloPopup.setLatLng(map.getCenter()).openOn(map);
  }).addTo( YOUR_LEAFLET_MAP ); // probably just `map`
</script>
Map State

set the map's center and use an img for the icon

<script>
  var antarctica = [-77,70];

  L.easyButton('<img src="/path/to/img/of/penguin.png">', function(btn, map){
    map.setView(antarctica);
  }).addTo( YOUR_LEAFLET_MAP );
</script>
Button States

change the button's function and appearance

<script>
  var stateChangingButton = L.easyButton({
    states: [{
      stateName: 'zoom-to-school',
      icon: 'fa-university',
      title: 'zoom to a school',
      onClick: function(btn, map) {
        map.setView([42.3748204,-71.1161913],16);
        btn.state('zoom-to-forest');
      }
    }, {
      stateName: 'zoom-to-forest',
      icon: 'fa-tree',
      title: 'zoom to a forest',
      onClick: function(btn, map) {
        map.setView([46.25,-121.8],10);
        btn.state('zoom-to-school');
      }
    }]
  });

  stateChangingButton.addTo( YOUR_LEAFLET_MAP );
</script>

read the old docs here

leaflet.easybutton's People

Contributors

atstp avatar egore avatar juandecarrion avatar markaphillips avatar

Watchers

James Cloos avatar Dylan Moberg avatar

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.