使用 Mapbox Maps iOS SDK 平移时出现故障 3d 地形图块加载和地图崩溃

问题描述

以下代码取自 MapBox/maps-ios-SDK git 存储库:https://github.com/mapbox/mapbox-maps-ios/blob/main/Examples/Examples/All%20Examples/TerrainExample.swift

我在 iPhone 12 Pro Max 部署目标上使用 Xcode 12.4 和 iOS 14.4。

以上链接指向存储库示例部分中的 3d TerrainExample.swift 文件

应用程序构建成功并加载了 3d 地形图,但是当在地图上平移时,图块加载变得非常困难,地图似乎很快就会崩溃,导致黑屏。

导入 UIKit 导入 MapBoxMaps

class ViewController: UIViewController {

internal var mapView: MapView!



override func viewDidLoad() {
    super.viewDidLoad()
    
    
    let resourceOptions = ResourceOptions(accesstoken: "access-token")
    
    
    self.mapView = MapView(with: view.bounds,resourceOptions: resourceOptions,styleURL: .custom(url: URL(string: "mapBox://styles/chris2020/ckkllfz2d3w6v17oi8t4p8x5y")!))
            mapView.autoresizingMask = [.flexibleWidth,.flexibleHeight]

    self.view.addSubview(mapView)
    
    
    let centerCoordinate = CLLocationCoordinate2D(latitude: 54.55209311674105,longitude: -3.0136239887454472)
            mapView.cameraManager.setCamera(centerCoordinate: centerCoordinate,zoom: 13.1,bearing: 80,pitch: 85)

            self.mapView.on(.styleLoadingFinished) { [weak self] _ in
                self?.addTerrain()
            }

    
}

func addTerrain() {
     var demSource = RasterDemSource()
     demSource.url = "mapBox://mapBox.mapBox-terrain-dem-v1"
     demSource.tileSize = 512
     demSource.maxzoom = 14.0
     _ = self.mapView.style.addSource(source: demSource,identifier: "mapBox-dem")

     var terrain = Terrain(sourceId: "mapBox-dem")
     terrain.exaggeration = .constant(1.5)

     _ = self.mapView.style.setTerrain(terrain)

     var skyLayer = SkyLayer(id: "sky-layer")
     skyLayer.paint?.skyType = .atmosphere
     skyLayer.paint?.skyAtmosphereSun = .constant([0.0,0.0])
     skyLayer.paint?.skyAtmosphereSunIntensity = .constant(15.0)

     _ = self.mapView.style.addLayer(layer: skyLayer)
 }

}

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)

相关问答

Selenium Web驱动程序和Java。元素在(x,y)点处不可单击。其...
Python-如何使用点“。” 访问字典成员?
Java 字符串是不可变的。到底是什么意思?
Java中的“ final”关键字如何工作?(我仍然可以修改对象。...
“loop:”在Java代码中。这是什么,为什么要编译?
java.lang.ClassNotFoundException:sun.jdbc.odbc.JdbcOdbc...