如何将 Mapbox 相机置于给定特征的中心?

问题描述 投票:0回答:1

我正在从 geoJSON 功能列表开始渲染一些 FillLayers。

现在我想以编程方式将相机移动到给定功能的中心,以便整个功能在视口中可见。


    func centerCameraTo(feature: Feature) {
        guard let mapView = self.mapView else { print("[centerCameraTo] no mapView"); return }
        
        mapView.mapboxMap.setCamera(to: ???)

    }
    

我该怎么做?

swift mapbox
1个回答
0
投票

你没有指定你的特征的类型,如果它是一个点,你可以提取坐标并使用setCenter

function centerCameraTo(feature: Featuere<Point>) {
   mapView.setCenter(feature.geometry.coordinates);
}

如果几何图形更复杂(多边形,LineString等),您可以使用fitBounds函数。

© www.soinside.com 2019 - 2024. All rights reserved.