• Stars
    star
    151
  • Rank 246,057 (Top 5 %)
  • Language
    JavaScript
  • License
    MIT License
  • Created about 10 years ago
  • Updated about 4 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Apply a relative pixel offset to polylines without changing their coordinates.

Leaflet Polyline Offset

Works with Leaflet >= 1.0.

This plugin adds to Leaflet Polylines the ability to be drawn with a relative pixel offset, without modifying their actual LatLngs. The offset value can be either negative or positive, for left- or right-side offset, and remains constant across zoom levels.

Install with NPM

npm install leaflet-polylineoffset

Use cases and demos

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.

This plugin brings this feature to Leaflet, to apply to client-side vectors.

Demos are clearer than words:

  • Basic demo. 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.
  • Cycle lanes. Drawing a road with two directions of cycle lanes, a main one and one shared.
  • Bus lines. 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.

Usage

The plugin adds offset capabilities directly to the L.Polyline class.

// Instantiate a normal Polyline with an 'offset' options, in pixels.
var pl = L.polyline([[48.8508, 2.3455], [48.8497, 2.3504], [48.8494, 2.35654]], {
  offset: 5
});

// Setting the 'offset' property through the 'setStyle' method won't work.
// If you want to set the offset afterwards, use 'setOffset'.
pl.setOffset(-10);

// To cancel the offset, simply set it to 0
pl.setOffset(0);

License

MIT.

Contributors

More Repositories

1

Leaflet.PolylineDecorator

A plug-in for the JS map library Leaflet, allowing to define patterns (like dashes, arrows, icons, etc.) on Polylines.
JavaScript
493
star
2

Leaflet.RotatedMarker

Leaflet plugin to enable the rotation of map marker icons
JavaScript
257
star
3

Leaflet.MagnifyingGlass

A plugin to add a customizable magnifying glass tool to a Leaflet map.
JavaScript
105
star
4

jkstra

JavaScript graph routing library
JavaScript
49
star
5

thread-reader-reader

Parse Twitter thread already simplified by third-party Thread Reader app, and produce dead simple HTML
JavaScript
20
star
6

FirefoxOS.GeoTracker

GPS track recording web app for Firefox OS… and mobile browsers in general.
JavaScript
20
star
7

bird-tracking

Interactive data viz of migrating birds
JavaScript
13
star
8

react-staticMapZoom

A React component which mimics the auto zoom mini-map found on geo-tagged photos Flickr pages.
JavaScript
10
star
9

clean-cnrtl

Clean and responsive proxy to CNRTL French dictionary website
CSS
10
star
10

simple-static-map-server

Raster map service based on MapLibre GL JS
JavaScript
9
star
11

metro-pili

JavaScript
5
star
12

irish-tune-map

A map of irish folk tunes
JavaScript
5
star
13

GeoTracker

JavaScript
3
star
14

updatable-priority-queue

A priority queue implementation based on a binary heap, with an efficient update-key operation
JavaScript
3
star
15

mapbox-gl-style-optimizer

Suggests optimizations to Mapbox-GL style files to improve rendering perfs.
JavaScript
3
star
16

place-place

Place-Place, a place positioning game to test spatial knowledge of your city
TypeScript
3
star
17

pw2014

Atelier Paris Web 2014
JavaScript
2
star
18

alt-route-labeller

A library to compute the best position to put labels on multiple routes between two points
JavaScript
2
star
19

bbecquet

1
star