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.7.2 to 0.8.0

spec/test.nClosestLayers.js

4

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

@@ -22,3 +22,3 @@ "keywords": [

"dependencies": {
"leaflet": "^0.7.0"
"leaflet": ">=0.7.0"
},

@@ -25,0 +25,0 @@ "devDependencies": {

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

* Nothing changed yet.
Nothing yet.
### 0.8.0 ###
* Update leaflet dependency to `>=0.7.0` (#64, thanks @kozze89)
* Add `nClosestLayer` (#62, thanks @haoliangyu)
### 0.7.2 ###
* Fix #59, `closest` method using a shallow copy of latLngs => deep copy now
### 0.7.1 ###

@@ -56,0 +65,0 @@

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

Shortcut function for planar distance between two {L.LatLng} at current zoom.
@tutorial distance-length

@@ -50,3 +50,3 @@

@param {L.Map} map Leaflet map to be used for this method
@param {L.LatLng} latlng - The position to search
@param {L.LatLng} latlng - The position to search
@param {L.LatLng} latlngA geographical point A of the segment

@@ -111,3 +111,3 @@ @param {L.LatLng} latlngB geographical point B of the segment

* @tutorial distance-length
*
*
* @param {L.Polyline|Array<L.Point>|Array<L.LatLng>} coords Set of coordinates

@@ -196,3 +196,3 @@ * @returns {Number} Total length (pixels for Point, meters for LatLng)

return result;
} else if (layer[0] instanceof L.LatLng
} else if (layer[0] instanceof L.LatLng
|| typeof layer[0][0] === 'number'

@@ -205,3 +205,3 @@ || typeof layer[0].lat === 'number') { // we could have a latlng as [x,y] with x & y numbers or {lat, lng}

}
// if we don't have here a Polyline, that means layer is incorrect

@@ -230,3 +230,3 @@ // see https://github.com/makinacorpus/Leaflet.GeometryUtil/issues/23

// we have a multi polygon / multi polyline / polygon with holes
// we have a multi polygon / multi polyline / polygon with holes
// use recursive to explore and return the good result

@@ -260,3 +260,3 @@ if ( ! L.Polyline._flat(latlngs) ) {

}
// Keep the closest point of all segments

@@ -323,2 +323,52 @@ for (i = 0, n = latlngs.length; i < n-1; i++) {

/**
Returns the n closest layers to latlng among a list of input layers.
@param {L.Map} map - Leaflet map to be used for this method
@param {Array<L.ILayer>} layers - Set of layers
@param {L.LatLng} latlng - The position to search
@param {?Number} [n=layers.length] - the expected number of output layers.
@returns {Array<object>} an array of objects ``{layer, latlng, distance}`` or ``null`` if the input is invalid (empty list or negative n)
*/
nClosestLayers: function (map, layers, latlng, n) {
n = typeof n === 'number' ? n : layers.length;
if (n < 1 || layers.length < 1) {
return null;
}
var results = [];
var distance, ll;
for (var i = 0, m = layers.length; i < m; i++) {
var layer = layers[i];
if (layer instanceof L.LayerGroup) {
// recursive
var subResult = L.GeometryUtil.closestLayer(map, layer.getLayers(), latlng);
results.push(subResult)
} else {
// Single dimension, snap on points, else snap on closest
if (typeof layer.getLatLng == 'function') {
ll = layer.getLatLng();
distance = L.GeometryUtil.distance(map, latlng, ll);
}
else {
ll = L.GeometryUtil.closest(map, layer, latlng);
if (ll) distance = ll.distance; // Can return null if layer has no points.
}
results.push({layer: layer, latlng: ll, distance: distance})
}
}
results.sort(function(a, b) {
return a.distance - b.distance;
});
if (results.length > n) {
return results.slice(0, n);
} else {
return results;
}
},
/**
* Returns all layers within a radius of the given position, in an ascending order of distance.

@@ -325,0 +375,0 @@ @param {L.Map} map Leaflet map to be used for this method

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

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