我正在努力做到这一点,以使制造商保持聚集状态,即使您的放大倍数很高且标记彼此之间的距离也不远。
我要解决的问题是我永远不应该显示各个标记的实际位置,因此我希望即使在高缩放级别下,并且标记也不要彼此靠近,它们仍会聚在一起。< / p>
我该如何实现?
我尝试将clusterMaxZoom设置为不同的级别,但这似乎对群集何时群集没有任何影响。
以下是用于群集的代码:
map.on('load', function() {
// Add a new source from our GeoJSON data and set the
// 'cluster' option to true. GL-JS will add the point_count property to your source data.
map.addSource('users', {
type: "geojson",
// Point to GeoJSON data. This example visualizes all M1.0+ users
// from 12/22/15 to 1/21/16 as logged by USGS' Earthquake hazards program.
data: markers,
cluster: true,
clusterMaxZoom: 14, // Max zoom to cluster points on
clusterRadius: 50 // Radius of each cluster when clustering points (defaults to 50)
});
map.addLayer({
id: "clusters",
type: "circle",
source: "users",
filter: ["has", "point_count"],
paint: {
// Use step expressions (https://docs.mapbox.com/mapbox-gl-js/style-spec/#expressions-step)
// with three steps to implement three types of circles:
// * Blue, 20px circles when point count is less than 100
// * Yellow, 30px circles when point count is between 100 and 750
// * Pink, 40px circles when point count is greater than or equal to 750
"circle-color": ["step", ["get", "point_count"], "#51bbd6", 100, "#f1f075", 750, "#f28cb1" ],
"circle-radius": ["step",["get", "point_count"], 20, 100, 30, 750, 40]
}
});