gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-11-28 11:04:02 26 4
gpt4 key购买 nike

正如您在这里看到的,每次缩放级别发生变化时,我都会删除和添加注释,但问题是速度太慢并且应用程序卡住了。我搜索了所有 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/

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