gpt4 book ai didi

javascript - 这里 map 放大集群点击

转载 作者:行者123 更新时间:2023-12-02 23:24:26 27 4
gpt4 key购买 nike

我正在 Here Maps 实例上使用聚类,它可以工作,显示聚类,但当我单击其中一个以显示包含的标记时,我找不到缩放的方法。是否可能或唯一的方法是使用鼠标滚轮或缩放按钮手动缩放?

这就是我创建集群并将其显示在 map 上的方式

let map = new H.Map(document.getElementById('map'),
defaultLayers.normal.map,{
center: {lat:{{ $map_center['lat'] }}, lng:{{ $map_center['lng'] }}},
zoom: 4
});

let sCluster = [];

// the coordinates come from an AJAX call
$.each(data,function(i, v) {
let coord = {lat:parseFloat(v["lat"]),lng:parseFloat(v["lng"])};

sCluster.push(new H.clustering.DataPoint(parseFloat(v["lat"]),parseFloat(v["lng"])));
});

let clusteredSugProvider = new H.clustering.Provider(sCluster,{
clusteringOptions: {
strategy: H.clustering.Provider.Strategy.GRID,
eps: 64,
minWeight: 2
}
});

let layer = new H.map.layer.ObjectLayer(clusteredSugProvider);

map.addLayer(layer);

最佳答案

我发现了如何在单击群集图标时进行缩放,这是我的解决方案:

// add a listener to the cluster which triggers on a tap event
clusteredSugProvider.addEventListener('tap', function (evt) {

// get the data of the object clicked
let cnt = evt.target.getData();

// if those data contain a data object it was a marker to be clicked
// mine has a string (not yet set in the code above) which I show inside an InfoBubble
if (typeof cnt.a.data !== 'undefined') {
let bubble = new H.ui.InfoBubble(evt.target.getPosition(), {
content: cnt.a.data.content
});
ui.addBubble(bubble);
} else {
// otherwise it was a cluster icon which doesn't contain a data object
// set the map center to the coordinates where the user clicked
// "true" is to have a smooth transition
map.setCenter(
map.screenToGeo(
evt.currentPointer.viewportX,
evt.currentPointer.viewportY
),
true
);

// increase the zoom level by an amount which fits your needs
// again "true" is to have a smooth transition
const zoomIn = () => {
map.setZoom(map.getZoom() + 2, true);
map.removeEventListener('mapviewchangeend', zoomIn);
};

map.addEventListener('mapviewchangeend', zoomIn);
}
}, false);

关于javascript - 这里 map 放大集群点击,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56808876/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com