问题描述
我正在使用 Leaflet.markercluster 将我的标记聚集在我的 Mapbox地图.标记将使用json
文件填充.我需要的是一个搜索功能,该功能可以根据搜索字符串弹出必要的标记.我了解了传单搜索,但是无法将其与我的代码集成.我该怎么办?
I am using Leaflet.markercluster to cluster my markers in my Mapbox Map. The markers are to be populated using a json
file. All I need is a search feature which can popup the requisite marker based on search string. I got to know about Leaflet-search, but am unable to integrate it with my code. How should I go about this?
推荐答案
只需遍历您的图层组(例如标记群集组"),例如使用 eachLayer(fn)
,对标记属性进行测试,如果您找到目标标记,使用markercluster zoomToShowLayer(targetMarker)
方法.
Simply iterate through your layer group (like your Marker Cluster Group), e.g. using eachLayer(fn)
, test against the marker attributes, and if you find your target marker, get the map to zoom and/or pan to it using markercluster zoomToShowLayer(targetMarker)
method.
这篇关于在标记群集组Leaflet-MarkerCluster中搜索标记的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!