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

leaflet-geometryutil

Package Overview
Dependencies
Maintainers
6
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.10.2 to 0.10.3

spec/test.closestCircle.js

2

package.json
{
"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

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