将空叠加层添加到传单地图?
Add empty overlay to leaflet map?
正在寻找将空叠加层添加到 Leaflet
地图的方法。我有多个 Leaflet
叠加层,它们从实时服务器加载数据。因为我使用的是自定义 UI 控件而不是默认的 Leaflet
控件,所以我有一个侦听器,每次创建新标记时,都会检查它们的关联层是否为 active
,并且如果是,则将标记添加到该图层。
$rootScope.on('newMarkers',markers)->
type = *fn to find type*
if mapFactory.currentLayers[type]?.active
mapFactory.addLayer(markers, type)
)
我不认为构建逻辑来查看它是否是第一次时间将标记添加到该层是有意义的,而是宁愿创建一个空层并添加之后的数据。我知道你可以使用 L.geoJson
类型来做到这一点,但这一层完全由普通 markers
构成。有什么建议
您可以 L.LayerGroup
用于此:
Used to group several layers and handle them as one. If you add it to the map, any layers added or removed from the group will be added/removed on the map as well. Implements ILayer interface.
参考:http://leafletjs.com/reference.html#layergroup
或L.FeatureGroup
:
Extended layerGroup that also has mouse events (propagated from members of the group) and a shared bindPopup method. Implements ILayer interface.
正在寻找将空叠加层添加到 Leaflet
地图的方法。我有多个 Leaflet
叠加层,它们从实时服务器加载数据。因为我使用的是自定义 UI 控件而不是默认的 Leaflet
控件,所以我有一个侦听器,每次创建新标记时,都会检查它们的关联层是否为 active
,并且如果是,则将标记添加到该图层。
$rootScope.on('newMarkers',markers)->
type = *fn to find type*
if mapFactory.currentLayers[type]?.active
mapFactory.addLayer(markers, type)
)
我不认为构建逻辑来查看它是否是第一次时间将标记添加到该层是有意义的,而是宁愿创建一个空层并添加之后的数据。我知道你可以使用 L.geoJson
类型来做到这一点,但这一层完全由普通 markers
构成。有什么建议
您可以 L.LayerGroup
用于此:
Used to group several layers and handle them as one. If you add it to the map, any layers added or removed from the group will be added/removed on the map as well. Implements ILayer interface.
参考:http://leafletjs.com/reference.html#layergroup
或L.FeatureGroup
:
Extended layerGroup that also has mouse events (propagated from members of the group) and a shared bindPopup method. Implements ILayer interface.