Coder Social home page Coder Social logo

houjinlong / leaflet.polylineoffset Goto Github PK

View Code? Open in Web Editor NEW

This project forked from bbecquet/leaflet.polylineoffset

0.0 1.0 0.0 34 KB

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

License: MIT License

JavaScript 100.00%

leaflet.polylineoffset's Introduction

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

leaflet.polylineoffset's People

Contributors

bbecquet avatar sijmen avatar ghybs avatar jellevoost avatar bartwaardenburg avatar sanderd17 avatar

Watchers

James Cloos avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.