├── .gitignore
├── LICENSE
├── README.md
├── examples
├── example.html
├── example_bus.html
└── example_cycle.html
├── leaflet.polylineoffset.js
└── package.json
/.gitignore:
--------------------------------------------------------------------------------
1 | *.sh
2 | *.ps1
3 | *~
4 | *.sublime-*
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 | The MIT License (MIT)
2 |
3 | Copyright (c) 2014 Benjamin Becquet
4 |
5 | Permission is hereby granted, free of charge, to any person obtaining a copy
6 | of this software and associated documentation files (the "Software"), to deal
7 | in the Software without restriction, including without limitation the rights
8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9 | copies of the Software, and to permit persons to whom the Software is
10 | furnished to do so, subject to the following conditions:
11 |
12 | The above copyright notice and this permission notice shall be included in all
13 | copies or substantial portions of the Software.
14 |
15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21 | SOFTWARE.
22 |
23 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | Leaflet Polyline Offset
2 | ===
3 | Works with Leaflet >= 1.0.
4 |
5 | This plugin adds to Leaflet `Polyline`s the ability to be drawn with a relative pixel offset, without modifying their actual `LatLng`s. The offset value can be either negative or positive, for left- or right-side offset, and remains constant across zoom levels.
6 |
7 | ## Install with NPM
8 |
9 | ```bash
10 | npm install leaflet-polylineoffset
11 | ```
12 |
13 | ## Use cases and demos
14 |
15 | Line offsetting is the process of drawing a line parallel to an existant one, at a fixed distance. It's not a simple (x,y) translation of the whole shape, as it shouldn't overlap. It can be used to visually emphasize different properties of the same linear feature, or achieve complex composite styling.
16 |
17 | This plugin brings this feature to Leaflet, to apply to client-side vectors.
18 |
19 | Demos are clearer than words:
20 | * [Basic demo](http://bbecquet.github.io/Leaflet.PolylineOffset/examples/example.html). The dashed line is the "model", with no offset applied. Red is with a -10px offset, green is with a 5px offset. The three are distinct `Polyline` objects but uses the same coordinate array.
21 | * [Cycle lanes](http://bbecquet.github.io/Leaflet.PolylineOffset/examples/example_cycle.html). Drawing a road with two directions of cycle lanes, a main one and one shared.
22 | * [Bus lines](http://bbecquet.github.io/Leaflet.PolylineOffset/examples/example_bus.html). A more complex demo. Offsets are computed automatically depending on the number of bus lines using the same segment. Other non-offset polylines are used to achieve the white and black outline effect.
23 |
24 | ## Usage
25 |
26 | The plugin adds offset capabilities directly to the `L.Polyline` class.
27 | ```javascript
28 | // Instantiate a normal Polyline with an 'offset' options, in pixels.
29 | var pl = L.polyline([[48.8508, 2.3455], [48.8497, 2.3504], [48.8494, 2.35654]], {
30 | offset: 5
31 | });
32 |
33 | // Setting the 'offset' property through the 'setStyle' method won't work.
34 | // If you want to set the offset afterwards, use 'setOffset'.
35 | pl.setOffset(-10);
36 |
37 | // To cancel the offset, simply set it to 0
38 | pl.setOffset(0);
39 | ```
40 |
41 | ## License
42 | MIT.
43 |
44 | ## Contributors
45 | * [Benjamin Becquet](https://github.com/bbecquet) (original author)
46 | * [sanderd17](https://github.com/sanderd17)
47 | * [jellevoost](https://github.com/jellevoost)
48 | * [ghybs](https://github.com/ghybs)
49 | * [BartWaardenburg](https://github.com/BartWaardenburg)
50 |
--------------------------------------------------------------------------------
/examples/example.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |