Код: Выделить всё
const zoomToCluster = (cluster: Feature) => {
const features = cluster.get('features')
const extent = boundingExtent(
features.map((f: any) => f.getGeometry().getFlatCoordinates())
)
viewRef.current.fit(extent,
{duration: 1000, padding: [200, 200, 200, 200]}
)
}
Код: Выделить всё
map.on('click', (e) => {
clusters.getFeatures(e.pixel).then((clickedFeatures) => {
if (clickedFeatures.length) {
// Get clustered Coordinates
const features = clickedFeatures[0].get('features');
if (features.length > 1) {
const extent = boundingExtent(
features.map((r) => r.getGeometry().getCoordinates()),
);
map.getView().fit(extent, {duration: 1000, padding: [50, 50, 50, 50]});
}
}
});
});
Я проверил, и getCoordinates() возвращает правильные координаты моего многоугольника, но результатом является массив пар, поэтому я использовал Вместо этого getFlatCoordinates().
Подробнее здесь: https://stackoverflow.com/questions/797 ... ngle-point
Мобильная версия