Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

leaflet-lasso

Package Overview
Dependencies
Maintainers
1
Versions
43
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

leaflet-lasso - npm Package Compare versions

Comparing version 1.1.3 to 2.0.0-alpha1

.DS_Store

22

dist/index.d.ts

@@ -0,15 +1,15 @@

import L from 'leaflet';
import * as LassoHandler from './lasso-handler';
import * as LassoControl from './lasso-control';
declare module 'leaflet' {
interface LassoOptions {
polygon?: PolylineOptions;
cursor?: string;
let Lasso: typeof LassoHandler.LassoHandler;
let lasso: (map: L.Map, options: LassoHandler.LassoHandlerOptions) => LassoHandler.LassoHandler;
namespace Control {
let Lasso: typeof LassoControl.LassoControl;
}
interface LassoFinishedEvent extends LeafletEvent {
latLngs: LatLng[];
layers: Layer[];
namespace control {
let lasso: (options: LassoControl.LassoControlOptions) => LassoControl.LassoControl;
}
class Lasso extends Handler {
constructor(map: Map, options?: LassoOptions);
}
const lasso: (map: Map, options?: LassoOptions) => Lasso;
}
export {};
export * from './lasso-handler';
export * from './lasso-control';
{
"name": "leaflet-lasso",
"version": "1.1.3",
"version": "2.0.0-alpha1",
"description": "Leaflet plugin for lasso selection",

@@ -10,15 +10,29 @@ "keywords": [

"license": "MIT",
"main": "dist/index.js",
"main": "dist/leaflet-lasso.cjs.js",
"module": "dist/leaflet-lasso.esm.js",
"browser": "dist/leaflet-lasso.umd.js",
"types": "dist/index.d.ts",
"scripts": {
"build": "tsc && webpack -p",
"test": "echo \"Error: no test specified\" && exit 1"
"build": "rm -rf dist && rollup -c",
"test": "jest",
"prepublishOnly": "npm run build"
},
"devDependencies": {
"@types/leaflet": "^1.2.7",
"@types/leaflet.markercluster": "^1.0.3",
"ts-loader": "^4.4.1",
"typescript": "^2.9.2",
"webpack": "^4.12.0",
"webpack-cli": "^3.0.8"
"@types/jest": "^24.0.13",
"@types/leaflet": "^1.4.4",
"@types/leaflet.markercluster": "^1.4.0",
"autoprefixer": "^9.5.1",
"jest": "^24.8.0",
"leaflet": "^1.5.1",
"leaflet.markercluster": "^1.4.1",
"postcss-assets": "^5.0.0",
"rollup": "^1.13.0",
"rollup-plugin-commonjs": "^10.0.0",
"rollup-plugin-node-resolve": "^5.0.1",
"rollup-plugin-postcss": "^2.0.3",
"rollup-plugin-terser": "^5.0.0",
"rollup-plugin-typescript2": "^0.21.1",
"rollup-plugin-visualizer": "^1.1.1",
"ts-jest": "^24.0.2",
"typescript": "^3.5.1"
},

@@ -30,4 +44,5 @@ "peerDependencies": {

"dependencies": {
"@turf/boolean-point-in-polygon": "^6.0.1"
"circle-to-polygon": "^1.0.2",
"terraformer": "^1.0.9"
}
}

@@ -7,16 +7,51 @@ # leaflet-lasso

Supports all Leaflet vector layers:
- Marker
- CircleMarker
- Circle
- Polyline
- Polyline with multiple segments
- Rectangle
- Polygon
- Polygon with hole
- Polygon with multiple segments
- Polygon with multiple segments and holes
Selection modes:
- contain - default, entire shape must be in lasso polygon
- intersect - any part of shape can be in lasso polygon
## Install
- `npm install leaflet-lasso`
- `import "leaflet-lasso"`
```
npm install leaflet-lasso
import "leaflet-lasso"
```
or
- `<script src="https://unpkg.com/leaflet-lasso@latest/dist/leaflet-lasso.min.js"></script>`
```
<script src="https://unpkg.com/leaflet-lasso@latest/dist/leaflet-lasso.min.js"></script>
```
## Usage
### Control
```
const lasso = L.control.lasso().addTo(map);
map.on('lasso.finished', (event) => {
console.log(event.layers);
});
```
### Handler
```
const lasso = L.lasso(map);
lasso.enable();
yourCustomButton.addEventListener('click', () => {
lasso.enable();
});
map.on('lasso.finished', (event) => {

@@ -27,16 +62,12 @@ console.log(event.layers);

## Methods
## Options
- `enable()`
- `disable()`
## Events
- `lasso.finished`
- `lasso.enabled`
- `lasso.disabled`
## API
## TODO
See TypeScript type definitions
- support also other layer types, not just markers (with @turf/intersect)
- add L.Control
## Thanks
Icon by @Falke-Design

@@ -1,137 +0,25 @@

import * as L from 'leaflet';
import { LeafletEvent, LeafletMouseEvent } from 'leaflet';
import booleanPointInPolygon from '@turf/boolean-point-in-polygon';
import L from 'leaflet';
import * as LassoHandler from './lasso-handler';
import * as LassoControl from './lasso-control';
declare module 'leaflet' {
export interface LassoOptions {
polygon?: PolylineOptions,
cursor?: string;
let Lasso: typeof LassoHandler.LassoHandler;
let lasso: (map: L.Map, options: LassoHandler.LassoHandlerOptions) => LassoHandler.LassoHandler;
namespace Control {
let Lasso: typeof LassoControl.LassoControl;
}
export interface LassoFinishedEvent extends LeafletEvent {
latLngs: LatLng[];
layers: Layer[];
namespace control {
let lasso: (options: LassoControl.LassoControlOptions) => LassoControl.LassoControl;
}
export class Lasso extends Handler {
constructor(map: Map, options?: LassoOptions);
}
export const lasso: (map: Map, options?: LassoOptions) => Lasso;
}
const Lasso = L.Handler.extend({
options: {
polygon: {
color: '#00C3FF',
weight: 2,
},
cursor: 'crosshair',
} as L.LassoOptions,
L.Lasso = LassoHandler.LassoHandler;
L.lasso = (map: L.Map, options: LassoHandler.LassoHandlerOptions) => new LassoHandler.LassoHandler(map, options);
map: undefined as L.Map | undefined,
polygon: undefined as L.Polygon | undefined,
L.Control.Lasso = LassoControl.LassoControl;
L.control.lasso = (options: LassoControl.LassoControlOptions) => new LassoControl.LassoControl(options);
initialize(map: L.Map, options?: L.LassoOptions) {
this.map = map;
this.onMouseUpBound = this.onMouseUp.bind(this);
L.Util.setOptions(this, options);
},
addHooks() {
this.map.on('mousedown', this.onMouseDown, this);
this.map.on('mouseup', this.onMouseUp, this);
document.addEventListener('mouseup', this.onMouseUpBound, true);
const mapContainer = this.map.getContainer();
mapContainer.style.cursor = this.options.cursor || '';
mapContainer.style.userSelect = 'none';
mapContainer.style.msUserSelect = 'none';
(mapContainer.style as any).mozUserSelect = 'none'; // missing typings
mapContainer.style.webkitUserSelect = 'none';
this.map.dragging.disable();
this.map.fire('lasso.enabled');
},
removeHooks() {
this.map.off('mousedown', this.onMouseDown, this);
this.map.off('mousemove', this.onMouseMove, this);
this.map.off('mouseup', this.onMouseUp, this);
document.removeEventListener('mouseup', this.onMouseUpBound);
const mapContainer = this.map.getContainer();
mapContainer.style.cursor = '';
mapContainer.style.userSelect = '';
mapContainer.style.msUserSelect = '';
(mapContainer.style as any).mozUserSelect = ''; // missing typings
mapContainer.style.webkitUserSelect = '';
this.map.dragging.enable();
this.map.fire('lasso.disabled');
},
onMouseDown(event: LeafletEvent) {
const event2 = event as LeafletMouseEvent;
this.polygon = L.polygon([event2.latlng], this.options.polygon).addTo(this.map);
this.map.on('mousemove', this.onMouseMove, this);
},
onMouseMove(event: LeafletEvent) {
if (!this.polygon) {
return;
}
const event2 = event as LeafletMouseEvent;
this.polygon.addLatLng(event2.latlng);
},
onMouseUp() {
if (!this.polygon) {
return;
}
const selectedFeatures = this.getSelectedLayers(this.polygon);
this.map.fire('lasso.finished', {
latLngs: this.polygon.getLatLngs()[0],
layers: selectedFeatures,
});
this.map.removeLayer(this.polygon);
this.polygon = undefined;
this.disable();
},
getSelectedLayers(polygon: L.Polygon) {
const lassoPolygonGeometry = polygon.toGeoJSON().geometry;
const layers: L.Layer[] = [];
this.map.eachLayer((layer: L.Layer) => {
if (layer === this.polygon) {
return;
}
if (L.MarkerCluster && layer instanceof L.MarkerCluster) {
layers.push(...layer.getAllChildMarkers());
} else {
layers.push(layer);
}
});
const selectedLayers = layers.filter(layer => {
if (layer instanceof L.Marker) {
const layerGeometry = layer.toGeoJSON().geometry;
return booleanPointInPolygon(layerGeometry, lassoPolygonGeometry);
}
return false;
});
return selectedLayers;
},
});
(L as any).Lasso = Lasso;
(L as any).lasso = (map: L.Map, options: L.LassoOptions) => {
return new Lasso(map, options);
};
export * from './lasso-handler';
export * from './lasso-control';
{
"compilerOptions": {
"target": "es5",
"module": "commonjs",
"module": "es2015",
"lib": ["dom", "es2018"],
"esModuleInterop": true,
"moduleResolution": "node",
"outDir": "dist",
"declaration": true,
"outDir": "./dist",
"strict": true,
"noUnusedLocals": true,
"noUnusedParameters": true,
"noImplicitReturns": true,
"noFallthroughCasesInSwitch": true
}
"noUnusedParameters": true
},
"include": [
"src/**/*.ts",
"typings/**/*.d.ts"
],
"exclude": [
"**/*.test.ts",
"node_modules"
]
}

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc