小编Wil*_*ill的帖子

如何在 iOS 上为 Mapbox 动态更新 MGLShapeSource 的 MGLPointFeature 属性值?

我的应用程序将数据(包括坐标和其他信息)存储在本地数据库中。由于数据点的数量,该应用程序使用聚类在 iOS 上使用 Mapbox 显示数据。一些标记样式基于数据,这些数据可能会在运行时发生变化。地图设置为:

// fetch data from DB
let dataArray: [MyData] = fetchData()

// build features from data array
var features = [MGLPointFeature]()
dataArray.forEach({ (data) in
   let feature = MGLPointFeature()
   feature.identifier = data.id
   feature.coordinate = CLLocationCoordinate2D(latitude: data.lat, longitude: data.lng)
   // our attributes
   feature.attributes = [
      "amount": data.amount
      "marked": false
   ]
   features.append(feature)
})

// make and add source
let source = MGLShapeSource(identifier: "MySourceId", features: features, options: [
   .clustered: true
])
style.addSource(source)

// regular marker layer
let layer = MGLSymbolStyleLayer(identifier: …
Run Code Online (Sandbox Code Playgroud)

mapbox mapbox-marker mapbox-ios

3
推荐指数
1
解决办法
344
查看次数

标签 统计

mapbox ×1

mapbox-ios ×1

mapbox-marker ×1