swift - MapBox IOS SDK swift : how to show the user annotations from specific zoomLevel without delete and add again?

标签 swift xcode swift2 mapbox

正如您在这里看到的,每次缩放级别发生变化时,我都会删除和添加注释,但问题是速度太慢并且应用程序卡住了。我搜索了所有 MapBox 文档,但没有找到实现它的更好方法。

isFull 、 isMedium 和 isEmpty 只是我需要的缩放级别的标志。

感谢帮助者:)

内部函数 mapView(mapView: MGLMapView, regionDidChangeAnimated animated: Bool) { 如果 (mapView.zoomLevel > 14) {

        isFull = true
        isMedium = false
        isEmpty = false
        if (gotMyHistory)
        {
            if (mapView.annotations?.count > 0){mapView.removeAnnotations(mapView.annotations!)}
        LoadAnnotation()
        }
    }else if (mapView.zoomLevel <= 14 && mapView.zoomLevel >= 8 && !isMedium )
    {

        isFull = false
        isMedium = true
        isEmpty = false
        if (gotMyHistory )
        {
            if (mapView.annotations?.count > 0){mapView.removeAnnotations(mapView.annotations!)}
            LoadAnnotation()
        }
    }else if (mapView.zoomLevel < 8 && !isEmpty)
    {
        isFull = false
        isMedium = false
        isEmpty = true
        if (gotMyHistory)
        {
            if (mapView.annotations?.count > 0){mapView.removeAnnotations(mapView.annotations!)}
        }
    }

最佳答案

我意识到这可能与原始发帖人无关,因为已经过去了很多时间,但希望对其他人有所帮助。 我遇到了同样的问题,经过 3 种不同的实现(首先是像您一样使用注释),我发现创建自己的 map 层是最流畅的选择。

  // Wait until the style is loaded before modifying the map style
func mapView(_ mapView: MGLMapView, didFinishLoading style: MGLStyle) {

    //Bicycle Parking Annotations Layer
    let bicycleParkingSource = MGLShapeSource(identifier: "bicycleParking", features: [], options: nil)
    self.bicycleParkingSource = bicycleParkingSource

    style.setImage(UIImage(named: "bicycleParking")!, forName: "bicycleParking") // referenced by an MGLSymbolStyleLayer’s iconImage

    let bicycleParkingSymbols = MGLSymbolStyleLayer(identifier: "bicycleParking", source: bicycleParkingSource)
    bicycleParkingSymbols.iconImageName = MGLStyleValue(rawValue: "bicycleParking")
    bicycleParkingSymbols.minimumZoomLevel = 12.0

    style.addSource(bicycleParkingSource)
    style.addLayer(bicycleParkingSymbols)
}

我实际上发现 Mapbox 在完成后有一个很好的教程,它有助于改进我的代码。 https://www.mapbox.com/ios-sdk/examples/runtime-multiple-annotations/ 如您所见,您可以为图层设置最大可见缩放级别。希望这可以帮助!

关于swift - MapBox IOS SDK swift : how to show the user annotations from specific zoomLevel without delete and add again?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39318594/

相关文章:

ios - 如何从我的 iOS 应用程序发送邮件 - SWIFT

ios - 如何使用以下数据填充 tableVIew 单元格?

ios - 如何使用 Xcode/Swift 创建横跨屏幕的横幅图像?

swift - 使用 NSDate 过渡到 swift 3 进行倒计时

ios swift 按功能替换选择器

ios - 从 Swift 中的任意 anchor 呈现弹出窗口

php - base64 字符串中的 IOS Swift UIImage 到 PHP

ios - Storyboard更改未在模拟器/iphone 中更新

xcode - 应用程序在到达 main.m 之前在模拟器 5.0 上崩溃

ios - UIWebView 和 Swift : Detect when a video starts playing