Code Monkey home page Code Monkey logo

l.control.linestringselect's Introduction

L.Control.LineStringSelect npm version CircleCI

Screenshot

LineString selection tool: you can select a part or a stretch of a polyline on the map. Performance-oriented, uses rbush for segment lookup

Look how this thing deals with a coastline polyline consisting of ~500 points

demo

Options

Option type default value
startMarkerClass string 'select-marker select-start-marker'
endMarkerClass string 'select-marker select-end-marker'
movingMarkerClass string 'select-marker select-moving-marker'
name string 'leaflet-linestring-select'
lineWeight number 4
lineTolerance number L.Browser.mobile ? 10 : 5
movingMarkerStyle L.CircleMarcerOptions {
  fillColor: '#fff',
  fillOpacity: 1,
  weight: 2,
  opacity: 0.5,
  color: '#000'
}
endpointStyle L.CircleMarcerOptions {
  radius: 5,
  color: '#111',
  fillColor: '#fff',
  fillOpacity: 1
}
selectionStyle L.PolylineOptions {
  color: '#0ff',
  opacity: 1
}
useTouch boolean L.Browser.mobile
position `'topright' 'topleft'

API

.enable({layer: polyline, feature: feature}) Enables control, initializes it with provided polyline. You can pass GeoJSON object as well, otherwise it will be auto-generated

.disable() Disable control, remove handlers and selection

.reset() Reset selection

.selectMeters(startMeter, endMeter) Select stretch by meter distances from linestring start.

.toGeoJSON() Returns selection GeoJSON

.getSelection() Returns array of selection L.LatLngs

Events

selection Selection changed or finished.

reset Selection cleared

select:start : {pos: <L.LatLng>} First point set

select:end : {pos: <L.LatLng>} Second point set

Usage

npm install --save leaflet-linestring-select
...
var Select = require('leaflet-linestring-select');

or

<script type="text/javascript" src="leaflet.js"></script>
<script type="text/javascript" src="path/to/L.Control.LineStringSelect.min.js"></script>

See /examples/app.js for initialization and other things

Requirements

  • leaflet@>=1.x
  • rbush@>=3.x

License

The MIT License (MIT)

Copyright (c) 2019 Alexander Milevski

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

l.control.linestringselect's People

Contributors

dependabot[bot] avatar oliv avatar w8r avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

l.control.linestringselect's Issues

Angular Js6

Please provide any reference or documentation in order to implement this great tool in typescript or angular.

Uncaught Error: Cannot find module 'rbush'

On a new reactjs project https://github.com/keyanyang/react-leaflet-webpack-boilerplate
npm install --save leaflet-linestring-select

I just add this lines in App.js

import { Map, TileLayer } from 'react-leaflet';
import Select from 'leaflet-linestring-select'

or

import { Map, TileLayer } from 'react-leaflet';
var Select = require('leaflet-linestring-select');

Uncaught Error: Cannot find module 'rbush'
    o http://localhost:8080/main.js?c2066d2489971b870df7:1666
    ./node_modules/leaflet-linestring-select/dist/L.Control.LineStringSelect.no-rbush.js/</</<[5]</<

On line : var Rbush = global.Rbush || require('rbush');

What I'm doing wrong ?

Markers can be dragged outside of LineString Element

There is an issue with creating a selection from the lineString, I have used your demo to illustrate.
Grabbing the marker and pulling it past the end of the segment extends the marker itself out to the point where the cursor influences the base feature. This influence (in latitude and longitude) becomes greater as the map is zoomed out.

I increased the thickness of the base feature to illustrate the discrepancy between its end and the end of the selection which was achieved at a lower zoom level.

issue-lineselect

Why is this a 'Control'?

It seems that this class would fit better under L.Handler, since it is enabled/disabled and uses markers (much like the Draw handlers), and isn't added to a control corner (like other L.Control types)

Is there a reason that this wasn't extended from L.Handler?

Set a fixed start point that doesn't respond to drag

How would it be possible to set a starting point that doesn't move, and only allow the end handle to respond to drag events?
This would need blocking the swapping of start and end points to go only in one direction.

TypeScript Support

Hello,
Nice work!!! This is a really cool component. I am developing a custom map tool in Angular2/4 project and would like to include your tool. I am having issue getting it to load in my angular project (Typescript). Do you have any Typescript support or recommendations for type script support and including and using in an Angular2/4 project?

Thank you in advance.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.