- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我有一个缩放级别为 2-7 并使用 MarkerCluster 插件的传单 map ,默认情况下我有 L.MarkerClusterGroup 禁用缩放级别 2 的聚类(这意味着没有聚类)并且我试图允许用户单击一个按钮,然后将聚类缩放级别更改为 5。这可能吗?
我知道我可以通过创建两个 markercluster 组来做到这一点,一个没有聚类,一个有聚类并根据点击删除/添加它,但这看起来非常困惑。真的,有几种方法可以做到这一点,但它们非常笨拙。
代码:
默认(2 是最低级别的缩放):
var markers = new L.MarkerClusterGroup (
{
disableClusteringAtZoom: 2,
maxClusterRadius: 100,
animateAddingMarkers: true
});
我想做的能做的:
$('#mcluster').click(function() {
//do some code that sets the disableClusterAtZoom to 5
});
最佳答案
我找不到在缩放时禁用集群或为 disableClustering 设置新值的方法,但我找到了一种不太笨拙的方法来实现这一点。
var markers = new L.LayerGroup(); //non cluster layer is added to map
markers.addTo(map);
var clusters = new L.MarkerClusterGroup (
{
disableClusteringAtZoom: 5,
maxClusterRadius: 100,
animateAddingMarkers: true
}); //cluster layer is set and waiting to be used
var clusterStatus = 'no'; //since non cluster group is on by default, the status for cluster is set to no
$('#mcluster').click(function( event ) {
if(clusterStatus === 'no'){
clusterStatus = 'yes';
var current1 = markers.getLayers(); //get current layers in markers
map.removeLayer(markers); // remove markers from map
clusters.clearLayers(); // clear any layers in clusters just in case
current1.forEach(function(item) { //loop through the current layers and add them to clusters
clusters.addLayer(item);
});
map.addLayer(clusters);
} else {
clusterStatus = 'no'; //we're turning off clustering here
var current2 = clusters.getLayers(); //same code as before just reversed
map.removeLayer(clusters);
markers.clearLayers();
current2.forEach(function(item) {
markers.addLayer(item);
});
map.addLayer(markers);
}
});
我确信有一个更优雅的解决方案,但随着我不断增长的知识,这就是我想出的。
关于javascript - 如何在单击 Leaflet map 时更改群集缩放级别?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32480469/
我正在尝试实现类似于 Leaflet.buffer 的缓冲区在我的 map 上。然而,Leaflet.buffer 似乎只适用于 Leaflet.Draw。 我正在使用 Leaflet Editabl
我正试图摆脱 Google map ,因为我受够了他们现在的速度有多慢!我决定试一试 Leaflet,这似乎是个不错的选择。下面是我的代码: initMap(); function initMap()
在 Leaflet 中,是否可以使用 {clickable:false} 定义标记或折线,以便点击传递到下方的任何内容 - 无论是 map 还是可点击的几何对象? 目前我通过使标记/折线可点击并自己传
我正在结合 Leaflet 使用 HTML map 进行一些测试。 .服务器端我有一个 Ruby Sinatra 应用程序,它提供由 MySQL 表获取的 json 标记。使用 2k-5k 和可能更多
我无法使用Leaflet(0.7.7)/Leaflet.Draw(latest)将Layer属性转换为GEOJson对象的属性。我的工作流程是: 1创建 map :var map = L.map('#
我正在使用使用传单 api 的应用程序。 简介 我需要绘制不同类型的围栏,使用装饰器我可以在一定程度上为折线应用良好的视觉效果,但不多。 问题 我愿意显示双绞线而不是破折号、点或普通线,我知道双绞线将
我在我的应用程序中使用 WebView 来显示 Leaflet map 。 在 HTML 文件中,我有以下信用和链接: L.tileLayer('https://api.tiles.mapbox.co
我正在使用https://github.com/Leaflet/Leaflet.draw插件,并且试图检索已编辑图层的图层类型。 在draw:created事件中,我有layer和layerType,
我的左下角有缩放控件和比例尺。 我遇到的问题是,当我的 map 在移动设备上旋转时,它们与左上角的自定义控制面板重叠。 那么如何使比例尺水平位于缩放控件旁边? 最佳答案 您可以通过更改比例控件的 CS
我想计算标记的高度,但我在传单中没有找到任何解决方案。我找到了海拔插件,它允许在 map 上绘制海拔剖面图,但我不需要它。你知道如何计算高度吗?谢谢。 最佳答案 编辑:一个不错的选择 为任何可能需要它
我明白我可以使用通用Leaflet layer ,以及更高级的 map 框 featureLayer ,它提供了作为过滤器的有用功能。但是,我不明白两者之间的区别 marker = L.Marker
我正在尝试在 Render mapbox vector tiles inside react-leaflet? 中描述此实现工作,除了我使用的是 TypeScript。 所以我的文件看起来像这样: i
我正在尝试将我的点在 map 上的正确位置作为 Latlng: let point = L.point(0,0) // x=0,y=0 let latlng = map.unproject(point
我正在使用 Leaflet.VectorGrid用于在传单 map 上加载 pbf 矢量切片的插件。我检索矢量切片的 API 需要传递授权 header 。在 Mapbox GL js 中,这可以通过
我们有一张 map ,在某个缩放级别,我们开始对标记进行聚类。 现在我希望能够删除某些标记。我可以删除不参与集群的标记,但集群中的标记不会被删除,因为代码不会遍历它们。 我会发布代码,但它无处不在,而
我仅在同一位置的标记上进行聚类(即 maxClusterRadius = 0)。单击集群时,我希望它以特定的缩放级别(不是最大缩放)居中并放大,然后立即 spiderfy。使用以下代码,spiderf
使用 Leaflet javascript。我希望我的“清除按钮”能做两件事... 1) 取消选中所有 L.Control 层2) 从 map 中移除当前叠加层 我可以使用这段代码轻松完成第一个: v
我正在开发一个包含大量标记的应用程序,并希望将它们聚类。我找到了 Leaflet.markercluster,它做得很好。但是,我想自定义标记的聚类。具体来说,我想根据标记所在的国家/地区对我的标记进
有点奇怪,希望有人能帮忙。 在传单中,一旦用户输入了纬度/经度并向 map 添加了一个点,我希望能够在该点周围添加一个 10 公里的正方形。 我已经尝试四处寻找计算以找到 x 公里外的正方形的角,但没
我在 leaflet.js 中创建了一个具有多个图层的 map ,但无法弄清楚如何切换一个图层以最初显示在 map 上。 Here is the link 我确信它相当简单,但就是无法弄清楚。 最佳答
我是一名优秀的程序员,十分优秀!