You're Invited: Meet the Socket team at BSidesSF and RSAC - April 27 - May 1.RSVP

@freenow/react-polygon-editor

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install
r

@freenow/react-polygon-editor

A react component for displaying and drawing geo polygons

2.0.1
latest
76

Supply Chain Security

100

Vulnerability

95

Quality

83

Maintenance

100

License

Version published
Weekly downloads
8
-63.64%
Maintainers
9
Weekly downloads
 
Created
Issues
5

@freenow/react-polygon-editor

Table of contents

  • About
  • Getting started
  • Components
  • How to run locally
  • Contribution

About

React Polygon Editor provides react components for displaying and editing polygons. We use leaflet for rendering maps. And typescript to provide a strongly typed interface.

Getting started

First install @freenow/react-polygon-editor:

npm i -S @freenow/react-polygon-editor

Make sure you have also installed all peer dependencies. Have a look at package.json for more information.

npm i -S react react-dom react-leaflet leaflet styled-components

inject the leaflet css style.

Import 'leaflet/dist/leaflet.css';

You can also link the css style from a CDN in your index.html

<link rel="stylesheet" href="https://unpkg.com/leaflet@1.4.0/dist/leaflet.css" />

Components

PolygonDraw

Props

  • polygon: Coordinate[] | Coordinate[][] (Single or list of polygons to render)
  • activeIndex?: number (index of currently active polygon, can be omitted when only one polygon exists. Default value: 0)
  • highlightedIndex?: number (index of the polygon that should be highlighted.)
  • boundary?: Coordinate[]
  • initialCenter?: Coordinate (The initial center will be used to localize the map on the first render if no polygon or boundary polygon were provided)
  • initialZoom?: number (The initial zoom will be used to localize the map on the first render if no polygon or boundary polygon were provided)
  • editable?: boolean (Allows enabling and disabling polygon editing. Default value: true)
  • onChange?: (polygonCoordinates: Coordinate[], isValid: boolean) => void
  • onClick?: (index: number) => void (called with the index of the polygon that was clicked on)
  • onMouseEnter?: (index: number) => void (called with the index of the polygon that was entered)
  • onMouseLeave?: (index: number) => void (called with the index of the polygon that was left)

The initialCenter and initialZoom props are applicable only when both the polygon and the boundary coordinates are empty. This flow explains which parameters are used to focus the map:

Focus flow

For more details, have a look at the Component definition in PolygonDraw

How to run locally

You can run the library locally. We use storybook to illustrate what can be done with the components.

Simply run:

npm i && npm start

Contribution

  • Discuss the contribution with the maintainers
  • Make sure the the code is well tested and adheres to code convention
  • Create a pull request

Keywords

FAQs

Package last updated on 07 Mar 2023

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts