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

leaflet-geometryutil

Package Overview
Dependencies
Maintainers
5
Versions
23
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

leaflet-geometryutil - npm Package Compare versions

Comparing version 0.8.1 to 0.9.0

spec/test.angle.js

4

package.json
{
"name": "leaflet-geometryutil",
"version": "0.8.1",
"version": "0.9.0",
"description": "Leaflet utility functions on geometries",

@@ -28,5 +28,5 @@ "keywords": [

"minami": "^1.1.1",
"mocha": "3.0.2",
"mocha": "5.2.0",
"mocha-phantomjs": "4.1.0"
}
}

@@ -52,4 +52,11 @@ Leaflet.GeometryUtil

Nothing yet.
### 0.9.0 ###
* Fix `interpolateOnLine()` doesn't return correct predecessor (#66, thanks @jb2b38)
* Add `angle()` and `destinationOnSegment()` (#71, thanks @trandaison)
### 0.8.1 ###
* Remove a deprecated function in Leaflet 1.x (#69)
### 0.8.0 ###

@@ -56,0 +63,0 @@

@@ -43,3 +43,4 @@ describe('Closest on path with precision', function() {

*/
assert.equal('LatLng(-1.46743, 21.57294)', closest.toString());
assert.almostEqual(closest.lat, -1.467431, 6)
assert.almostEqual(closest.lng, 21.5729367, 6)

@@ -54,3 +55,4 @@ // Change zoom and check that closest did not change.

closest = L.GeometryUtil.closest(map, line, ll);
assert.equal('LatLng(-1.46743, 21.57294)', closest.toString());
assert.almostEqual(closest.lat, -1.467431, 6)
assert.almostEqual(closest.lng, 21.5729367, 6)
// Restore zoom

@@ -166,3 +168,3 @@ map.off('moveend');

// so there is no result
// if not, we are in Leaflet 1.0, and we don't need to test it, because
// if not, we are in Leaflet 1.0, and we don't need to test it, because
// layers.getLayers()[0] will contain a multipolygon, and so there is a result

@@ -257,2 +259,2 @@ if (layers.getLayers()[0] instanceof L.LayerGroup) {

});
});

@@ -29,2 +29,2 @@ describe('Destination', function() {

});
});
});

@@ -72,2 +72,7 @@ describe('Interpolate on line', function() {

});
it('It should not return a negative predecessor index when interpolating a point on the first segment', function() {
var interp = L.GeometryUtil.interpolateOnLine(map, [llA, llB], 0.5);
assert.isTrue(interp.predecessor >= 0);
});
});

@@ -178,3 +178,3 @@ // Packaging/modules magic dance.

result = null,
i, n, distance;
i, n, distance, subResult;

@@ -186,4 +186,4 @@ if (layer instanceof Array) {

// recursive
for (var i = 0; i < layer.length; i++) {
var subResult = L.GeometryUtil.closest(map, layer[i], latlng, vertices);
for (i = 0; i < layer.length; i++) {
subResult = L.GeometryUtil.closest(map, layer[i], latlng, vertices);
if (subResult.distance < mindist) {

@@ -223,3 +223,3 @@ mindist = subResult.distance;

}
}
};
addLastSegment(latlngs);

@@ -231,6 +231,5 @@ }

