leaflet-geometryutil
Advanced tools
Comparing version 0.10.2 to 0.10.3
{ | ||
"name": "leaflet-geometryutil", | ||
"version": "0.10.2", | ||
"version": "0.10.3", | ||
"description": "Leaflet utility functions on geometries", | ||
@@ -5,0 +5,0 @@ "keywords": [ |
@@ -0,6 +1,7 @@ | ||
<a href="https://www.npmjs.com/package/leaflet-geometryutil"><img alt="npm" src="https://img.shields.io/npm/dt/leaflet-geometryutil"></a> | ||
<a href="https://www.npmjs.com/package/leaflet-geometryutil"><img alt="npm" src= "https://img.shields.io/npm/v/leaflet-geometryutil?color=red"></a> | ||
Leaflet.GeometryUtil | ||
==================== | ||
[![Build Status](https://travis-ci.org/makinacorpus/Leaflet.GeometryUtil.png?branch=master)](https://travis-ci.org/makinacorpus/Leaflet.GeometryUtil) | ||
* Tested with stable Leaflet 0.7.0 | ||
@@ -50,2 +51,6 @@ * Tested with Leaflet 1.0.0-rc.3 | ||
### 0.10.3 ### | ||
* add support for closestOnCircle (#101, thanks to @danyhoron) | ||
### 0.10.2 ### | ||
@@ -52,0 +57,0 @@ |
@@ -161,2 +161,34 @@ // Packaging/modules magic dance. | ||
/** | ||
Returns the closest point of a {L.LatLng} on a {L.Circle} | ||
@tutorial closest | ||
@param {L.LatLng} latlng - The position to search | ||
@param {L.Circle} circle - A Circle defined by a center and a radius | ||
@returns {L.LatLng} Closest geographical point on the circle circumference | ||
*/ | ||
closestOnCircle: function (circle, latLng) { | ||
const center = circle.getLatLng(); | ||
const circleRadius = circle.getRadius(); | ||
const radius = typeof circleRadius === 'number' ? circleRadius : circleRadius.radius; | ||
const x = latLng.lng; | ||
const y = latLng.lat; | ||
const cx = center.lng; | ||
const cy = center.lat; | ||
// dx and dy is the vector from the circle's center to latLng | ||
const dx = x - cx; | ||
const dy = y - cy; | ||
// distance between the point and the circle's center | ||
const distance = Math.sqrt(dx * dx + dy * dy) | ||
// Calculate the closest point on the circle by adding the normalized vector to the center | ||
const tx = cx + (dx / distance) * radius; | ||
const ty = cy + (dy / distance) * radius; | ||
return new L.LatLng(ty, tx); | ||
}, | ||
/** | ||
Returns the closest latlng on layer. | ||
@@ -297,2 +329,6 @@ | ||
} else { | ||
if (layer instanceof L.Circle){ | ||
ll = this.closestOnCircle(layer, latlng); | ||
distance = L.GeometryUtil.distance(map, latlng, ll); | ||
} else | ||
// Single dimension, snap on points, else snap on closest | ||
@@ -342,2 +378,6 @@ if (typeof layer.getLatLng == 'function') { | ||
} else { | ||
if (layer instanceof L.Circle){ | ||
ll = this.closestOnCircle(layer, latlng); | ||
distance = L.GeometryUtil.distance(map, latlng, ll); | ||
} else | ||
// Single dimension, snap on points, else snap on closest | ||
@@ -344,0 +384,0 @@ if (typeof layer.getLatLng == 'function') { |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
New author
Supply chain riskA new npm collaborator published a version of the package for the first time. New collaborators are usually benign additions to a project, but do indicate a change to the security surface area of a package.
Found 1 instance in 1 package
1660927
73
2586
178
18