如何隐藏集群中的标记(Mapbox.js / Leaflet Markercluster)?
How to hide markers that are in a cluster (Mapbox.js / Leaflet Markercluster)?
我正在地图上显示照片,这些照片聚集在彼此靠近的地方。出于某种原因,我无法弄清楚,标记集群中的标记仍然显示 - 在它们所在的集群下方或上方。(有关演示,请参见 here)。
当它们恰好在集群下方时,这只是一个外观问题(我仍然想解决),因为单击集群仍会按预期放大该集群。
但是,当标记在群集上方呈现时,单击群集几乎总是会注册为对标记的单击,这不是预期的行为。
长话短说,我如何让包含的标记从我的集群中消失(并且很明显,一旦它们不再在集群组中,就让它们重新出现?
这是相关代码:
< script >
L.mapbox.accessToken = '###MyMapboxToken###';
var map = L.mapbox.map('home-worldmap', 'mapbox.dark', {
// These options apply to the tile layer in the map.
tileLayer: {
// This map option disables world wrapping. by default, it is false.
continuousWorld: false,
// This option disables loading tiles outside of the world bounds.
noWrap: true
}
}).setView([30, 0], 2);
map.scrollWheelZoom.disable();
var clusterGroup = new L.MarkerClusterGroup();
map.addLayer(clusterGroup);
var myLayer = L.mapbox.featureLayer().addTo(map);
var geojson = {
type: 'FeatureCollection',
features: [{
type: 'Feature',
geometry: {
type: 'Point',
coordinates: [-19.512555, 63.530581666667]
},
properties: {
title: 'Skógafoss from Below',
'marker-size': 'small',
'marker-color': '#ffcc11',
'marker-symbol': 'camera',
url: 'http://phototastic.world/photo/skogafoss-from-below/'
}
}, {
type: 'Feature',
geometry: {
type: 'Point',
coordinates: [-23.31073, 64.92612]
},
properties: {
title: 'Kirkjufellsfoss on a Cloudy Day',
'marker-size': 'small',
'marker-color': '#ffcc11',
'marker-symbol': 'camera',
url: 'http://phototastic.world/photo/kirkjufellsfoss-on-a-cloudy-day/'
}
}
/* more Features in the same format ... */
]
};
myLayer.setGeoJSON(geojson);
myLayer.on('click', function(e) {
document.location.href = e.layer.feature.properties.url;
});
clusterGroup.addLayer(myLayer);
map.fitBounds(myLayer.getBounds()); < /script>
可在此处找到完整的源代码:http://phototastic.world/world-travels/
感谢您的帮助!
我无法真正在 fiddle 中进行测试,因为您正在使用令牌和其他东西,但我认为 "issue" 是因为您将 mapbox 图层添加到地图,然后是地图的集群层,这意味着从技术上讲,在传单方面,两者都在地图上。
所以集群层运行正确,聚合数据和东西,但 mapbox 层也是独立添加的,因此显示。
尝试删除
.addTo(map);
在
var myLayer = L.mapbox.featureLayer().addTo(map);
我正在地图上显示照片,这些照片聚集在彼此靠近的地方。出于某种原因,我无法弄清楚,标记集群中的标记仍然显示 - 在它们所在的集群下方或上方。(有关演示,请参见 here)。
当它们恰好在集群下方时,这只是一个外观问题(我仍然想解决),因为单击集群仍会按预期放大该集群。
但是,当标记在群集上方呈现时,单击群集几乎总是会注册为对标记的单击,这不是预期的行为。
长话短说,我如何让包含的标记从我的集群中消失(并且很明显,一旦它们不再在集群组中,就让它们重新出现?
这是相关代码:
< script >
L.mapbox.accessToken = '###MyMapboxToken###';
var map = L.mapbox.map('home-worldmap', 'mapbox.dark', {
// These options apply to the tile layer in the map.
tileLayer: {
// This map option disables world wrapping. by default, it is false.
continuousWorld: false,
// This option disables loading tiles outside of the world bounds.
noWrap: true
}
}).setView([30, 0], 2);
map.scrollWheelZoom.disable();
var clusterGroup = new L.MarkerClusterGroup();
map.addLayer(clusterGroup);
var myLayer = L.mapbox.featureLayer().addTo(map);
var geojson = {
type: 'FeatureCollection',
features: [{
type: 'Feature',
geometry: {
type: 'Point',
coordinates: [-19.512555, 63.530581666667]
},
properties: {
title: 'Skógafoss from Below',
'marker-size': 'small',
'marker-color': '#ffcc11',
'marker-symbol': 'camera',
url: 'http://phototastic.world/photo/skogafoss-from-below/'
}
}, {
type: 'Feature',
geometry: {
type: 'Point',
coordinates: [-23.31073, 64.92612]
},
properties: {
title: 'Kirkjufellsfoss on a Cloudy Day',
'marker-size': 'small',
'marker-color': '#ffcc11',
'marker-symbol': 'camera',
url: 'http://phototastic.world/photo/kirkjufellsfoss-on-a-cloudy-day/'
}
}
/* more Features in the same format ... */
]
};
myLayer.setGeoJSON(geojson);
myLayer.on('click', function(e) {
document.location.href = e.layer.feature.properties.url;
});
clusterGroup.addLayer(myLayer);
map.fitBounds(myLayer.getBounds()); < /script>
可在此处找到完整的源代码:http://phototastic.world/world-travels/
感谢您的帮助!
我无法真正在 fiddle 中进行测试,因为您正在使用令牌和其他东西,但我认为 "issue" 是因为您将 mapbox 图层添加到地图,然后是地图的集群层,这意味着从技术上讲,在传单方面,两者都在地图上。 所以集群层运行正确,聚合数据和东西,但 mapbox 层也是独立添加的,因此显示。
尝试删除
.addTo(map);
在
var myLayer = L.mapbox.featureLayer().addTo(map);