# leaflet-knn

> next nearest neighbors for leaflet

Latest version **0.1.0** (published 2013-09-27) · BSD license · 0 weekly downloads

## Install

```sh
npm install leaflet-knn
pnpm add leaflet-knn
yarn add leaflet-knn
bun add leaflet-knn
```

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support; pre 1.0.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.1.0 |
| Published | 2013-09-27 |
| First published | 2013-04-25 |
| Weekly downloads | 0 |
| License | BSD |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 1 |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Author | Tom MacWright |
| Maintainers | tmcw |
| Keywords | maps, leaflet, plugin, next, nearest, neighbor |

## Links

- npm: https://www.npmjs.com/package/leaflet-knn
- npm.io page: https://npm.io/package/leaflet-knn

## Dependencies (1)

- [sphere-knn](https://npm.io/package/sphere-knn.md) ~1.2.1

## Recent versions

- 0.1.0 (latest) — 2013-09-27
- 0.0.0 — 2013-04-25

## README

## leaflet-knn

Next-nearest neighbor searches with [sphere-knn](https://github.com/darkskyapp/sphere-knn),
with a [Leaflet](http://leafletjs.com/)-friendly API.

## example

```js
var gj = L.geoJson(GEOJSON_DATA);
var nearest = leafletKnn(gj).nearest(L.latLng(38, -78), 5);
```

## using it

    wget https://raw.github.com/mapbox/leaflet-knn/master/leaflet-knn.min.js

(or without the `.min.` if you want more debugging power)

With [browserify](https://github.com/substack/node-browserify)

    npm install leaflet-knn

## api

### `var index = leafletKnn(layer)`

Generates a lookup function from an `L.geoJson` layer object.

API is the same as the [sphere-knn](https://github.com/darkskyapp/sphere-knn) API
for the lookup function, but with nice handling for `l.latLng`

### `index.nearest(point: L.LatLng or [lon, lat], n, max_distance)`

Given a point, find the nearest points to it. If the index contains multi-point
features, like lines, polygons, and so on, it returns _points in those features_
and can return more than one point in each feature.

* point: L.LatLng or [lon, lat], index, [max points: int], [max distance: number])`
* n: the maximum number of points returned from the search
* max_distance: maximum distance in meters

### `index.nearestLayer(point: L.LatLng or [lon, lat], n, max_distance)`

Like `nearest`, except multiple matches in the same multi-point feature are
collapsed, so the array returned has one result per layer.

* point: L.LatLng or [lon, lat], index, [max points: int], [max distance: number])`
* n: the maximum number of points returned from the search
* max_distance: maximum distance in meters

---
_Source: https://npm.io/package/leaflet-knn · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
