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

@bopen/leaflet-area-selection

v0.7.0

Published

Create and manipulate a polygonal area on a Leaflet map

Downloads

2,931

Readme

@bopen/leaflet-area-selection

Create and manipulate a polygonal area on a Leaflet map

NPM

CI

The primary target of this plugin is to obtain a customizable selected area while keeping high usability.

Install

npm install --save @bopen/leaflet-area-selection

Usage

import L from 'leaflet';
import '@bopen/leaflet-area-selection/dist/index.css';
import { DrawAreaSelection } from '@bopen/leaflet-area-selection';

const map = L.map('root').setView([41.901493, 12.5009157], 13);

L.tileLayer('https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png', {
  attribution:
    '&copy; <a href="https://www.openstreetmap.org/copyright">OpenStreetMap</a> contributors',
}).addTo(map);

const areaSelection = new DrawAreaSelection();

map.addControl(areaSelection);

Old school usage?

Although we think it's time for Leaflet to move away from global L object and open to modern JavaScript and tree-shaking, you can still use this plugin in the old way.

This gist contains a modified version of the Leaflet "Hello World" example: https://gist.github.com/keul/74e442b96a41c4f50e304c22259a63c3

Configuration

The DrawAreaSelection can receive a configuration object with followings supported options:

  • active - the plugin starts as active, no need to run it from the button
  • fadeOnActivation - when actively drawing a new area the map is partially faded out
  • onPolygonReady - callback called during the adjustment phase (see below) every time a change is performed to the polygon (vertex moved, added or removed). Receives the Leaflet.Polygon and the control instance as arguments.
  • onPolygonDblClick - called when performing a double-click on the draw polygon when in the adjustment phase (see below). Receives three arguments: the Leaflet.Polygon, the control instance and the event.
  • onButtonActivate - called when user clicks on the button to enable draw a polygon. Receives two arguments: the control instance and the event. Calling preventDefault on the event will abort the activation.
  • onButtonDeactivate - called when user clicks on the button to stop drawing the polygon. Receives three arguments: the Leaflet.Polygon, the control instance and the event. Calling preventDefault on the event will abort the deactivation.

User guide

Defining the skeleton of the polygon

When the plugin is activated by using the new control, the map enters in a drawing phase. Clicks on the map will trigger the creation of a vertex for the polygon.

User can continue adding vertexes to the polygon (min length is 3) until the whole required area is covered. To complete the polygon drawing phase user must click on the first (green) point created.

Alternatively: on the first click you can drag&drop and directly create a square shape (note: this method is not currently working on mobile!).

Fix and change polygon shape

At this point we enter the adjustment phase, where user can:

  • move edges of the polygon by dragging them
  • create new edges, by dragging the ghost markers in the middle of every path
  • deleting edges by double clicking on them

See it in action

Example animation

Example creating a rect

See also the live example.

Credits

This plugin is heavily inspired by the "draw on map" feature provided on Immobiliare.it website.

License

MIT © B-Open