npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

leaflet-polylinedecorator

v1.6.0

Published

[![CDNJS](https://img.shields.io/cdnjs/v/leaflet-polylinedecorator.svg)](https://cdnjs.com/libraries/leaflet-polylinedecorator)

Downloads

71,895

Readme

Leaflet PolylineDecorator

CDNJS

A Leaflet plug-in to define and draw patterns on existing Polylines or along coordinate paths. Demo.

Compatibility with Leaflet versions

The current version of the plugin (on the master branch) works only with versions 1.* of Leaflet.

For a version of the plugin compatible with the older 0.7.* Leaflet releases, use the leaflet-0.7.2 branch. But this branch is not maintained anymore and Leaflet 1.* has been around for a while, so you should definitely update.

npm / bower

npm install leaflet-polylinedecorator
bower install leaflet-polylinedecorator

Features

  • Dashed or dotted lines, arrow heads, markers following line
  • Works on Polygons too! (easy, as Polygon extends Polyline)
  • Multiple patterns can be applied to the same line
  • New behaviors can be obtained by defining new symbols

Screenshot

screenshot

Usage

To create a decorator and add it to the map: L.polylineDecorator(latlngs, options).addTo(map);

  • latlngs can be one of the following types:

  • L.Polyline

  • L.Polygon

  • an array of L.LatLng, or with Leaflet's simplified syntax, an array of 2-cells arrays of coordinates (useful if you just want to draw patterns following coordinates, but not the line itself)

  • an array of any of these previous types, to apply the same patterns to multiple lines

  • options has a single property patterns, which is an array of Pattern objects.

Pattern definition

Property | Type | Required | Description --- | --- | --- | --- offset| see below | No | Offset of the first pattern symbol, from the start point of the line. Default: 0. endOffset| see below | No | Minimum offset of the last pattern symbol, from the end point of the line. Default: 0. repeat| see below | Yes | Repetition interval of the pattern symbols. Defines the distance between each consecutive symbol's anchor point. symbol| Symbol factory | Yes | Instance of a symbol factory class.

offset, endOffset and repeat can be each defined as a number, in pixels, or in percentage of the line's length, as a string (ex: '10%').

Methods

Method | Description --- | --- setPaths(latlngs) | Changes the path(s) the decorator applies to. latlngs can be all the types supported by the constructor. Useful for example if you remove polyline from a set, or coordinates change. setPatterns(<Pattern[]> patterns) | Changes the decorator's pattern definitions, and update the symbols accordingly.

Example

var polyline = L.polyline([...]).addTo(map);
var decorator = L.polylineDecorator(polyline, {
    patterns: [
        // defines a pattern of 10px-wide dashes, repeated every 20px on the line
        {offset: 0, repeat: 20, symbol: L.Symbol.dash({pixelSize: 10})}
    ]
}).addTo(map);

Performance note/alternatives

This plugin creates actual L.Layer objects (markers, polyline, etc.) to draw the pattern symbols. This is extra customizable as you can define your own symbols, but it may have an impact on the responsiveness of your map if you have to draw a lot of symbols on many large polylines.

Here are two light-weight alternatives for simpler cases: