我正在尝试在Mapbox的添加图层中动态更改图像。我的代码的适当部分:
func mapView(_ mapView: MGLMapView, didFinishLoading style: MGLStyle) {
let weatherSource = MGLImageSource(identifier: "weatherSource", coordinateQuad: radarCoordinates, image: radarImages[radarImages.count-1])
let weatherLayer = MGLRasterStyleLayer(identifier: "weatherLayer", source: weatherSource)
radarTimer = Timer.scheduledTimer(timeInterval: 1, target: self, selector: #selector(changeRadar), userInfo: nil, repeats: true)
style.addSource(weatherSource)
style.addLayer(weatherLayer)
self.weatherLayer = weatherLayer
}
以及更新功能:
@objc func changeRadar() {
snap = (snap != radarImages.count-1 ? snap+1 : 0)
weatherSource.image = (radarImages[snap] == nil ? radarImages[snap-1] : radarImages[snap])
}
当我启动该应用程序时,什么都没有发生,但是它应该更改radarImages数组(包含雷达图片)中包含的图像。
有什么主意,我可以做些什么更好的办法?