1 | # Leaflet Ant Path
|
2 | [![Build Status](https://travis-ci.org/rubenspgcavalcante/leaflet-ant-path.svg?branch=master)](https://travis-ci.org/rubenspgcavalcante/leaflet-ant-path) [![Codacy Badge](https://api.codacy.com/project/badge/Grade/ca1062428b51428b8204e9044d4fdc3b)](https://www.codacy.com/app/rubenspgcavalcante/leaflet-ant-path?utm_source=github.com&utm_medium=referral&utm_content=rubenspgcavalcante/leaflet-ant-path&utm_campaign=Badge_Grade)
|
3 |
|
4 | ## *Creates a leaflet polyline with a 'ant-path' animated flux*
|
5 | [Live demo here](http://rubenspgcavalcante.github.io/leaflet-ant-path)
|
6 |
|
7 | ### Installing
|
8 | Via Bower:
|
9 | ```
|
10 | bower install leaflet-ant-path
|
11 | ```
|
12 |
|
13 | Via NPM:
|
14 | ```
|
15 | npm install leaflet-ant-path
|
16 | ```
|
17 |
|
18 | Or just [download](https://github.com/rubenspgcavalcante/leaflet-ant-path-bower/archive/master.zip) this source code
|
19 |
|
20 |
|
21 | ### Requirements
|
22 |
|
23 | - Leaflet >= 0.7.7
|
24 | - Leaflet 1.0.0-rc
|
25 |
|
26 | ### Browser compatibility
|
27 | Tested on:
|
28 |
|
29 | - Firefox 43
|
30 | - Chrome 45
|
31 | - Chromium 47
|
32 |
|
33 | ### UMD compatible
|
34 | Can be used with asynchronous module loaders and CommonJS packers
|
35 |
|
36 | ### Important!
|
37 | Soon leaflet 0.7 will be deprecated, and so MultiPolyline. Because this, the MultiAntPath is
|
38 | also been **deprecated**, therefore use the L.LayerGroup to control your AntPath layers collection. :)
|
39 |
|
40 | ### Using the plugin
|
41 | It's just like a polyline:
|
42 |
|
43 | ``` javascript
|
44 | // Using the AntPath
|
45 | var antPolyline = new L.Polyline.AntPath(latlngs, options);
|
46 |
|
47 | //or use the factory
|
48 | antPolyline = L.polyline.antPath(latlngs, options);
|
49 |
|
50 | antPolyline.addTo(map);
|
51 |
|
52 | // ... And the MultiAntPath
|
53 | var antPolyline = new L.MultiPolyline.MultiAntPath(latlngsList, options);
|
54 |
|
55 | //or use the factory
|
56 | antPolylines = L.multiPolyline.multiAntPath(latlngsList, options);
|
57 |
|
58 | antPolylines.addTo(map);
|
59 |
|
60 | ```
|
61 |
|
62 | Note for AMD/CommonJS:
|
63 | The direct use as 'AntPath' now is **deprecated** and instead is exported by default, the modules which contains the AntPath and MultiAntPath
|
64 |
|
65 | Using with AMD:
|
66 |
|
67 | ``` javascript
|
68 | require(['leafletAntPath'], function(AntPathModule) {
|
69 | // ...
|
70 | var antPolyline = new AntPathModule.AntPath(latlngs, options);
|
71 | antPolyline.addTo(map);
|
72 |
|
73 | var multiAntPolylines = new AntPathModule.MultiAntPath(latlngs, options);
|
74 | multiAntPolylines.addTo(map);
|
75 | });
|
76 | ```
|
77 |
|
78 | Using with browserify:
|
79 |
|
80 | ``` javascript
|
81 | var AntPath = require('leafletAntPath').AntPath;
|
82 | var MultiAntPath = require('leafletAntPath').MultiAntPath;
|
83 |
|
84 | // ...
|
85 | var antPolyline = new AntPath(latlngs, options);
|
86 | antPolyline.addTo(map);
|
87 | ```
|
88 |
|
89 | Using with ES6 imports
|
90 | ``` javascript
|
91 | import {AntPath, MultiAntPath} from 'leafletAntPath';
|
92 |
|
93 | var antPolyline = new AntPath(latlngs, options);
|
94 | antPolyline.addTo(map);
|
95 | ```
|
96 |
|
97 | ### ES6/ES2015 features
|
98 | Thinking in the new features of JavaScript, and its new way of programing,
|
99 | AntPath has some nicely features to work with ES6.
|
100 |
|
101 | #### spreadable
|
102 | When spread the path, you will receive it lat/lngs array;
|
103 | ```javascript
|
104 | ...
|
105 | let antPathLayer = new AntPath(path, options);
|
106 | let anotherAntPath = new AntPath(path2, options);
|
107 |
|
108 | let latLngs = [...antPathLayer, ...anotherAntPath];
|
109 | ```
|
110 |
|
111 | #### iterable
|
112 | When used in a **for ... of ...** loops over the path coordinates
|
113 | ```javascript
|
114 | for(let latLng of antPath) {
|
115 | // do something with it latLngs ...
|
116 | }
|
117 | ```
|
118 |
|
119 | #### extensible
|
120 | You can create you custom 'class' based on the AntPath:
|
121 | ```javascript
|
122 | class CustomAntPath extends AntPath {
|
123 | //...
|
124 | }
|
125 | ```
|
126 |
|
127 | #### map method
|
128 | AntPath has a map method as the Array, returning a new instance of
|
129 | AntPath *(or the child class which extends it)*:
|
130 | ```javascript
|
131 | //New path with translated path
|
132 | let newAnthPath = myAntPath.map(pos => latLng(pos.lat+1, pos.lng+1));
|
133 | ```
|
134 |
|
135 | ### Parameters
|
136 | The AntPath extends from the [FeatureGroup](http://leafletjs.com/reference.html#featuregroup), but you initialise with
|
137 | the same options of a common [Polyline]((http://leafletjs.com/reference.html#polyline)), with some extra options, like the flux color.
|
138 |
|
139 | | name | type | example | description |
|
140 | |------|------|---------| ------------|
|
141 | |latlngs| L.LatLng[] **or** Array\[number, number\] | \[ \[0, 10\], \[-20, 0\], ... \] | A array of latitude and longitudes (same as used in [Polyline constructor](http://leafletjs.com/reference.html#polyline) )
|
142 | |options| Object | {color: 'red', weight: 5, ...} | Same as the [Polyline options](http://leafletjs.com/reference.html#polyline-options) plus the **extra** options bellow
|
143 | |options.paused| boolean | true/false | Starts with the animation paused (default: false)
|
144 | |options.pulseColor| string | #FF00FF | Adds a color to the dashed flux (default: 'white')
|
145 | |options.delay | string | 120 | Add a delay to the animation flux (default: 400)
|
146 | |options.dashArray| [number, number] | [15, 30] |The size of the animated dashes (default: [10, 20])
|
147 |
|
148 | ---
|
149 |
|
150 | ### Methods
|
151 | Same as the L.Polyline API and with the same behaviour. [See it here.](http://leafletjs.com/reference.html#polyline)
|
152 |
|
153 | ### Building and Testing
|
154 | To run the build, before install the npm and gulp dependencies, then run:
|
155 |
|
156 | To build
|
157 | ```
|
158 | gulp pack
|
159 | ```
|
160 |
|
161 | To test:
|
162 | ```
|
163 | gulp test
|
164 | ```
|
165 |
|
166 | ### Development Environment
|
167 | **Be sure all the dev-dependencies are installed.**
|
168 | Just run the command:
|
169 | ```
|
170 | npm start
|
171 | ```
|
172 |
|
173 | This will make the webpack compile the dev. env. and set up into a
|
174 | webserver with hot deployment into the localhost:8080. There you can make
|
175 | changes into the plugin and see in real time all your modifications running.
|
176 |
|
177 | ### License
|
178 |
|
179 | This project is under the [MIT LICENSE](http://opensource.org/licenses/MIT)
|