0.3.1 • Published 3 months ago

leaflet-trace v0.3.1

Weekly downloads
-
License
MIT
Repository
github
Last release
3 months ago

Leaflet.Trace

This plugin is an extension for Leaflet.Draw that includes a new set of tools which allow the user to select a line and trace along it.

It requires Leaflet.Draw and @turf/turf. It also includes code based on Leaflet.AlmostOver and Leaflet.GeometryUtil, altered to fit the needs of this plugin.

Demo

Play with it here

Install

To include it in your app using a cdn add the following to the top of your html

<link rel="stylesheet" type="text/css" href="https://unpkg.com/leaflet-draw@1.0.4/dist/leaflet.draw-src.css" />
<script src="https://unpkg.com/leaflet-draw@1.0.4/dist/leaflet.draw.js"></script> 
<script src="https://cdn.jsdelivr.net/npm/@turf/turf@6/turf.min.js"></script>
<link rel="stylesheet" href="https://unpkg.com/leaflet-trace@0.3.1/dist/leaflet.trace.css" />
<script type="module" src="https://unpkg.com/leaflet-trace@0.3.1/dist/leaflet.trace.js"></script>

If you install using npm adding this to your html should do the trick:

<link rel="stylesheet" type="text/css" href="../node_modules/leaflet/dist/leaflet.css"/>
<script src="../node_modules/leaflet-draw/dist/leaflet.draw.js"></script>
<script src="../node_modules/@turf/turf/turf.min.js" charset="utf-8"></script>
<link rel="stylesheet" type="text/css" href="../node_modules/leaflet-trace/dist/leaflet.trace.css"/>
<script src="../node_modules/leaflet-trace/dist/leaflet.trace.js"></script>

Usage

Leaflet.Trace mainly extends L.Control.Draw to add a new set of 3 tools that work together to allow users to trace along a selected line and snap a marker to a selected line.

It is initalized similarly to L.Control.Draw, with the addition of a trace option.

Example:

new L.Control.Trace({
  trace: true,
  draw: {
    circlemarker: false, //Leaflet.Trace includes a slightly altered version of the L.Draw.CircleMarker
  },
  edit: {
    featureGroup: drawnItems,
  },
}).addTo(map);

Leaflet.Trace works with L.geoJSON layers that contain a FeatureCollection made up of LineString and MultiLineString features.

For Leaflet.Trace to be able to detect your L.geoJSON you need to give it an attribute of "trace" set to "true".

Example:

const lines = L.geoJSON(featureCollection).addTo(map);

lines.trace = true;
0.3.1

3 months ago

0.3.0

10 months ago

0.2.7

10 months ago

0.2.6

10 months ago

0.2.8

10 months ago

0.2.5

10 months ago

0.2.4

10 months ago

0.2.3

1 year ago

0.2.2

1 year ago

0.2.1

1 year ago

0.2.0

1 year ago

0.1.11

1 year ago

0.1.10

1 year ago

0.1.9

1 year ago

0.1.8

1 year ago

0.1.7

1 year ago

0.1.6

1 year ago

0.1.5

1 year ago

0.1.4

1 year ago

0.1.3

1 year ago

0.1.2

1 year ago

0.1.1

1 year ago

0.1.0

1 year ago