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

mapbox-gl-draw-rectangle-restrict-area

v3.1.5

Published

[mapbox-gl](https://github.com/mapbox/mapbox-gl-draw) Draw rectangle mode, with optional area limitation

Downloads

1,382

Readme

mapbox-gl-draw-rectangle-restrict-area

mapbox-gl Draw rectangle mode, with optional area limitation

DEMO

NPM

Features

  • One/two click drawing
  • Mobile compabillity
  • Area square restriction Optional

Install

npm install --save @mapbox/mapbox-gl-draw mapbox-gl-draw-rectangle-restrict-area

Usage

import MapboxDraw from "@mapbox/mapbox-gl-draw";
import DrawRectangle, {
  DrawStyles,
} from "mapbox-gl-draw-rectangle-restrict-area";

const map = new mapboxgl.Map({
  container: "map", // container id
  style: "mapbox://styles/mapbox/streets-v11",
  center: [-91.874, 42.76], // starting position
  zoom: 12, // starting zoom
});

const draw = new MapboxDraw({
  userProperties: true,
  displayControlsDefault: false,
  styles: DrawStyles,
  modes: Object.assign(MapboxDraw.modes, {
    draw_rectangle: DrawRectangle,
  }),
});
map.addControl(draw);

// when mode drawing should be activated
draw.changeMode("draw_rectangle", {
  areaLimit: 5 * 1_000_000, // 5 km2, optional
  escapeKeyStopsDrawing: true, // default true
  allowCreateExceeded: false, // default false
  exceedCallsOnEachMove: false, // default false
  exceedCallback: (area) => console.log("exceeded!", area), // optional
  areaChangedCallback: (area) => console.log("updated", area), // optional
});

Styles

Exceeded features

Exeeded size feature has user_size_exceed: true property

Default styles

mapbox-gl-draw-rectangle-restrict-area use default mapbox-gl-draw styles with 2 overrided layers:

[
  {
    id: "gl-draw-polygon-fill-active",
    type: "fill",
    filter: ["all", ["==", "active", "true"], ["==", "$type", "Polygon"]],
    paint: {
      "fill-color": [
        "case",
        ["!", ["to-boolean", ["get", "user_size_exceed"]]], // turns to red if feature has `user_size_exceed: true` prop
        "#fbb03b",
        "#ff0000",
      ],
      "fill-opacity": 0.2,
    },
  },
  {
    id: "gl-draw-polygon-stroke-active",
    type: "line",
    filter: ["all", ["==", "active", "true"], ["==", "$type", "Polygon"]],
    layout: {
      "line-cap": "round",
      "line-join": "round",
    },
    paint: {
      "line-color": [
        "case",
        ["!", ["to-boolean", ["get", "user_size_exceed"]]],
        "#fbb03b",
        "#ff0000",
      ],
      "line-dasharray": [0.2, 2],
      "line-width": 2,
    },
  },
];

You also can export it

import { ActivePolygonStyles } from "mapbox-gl-draw-rectangle-restrict-area";

Override styles

You can override default drawing styles with overrideDefaultStyles helper function

import { overrideDefaultStyles } from "mapbox-gl-draw-rectangle-restrict-area";

const drawStyles = overrideDefaultStyles(<your_custom_styles>);

Default styles with same ids will be replaced.

Example

License

MIT © dqunbp