
Security News
Crates.io Users Targeted by Phishing Emails
The Rust Security Response WG is warning of phishing emails from rustfoundation.dev targeting crates.io users.
leaflet.smooth_marker_bouncing
Advanced tools
Plugin for Leaflet that will make you markers bounce!
It provides smooth, lightweight and customizable animation of marker bouncing. Allows the bouncing of multiple markers on the map, without loss of performance.
Starting from version v3.0.0
, plugin is based on CSS3 keyframes to make animation. If you need support older browsers,
it will be better to stick to v2.0.x
.
Check out the demo.
Add Javascript file on your page:
<script type="text/javascript"
src="https://cdn.jsdelivr.net/gh/hosuaby/Leaflet.SmoothMarkerBouncing@v3.0.3/dist/bundle.js"
crossorigin="anonymous"></script>
Or install it as npm
module:
npm install leaflet.smooth_marker_bouncing
Since v3.1.0
plugin provides ES module, that can be imported in your code as following:
import L from 'leaflet';
import SmoothMarkerBouncing from 'leaflet.smooth_marker_bouncing';
SmoothMarkerBouncing(L); // <-- adds plugins code to the global L variable
Check the example of how it is used with Angular
and Typescript
: AngularLeafletExample.
If Content Security Policy (CSP) is enabled on the page, you must include the hash of
dynamically injected styles in the style-src
directive. This ensures that the inline styles comply
with the CSP without compromising security.
The right hash code could be found in the file dist/bouncing.css.sha256.
Example CSP Meta Tag::
<meta http-equiv="Content-Security-Policy" content="script-src 'self'; style-src 'self' 'sha256-fepvpp//vQvk3B6VNSvwdc7exafX0cguysFL3FH4NXw=';">
Plugin provides additional methods to Marker
:
/* 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 markers to stop bouncing
L.Marker.stopAllBouncingMarkers(true); // stops bouncing of all markers abruptly
/* Methods of marker instances */
const marker = L.marker([lat, lng]);
marker.setBouncingOptions({..}); // sets options of bouncing for 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 of the marker
marker.stopBouncing(true); // stops bouncing of the marker abruptly
marker.toggleBouncing(); // starts/stops bouncing of the 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 */
const marker = L.marker([lat, lng]).addTo(map).bounce();
/* Create a marker and make it bounce 2 times when clicked.
* Do something when the bouncing is stopped, like open a popup.
*/
const marker = L.marker([lat, lng])
.addTo(map)
.on('click', function() {
this.bounce(2) // bounce 2 times
.on('bounceend',function() {
console.log('bounce end');
});
});
/* Create a marker and set its bouncing options.
* Bouncing can be started/stopped by the click on the marker.
*/
const marker = L.marker([lat, lng])
.setBouncingOptions({
bounceHeight : 60, // height of the bouncing
bounceSpeed : 54, // bouncing speed coefficient
exclusive : true, // if this marker is bouncing all others must stop
})
.addTo(map)
.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 (let i = 0; i < 10; i++) {
const marker = L.marker([lat, lng])
.addTo(map)
.on('click', function() {
this.bounce(3); // bounce 3 times
});
}
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 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 parameters.
Animation can be customized with following properties:
null
shadow animation disabled (radians), default: -𝜋÷4Event | Description |
---|---|
bounceend | Fired when the animation is done |
FAQs
Smooth animation of marker bouncing for Leaflet.
The npm package leaflet.smooth_marker_bouncing receives a total of 539 weekly downloads. As such, leaflet.smooth_marker_bouncing popularity was classified as not popular.
We found that leaflet.smooth_marker_bouncing demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 0 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
The Rust Security Response WG is warning of phishing emails from rustfoundation.dev targeting crates.io users.
Product
Socket now lets you customize pull request alert headers, helping security teams share clear guidance right in PRs to speed reviews and reduce back-and-forth.
Product
Socket's Rust support is moving to Beta: all users can scan Cargo projects and generate SBOMs, including Cargo.toml-only crates, with Rust-aware supply chain checks.