How to find closest marker leaflet.js

久未见 提交于 2019-12-05 03:44:48

Try leaflet-knn, which does nearest-neighbor lookups: given a point and a bunch of other points, it finds the nearest neighbors (as it says on the tin)

Leaflet.GeometryUtil is the best solution I found for that (https://github.com/makinacorpus/Leaflet.GeometryUtil). Use L.GeometryUtil.closestLayer.

It's more practical to use than leaflet-knn because you can send an array of layers (markers for examples), instead of only a geojson layer. But more importantly, it seems faster (about 90% faster with a set of 500+ markers, cold start, on Chrome 36, although on FF31 it's comparable)

You could use the turf.js library

http://turfjs.org/examples/turf-nearest/

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!