Socket
Socket
Sign inDemoInstall

leaflet-polylinedecorator

Package Overview
Dependencies
Maintainers
1
Versions
12
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

leaflet-polylinedecorator - npm Package Compare versions

Comparing version 1.3.2 to 1.4.0

tests/projectPatternOnPointPath.js

2

bower.json
{
"name": "leaflet-polylinedecorator",
"main": "leaflet.polylineDecorator.js",
"version": "1.3.2",
"version": "1.4.0",
"authors": [

@@ -6,0 +6,0 @@ "Benjamin Becquet"

@@ -7,12 +7,14 @@ (function (global, factory) {

// functional re-impl of L.Point.distanceTo,
// with no dependency on Leaflet for easier testing
function pointDistance(ptA, ptB) {
var x = ptB.x - ptA.x;
var y = ptB.y - ptA.y;
return Math.sqrt(x * x + y * y);
}
var computeSegmentHeading = function computeSegmentHeading(a, b) {
return Math.atan2(b.y - a.y, b.x - a.x) * 180 / Math.PI + 90;
return (Math.atan2(b.y - a.y, b.x - a.x) * 180 / Math.PI + 90 + 360) % 360;
};
var getPointPathPixelLength = function getPointPathPixelLength(pts) {
return pts.reduce(function (distance, pt, i) {
return i === 0 ? 0 : distance + pt.distanceTo(pts[i - 1]);
}, 0);
};
var asRatioToPathLength = function asRatioToPathLength(_ref, totalPathLength) {

@@ -42,13 +44,5 @@ var value = _ref.value,

});
var pathPixelLength = getPointPathPixelLength(pathAsPoints);
var ratios = {
offset: asRatioToPathLength(pattern.offset, pathPixelLength),
endOffset: asRatioToPathLength(pattern.endOffset, pathPixelLength),
repeat: asRatioToPathLength(pattern.repeat, pathPixelLength)
};
return projectPatternOnPointPath(pathAsPoints, ratios).map(function (point) {
return projectPatternOnPointPath(pathAsPoints, pattern).map(function (point) {
return {
latLng: map.unproject(point.pt),
latLng: map.unproject(L.point(point.pt)),
heading: point.heading

@@ -68,3 +62,3 @@ };

b = pts[i];
distAB = a.distanceTo(b);
distAB = pointDistance(a, b);
segments.push({

@@ -82,11 +76,6 @@ a: a,

function projectPatternOnPointPath(pts, _ref2) {
var offset = _ref2.offset,
endOffset = _ref2.endOffset,
repeat = _ref2.repeat;
function projectPatternOnPointPath(pts, pattern) {
// 1. split the path as segment infos
var segments = pointsToSegments(pts);
var nbSegments = segments.length;
if (nbSegments === 0) {

@@ -97,2 +86,10 @@ return [];

var totalPathLength = segments[nbSegments - 1].distB;
if (totalPathLength === 0) {
return [];
}
var offset = asRatioToPathLength(pattern.offset, totalPathLength);
var endOffset = asRatioToPathLength(pattern.endOffset, totalPathLength);
var repeat = asRatioToPathLength(pattern.repeat, totalPathLength);
var repeatIntervalPixels = totalPathLength * repeat;

@@ -102,3 +99,3 @@ var startOffsetPixels = offset > 0 ? totalPathLength * offset : 0;

// 2. generate the positions of the pattern as offsets from the polygon start
// 2. generate the positions of the pattern as offsets from the path start
var positionOffsets = [];

@@ -136,6 +133,12 @@ var positionOffset = startOffsetPixels;

if (ptB.x !== ptA.x) {
return L.point(ptA.x + ratio * (ptB.x - ptA.x), ptA.y + ratio * (ptB.y - ptA.y));
return {
x: ptA.x + ratio * (ptB.x - ptA.x),
y: ptA.y + ratio * (ptB.y - ptA.y)
};
}
// special case where points lie on the same vertical axis
return L.point(ptA.x, ptA.y + (ptB.y - ptA.y) * ratio);
return {
x: ptA.x,
y: ptA.y + (ptB.y - ptA.y) * ratio
};
}

@@ -202,2 +205,7 @@

// enable rotationAngle and rotationOrigin support on L.Marker
/**
* Defines several classes of symbol factories,
* to be used with L.PolylineDecorator
*/
L.Symbol = L.Symbol || {};

@@ -204,0 +212,0 @@

{
"name": "leaflet-polylinedecorator",
"version": "1.3.2",
"version": "1.4.0",
"repository": "bbecquet/Leaflet.PolylineDecorator",

@@ -8,7 +8,13 @@ "main": "./dist/leaflet.polylineDecorator.js",

"build": "rollup -c",
"build:watch": "rollup -c -w"
"build:watch": "rollup -c -w",
"test": "ava tests -v",
"test:watch": "ava tests -v -w"
},
"devDependencies": {
"ava": "^0.21.0",
"babel-plugin-external-helpers": "^6.22.0",
"babel-preset-es2015": "^6.24.1",
"babel-preset-es2015-rollup": "^3.0.0",
"babel-preset-latest": "^6.24.1",
"babel-register": "^6.24.1",
"rollup": "^0.45.2",

@@ -25,15 +31,11 @@ "rollup-plugin-babel": "^2.7.1",

"presets": [
[
"latest",
{
"es2015": {
"modules": false
}
}
]
],
"plugins": [
"external-helpers"
"latest",
"es2015"
]
},
"ava": {
"require": [
"babel-register"
]
}
}

@@ -83,3 +83,3 @@ # Leaflet PolylineDecorator

Here are two light-weight alternatives for simpler cases:
- the [`dashArray` property of `L.Path`](http://leafletjs.com/reference-1.1.0.html#path-dasharray), f you only need to draw simple patterns (dashes, dots, etc.).
- the [`dashArray` property of `L.Path`](http://leafletjs.com/reference-1.1.0.html#path-dasharray), if you only need to draw simple patterns (dashes, dots, etc.).
- the [`Leaflet.TextPath`](https://github.com/makinacorpus/Leaflet.TextPath) plugin, which is based on SVG.

@@ -11,5 +11,8 @@ import resolve from 'rollup-plugin-node-resolve';

babel({
babelrc: false,
exclude: 'node_modules/**',
presets: ['es2015-rollup'],
plugins: ['external-helpers']
})
],
};
// functional re-impl of L.Point.distanceTo,
// with no dependency on Leaflet for easier testing
function pointDistance(ptA, ptB) {
const x = ptB.x - ptA.x;
const y = ptB.y - ptA.y;
return Math.sqrt(x * x + y * y);
}
const computeSegmentHeading = (a, b) =>
(Math.atan2(b.y - a.y, b.x - a.x) * 180 / Math.PI) + 90;
((Math.atan2(b.y - a.y, b.x - a.x) * 180 / Math.PI) + 90 + 360) % 360;
const getPointPathPixelLength = pts =>
pts.reduce((distance, pt, i) => {
return i === 0 ? 0 : distance + pt.distanceTo(pts[i - 1]);
}, 0);
const asRatioToPathLength = ({ value, isInPixels }, totalPathLength) =>

@@ -29,13 +32,5 @@ isInPixels ? value / totalPathLength : value;

const pathAsPoints = latLngs.map(latLng => map.project(latLng));
const pathPixelLength = getPointPathPixelLength(pathAsPoints);
const ratios = {
offset: asRatioToPathLength(pattern.offset, pathPixelLength),
endOffset: asRatioToPathLength(pattern.endOffset, pathPixelLength),
repeat: asRatioToPathLength(pattern.repeat, pathPixelLength),
};
return projectPatternOnPointPath(pathAsPoints, ratios)
return projectPatternOnPointPath(pathAsPoints, pattern)
.map(point => ({
latLng: map.unproject(point.pt),
latLng: map.unproject(L.point(point.pt)),
heading: point.heading,

@@ -51,3 +46,3 @@ }));

b = pts[i];
distAB = a.distanceTo(b);
distAB = pointDistance(a, b);
segments.push({

@@ -65,10 +60,15 @@ a,

function projectPatternOnPointPath(pts, { offset, endOffset, repeat }) {
function projectPatternOnPointPath(pts, pattern) {
// 1. split the path as segment infos
const segments = pointsToSegments(pts);
const nbSegments = segments.length;
if (nbSegments === 0) { return []; }
const totalPathLength = segments[nbSegments - 1].distB;
if (totalPathLength === 0) { return []; }
const offset = asRatioToPathLength(pattern.offset, totalPathLength);
const endOffset = asRatioToPathLength(pattern.endOffset, totalPathLength);
const repeat = asRatioToPathLength(pattern.repeat, totalPathLength);
const repeatIntervalPixels = totalPathLength * repeat;

@@ -78,3 +78,3 @@ const startOffsetPixels = offset > 0 ? totalPathLength * offset : 0;

// 2. generate the positions of the pattern as offsets from the polygon start
// 2. generate the positions of the pattern as offsets from the path start
const positionOffsets = [];

@@ -112,9 +112,12 @@ let positionOffset = startOffsetPixels;

if (ptB.x !== ptA.x) {
return L.point(
ptA.x + ratio * (ptB.x - ptA.x),
ptA.y + ratio * (ptB.y - ptA.y)
);
return {
x: ptA.x + ratio * (ptB.x - ptA.x),
y: ptA.y + ratio * (ptB.y - ptA.y),
};
}
// special case where points lie on the same vertical axis
return L.point(ptA.x, ptA.y + (ptB.y - ptA.y) * ratio);
return {
x: ptA.x,
y: ptA.y + (ptB.y - ptA.y) * ratio,
};
}

@@ -125,2 +128,6 @@

parseRelativeOrAbsoluteValue,
// the following function are exported only for unit testing purpose
computeSegmentHeading,
asRatioToPathLength,
projectPatternOnPointPath,
};

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