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 🙏

© 2026 – Pkg Stats / Ryan Hefner

map-boundary-editor

v0.3.3

Published

Generic embeddable map boundary editor as a Web Component

Readme

map-boundary-editor

npm license downloads

map-boundary-editor is a lightweight, embeddable map-based boundary editor designed for defining and validating geographic service boundaries.

It is optimized for use cases where a user-defined area (polygon) must be evaluated against a fixed administrative or reference boundary — such as service eligibility, coverage restriction, or zoning rules.


Why map-boundary-editor?

Many applications need users to define geographic areas:

  • delivery zones
  • service coverage
  • eligibility rules
  • geofencing configuration

A common requirement in these use cases is a clear separation between editable user input and non-editable reference boundaries.

Most teams end up rebuilding the same map drawing logic again and again, tightly coupled to a specific map provider.

map-boundary-editor solves this by providing:

  • a reusable boundary authoring UI
  • a stable and minimal API
  • engine-agnostic GeoJSON output

Key Concepts

Editable Polygon

A polygon created or modified by the user to represent an area of interest (e.g. delivery zone, service coverage).

Reference Boundary

A fixed, non-editable boundary used as a reference for validation or restriction. Typical examples include cities, provinces, or regulatory zones.

Readonly Mode

A mode where editing controls are disabled, allowing the map to be used purely for visualization, review, or approval workflows.


Features

  • Draw, edit, and delete editable polygon boundaries
  • Support for fixed, non-editable reference boundaries
  • Read-only mode for review or visualization use cases
  • Supports multiple editable boundaries (GeoJSON FeatureCollection)
  • No vendor lock-in or API keys required

Installation

Via npm

npm install map-boundary-editor

Basic Usage (Recommended)

The most common usage pattern is defining an editable area within a fixed reference boundary.

<map-boundary-editor
  id="editor"
  style="width: 800px; height: 500px;"
></map-boundary-editor>

<script type="module">
  import "map-boundary-editor";

  const editor = document.getElementById("editor");

  // Set a fixed reference boundary (e.g. administrative area)
  editor.setBoundary({
    type: "FeatureCollection",
    features: [
      {
        type: "Feature",
        geometry: {
          type: "Polygon",
          coordinates: [
            [
              [106.69, -6.1],
              [107.03, -6.1],
              [107.03, -6.38],
              [106.69, -6.38],
              [106.69, -6.1],
            ],
          ],
        },
        properties: {},
      },
    ],
  });

  // Listen for user-defined polygon changes
  editor.addEventListener("change", (e) => {
    console.log("Editable GeoJSON:", e.detail.geojson);
  });
</script>

All public APIs (setView, setGeoJSON, clear, etc.) are safe to call immediately after the element is created. No setTimeout or customElements.whenDefined is required.


Loading an Existing Editable Boundary

editor.setGeoJSON({
  type: "FeatureCollection",
  features: [
    {
      type: "Feature",
      geometry: {
        type: "Polygon",
        coordinates: [
          [
            [106.8166, -6.2],
            [106.82, -6.21],
            [106.83, -6.205],
            [106.8166, -6.2],
          ],
        ],
      },
      properties: {},
    },
  ],
});

Even when loading a single boundary, the data must be wrapped in a FeatureCollection for consistency.


View Control

editor.setView(lat, lng, zoom);

If editable boundaries are later loaded using setGeoJSON, the map will automatically fit to the boundary.


Geolocation

Geolocation must be triggered explicitly from a user interaction due to browser permission requirements.

editor.enableGeolocation();

Public API (v0.3)

Editable Polygon

setGeoJSON(geojson: FeatureCollection): void

Loads editable polygon boundaries from GeoJSON.

getGeoJSON(): FeatureCollection

Returns the current editable polygon boundaries.

clear(): void

Removes all editable polygon boundaries.


Reference Boundary

setBoundary(geojson: FeatureCollection): void

Sets a fixed, non-editable reference boundary.

getBoundary(): FeatureCollection | null

Returns the current reference boundary.

clearBoundary(): void

Removes the reference boundary from the map.


Mode Control

setReadonly(value: boolean): void

Enables or disables editing controls.

isReadonly(): boolean

Returns the current readonly state.


View Control

setView(lat: number, lng: number, zoom?: number): void

Moves the map to the specified location.

Events

change

Fired whenever the editable polygon is created, edited, or deleted.

editor.addEventListener("change", (e) => {
  console.log(e.detail.geojson);
});

Data Format

The editor uses GeoJSON as its data contract.

GeoJSON is treated as the single source of truth and is intentionally decoupled from any specific map engine.

The output is compatible with:

  • Google Maps Data Layer
  • Mapbox / MapLibre
  • Backend GIS libraries (PostGIS, Shapely, Turf.js)

Demo

A demo is included in the repository to showcase:

  • Editable polygons vs administrative reference boundaries
  • Visual hierarchy between reference and user-defined areas
  • Readonly vs editable interaction modes

Live demo on StackBlitz:
https://stackblitz.com/github/heritechie/map-boundary-editor


Roadmap

  • v0.3: reference boundary support, read-only mode, improved demo UX
  • v0.4: additional map engine adapters (MapLibre, Google Maps)
  • v1.0: stable API

The roadmap is intentionally conservative to keep the core API stable.


Non-Goals

This project is intentionally not:

  • A full GIS editor
  • A GeoJSON validation library
  • A replacement for tools like geojson.io
  • A general-purpose map rendering framework