Git Product home page Git Product logo

leaflet.smoothmarkerbouncing's Introduction

Leaflet.SmoothMarkerBouncing npm

Plugin for Leaflet that will make you markers bounce!

It provides smooth, lightweight and customisable animation of marker bouncing. Allows the bouncing of multiple markers on the map, without lose of performance. Plugin shows it's best performances on the 3D-able modern browsers, using hardware acceleration.
On old browsers plugin provides simplified animation.

Demo

Check out the demo.

Usage

Add Javascript file on your page:

<script type="text/javascript" src="js/leaflet.smoothmarkerbouncing.js" />

Plugin provides additional methods:

/* Methods of L.Marker class */
L.Marker.setBouncingOptions({..}); // sets options of bouncing of all markers
L.Marker.getBouncingMarkers();     // gets all bouncing markers
L.Marker.stopAllBouncingMarkers(); // asks all bouncing markers to stop

/* Methods of marker instances */
var marker = L.marker([lat, lng]);
marker.setBouncingOptions({..});   // sets options of bouncing of this marker
marker.isBouncing();               // checks if marker is bouncing
marker.bounce();                   // starts the bouncing
marker.bounce(n);                  // makes marker bounce "n" times
marker.stopBouncing();             // stops bouncing marker
marker.toggleBouncing();           // starts/stops bouncing of this marker

Plugin respects fluent API. All marker instance methods (except isBouncing) return the marker object.
Some usage examples:

/* Create a marker and make it bounce immediately */
var marker = L.marker([lat, lng]).bounce();

/* Create a marker and define it's bouncing options.
 * Bouncing can be started/stoped by the click on the marker.
 */
var marker = L.marker([lat, lng])
    .setBouncingOptions({
        bounceHeight : 60,    // height of the bouncing
        bounceSpeed  : 54,    // bouncing speed coefficient
        exclusive    : true,  // if this marker bouncing all others must stop
    }).on('click', function() {
        this.toggleBouncing();
    });

/* Define options of bouncing for all markers */
L.Marker.setBouncingOptions({
        bounceHeight : 60,   // height of the bouncing
        bounceSpeed  : 54,   // bouncing speed coefficient
});

/* Create 10 markers and each of them will bounce 3 times when clicked */
for (var i = 0; i < 10; i++) {
    var marker = L.marker([lat, lng])
        .on('click', function() {
            this.bounce(3); // bounce 3 times
        });
}

Options of bouncing

You can easily customize bouncing animation supplying options in method setBouncingOptions. This method available on the marker class L.Marker and on each of marker instances.
It's highly recommended to define options for all markers via L.Marker.setBouncingOptions instead of define them on each marker individually. The animation performance highly increases when all markers have the same options.
Method setBouncingOptions accepts an object with options as parameter. Animation can be customized with following properties:

  • bounceHeight - how high marker will bounce (px), default: 15
  • contractHeight - how much marker will contract when it touch the ground (px), default: 12
  • bounceSpeed - bouncing speed coefficient, value used to calculate the speed of bounce animation, more it becomes high, more animation becomes slow, default: 52
  • contractSpeed - contracting speed coefficient, default: 52
  • shadowAngle - shadow inclination angle, if set to null shadow animation is disabled (radians), default: - Math.PI / 4
  • elastic - activate contract animation when marker touch the ground, default: true
  • exclusive - when it's true, stops the bouncing of other markers when this one starts to bounce. If another marker start to bounce after, this marker stops. default: false

Tested on

✅ Chrome 40.0
✅ Firefox 35.0
✅ IE 11
✅ Android 4.4/5.0
✅ Safari

License

Plugin distributed under BSD license.

leaflet.smoothmarkerbouncing's People

Contributors

hosuaby avatar

Watchers

James Cloos avatar Utku Cansever 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.