Skip to content

Latest commit

History

14 Commits

Folders and files

NameName
Last commit message
Last commit date

Repository files navigation

Animation Plugin for Leaflet.js

npm version

General information

A leaflet plugin which allows users to apply animation.

Downloads

NPM

npm install --save leaflet.motion

YARN

yarn add leaflet.motion

Usage

Include script:

<scriptsrc="dist/leaflet.motion.min.js"></script>

Main options:

L.motion.polyline([],options,motionOptions,markerOptions).addTo(map);// as L.polylineL.motion.polygon([],options,motionOptions,markerOptions).addTo(map);// as L.polygonL.motion.group([],options).addTo(map);// as L.featureGroup - to run all animation at same timeL.motion.seq([],options).addTo(map);// as L.featureGroup - to setup seq for animations.

Options:

You can pass a number of options to the plugin to control various settings.

Default control options

OptionTypeDefaultDescription
panePane'polymotionPane'Default pane

Motion options

OptionTypeDefaultDescription
autoBooleanfalseIndicates auto start animation on plugin added to the map
easingL.Motion.EaseL.Motion.Ease.linearAnimation strategy
speedNumber0Motion speed in KM/s, yes, kilometers per second
durationNumber0Motion duration in ms, 0 means no animation, istant rendering on motionStart()

Marker options

All MarkerOptions that you can add to any marker + one more:

OptionTypeDefaultDescription
removeOnEndBooleanfalseRemoves marker from map on motion end

Here's an example of passing through some options:

L.motion.polyline([[50,0],[60,10]],{color: "transparent"},{auto: true,duration: 3000,easing: L.Motion.Ease.easeInOutQuart},{removeOnEnd: true,icon: L.divIcon({html: "<i class='fa fa-car fa-2x' aria-hidden='true'></i>",iconSize: L.point(27.5,24)})}).addTo(map);

Public methods

L.motion.*

Public methods in all motion objects:

motionStart()// to start motion.motionStop()// to stop motion.motionPause()// to pause motion.motionResume()// to resume paused motion.motionToggle()// to pause motion, if it's running. To start motion if it's not. Also will resume motion if it was paused.

L.motion.polyline and L.motion.polygon

Additional methods in polyline and polygon

motionDuration(duration)// - expected duration for motion in milliseconds, can be used after motion is created.motionSpeed(speed)// - expected motion speed in KM/H, can be used after motion is created.addLatLng(latLng)// - allows to add additional point in the end for the motion animation.

Motion Events

EventValueDescription
L.Motion.Event.Started{ layer }Fires on motion stated on root element only
L.Motion.Event.Paused{ layer }Fires on motion paused on root element only
L.Motion.Event.Resumed{ layer }Fires on motion resumed on root element only
L.Motion.Event.Ended{ layer }Fires on motion ended on root element only
L.Motion.Event.Section{ layer }Fires on each motion section change in L.Motion.Seq starting with first one

About

A simple tool to animate polylines and polygons in different way

Resources

Stars

0 stars

Watchers

4 watching

Forks

Releases

Packages

Contributors

Languages