if ( ! L.Polyline._flat(latlngs) ) {
for (var i = 0; i < latlngs.length; i++) {
for (i = 0; i < latlngs.length; i++) {
// if we are at the lower level, and if we have a L.Polygon, we add the last segment
var subResult = L.GeometryUtil.closest(map, latlngs[i], latlng, vertices);
subResult = L.GeometryUtil.closest(map, latlngs[i], latlng, vertices);
if (subResult.distance < mindist) {

@@ -343,3 +342,3 @@ mindist = subResult.distance;

var subResult = L.GeometryUtil.closestLayer(map, layer.getLayers(), latlng);
results.push(subResult)
results.push(subResult);
} else {

@@ -355,3 +354,3 @@ // Single dimension, snap on points, else snap on closest

}
results.push({layer: layer, latlng: ll, distance: distance})
results.push({layer: layer, latlng: ll, distance: distance});
}

@@ -501,22 +500,24 @@ }

var ratioDist = lineLength * ratio;
var a = pts[0],
b = pts[1],
distA = 0,
distB = a.distanceTo(b);
// follow the line segments [ab], adding lengths,
// follow the line segments [ab], adding lengths,
// until we find the segment where the points should lie on
var index = 1;
for (; index < n && distB < ratioDist; index++) {
a = b;
distA = distB;
b = pts[index];
distB += a.distanceTo(b);
}
// compute the ratio relative to the segment [ab]
var segmentRatio = ((distB - distA) !== 0) ? ((ratioDist - distA) / (distB - distA)) : 0;
var interpolatedPoint = L.GeometryUtil.interpolateOnPointSegment(a, b, segmentRatio);
return {
latLng: map.unproject(interpolatedPoint, maxzoom),
predecessor: index-2
};
var cumulativeDistanceToA = 0, cumulativeDistanceToB = 0;
for (var i = 0; cumulativeDistanceToB < ratioDist; i++) {
var pointA = pts[i], pointB = pts[i+1];
cumulativeDistanceToA = cumulativeDistanceToB;
cumulativeDistanceToB += pointA.distanceTo(pointB);
}
if (pointA == undefined && pointB == undefined) { // Happens when line has no length
var pointA = pts[0], pointB = pts[1], i = 1;
}
// compute the ratio relative to the segment [ab]
var segmentRatio = ((cumulativeDistanceToB - cumulativeDistanceToA) !== 0) ? ((ratioDist - cumulativeDistanceToA) / (cumulativeDistanceToB - cumulativeDistanceToA)) : 0;
var interpolatedPoint = L.GeometryUtil.interpolateOnPointSegment(pointA, pointB, segmentRatio);
return {
latLng: map.unproject(interpolatedPoint, maxzoom),
predecessor: i-1
};
},

@@ -713,4 +714,4 @@

@param {L.LatLng} latlng: origin point
@param {float}: heading in degrees, clockwise from 0 degrees north.
@param {float}: distance in meters
@param {float} heading: heading in degrees, clockwise from 0 degrees north.
@param {float} distance: distance in meters
@returns {L.latLng} the destination point.

@@ -739,3 +740,33 @@ Many thanks to Chris Veness at http://www.movable-type.co.uk/scripts/latlong.html

return L.latLng([lat2 * radInv, lon2]);
}
},
/**
Returns the the angle of the given segment and the Equator in degrees,
clockwise from 0 degrees north.
@param {L.Map} map: Leaflet map to be used for this method
@param {L.LatLng} latlngA: geographical point A of the segment
@param {L.LatLng} latlngB: geographical point B of the segment
@returns {Float} the angle in degrees.
*/
angle: function(map, latlngA, latlngB) {
var pointA = map.latLngToContainerPoint(latlngA),
pointB = map.latLngToContainerPoint(latlngB),
angleDeg = Math.atan2(pointB.y - pointA.y, pointB.x - pointA.x) * 180 / Math.PI + 90;
angleDeg += angleDeg < 0 ? 360 : 0;
return angleDeg;
},
/**
Returns a point snaps on the segment and heading away from the given origin point a distance.
@param {L.Map} map: Leaflet map to be used for this method
@param {L.LatLng} latlngA: geographical point A of the segment
@param {L.LatLng} latlngB: geographical point B of the segment
@param {float} distance: distance in meters
@returns {L.latLng} the destination point.
*/
destinationOnSegment: function(map, latlngA, latlngB, distance) {
var angleDeg = L.GeometryUtil.angle(map, latlngA, latlngB),
latlng = L.GeometryUtil.destination(latlngA, angleDeg, distance);
return L.GeometryUtil.closestOnSegment(map, latlng, latlngA, latlngB);
},
});

@@ -742,0 +773,0 @@

Sorry, the diff of this file is not supported yet

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