我在下面标记的地方遇到运行时错误?如何从子类调用 MKTileOverlay “url”函数?得到 EXC_BAD_INSTRUCTION?
基本上想在某些地方显示自定义图块,但当不可用时退回到标准 Apple 地图图块。
class GCMapOverlay : MKTileOverlay {
override func url(forTilePath path: MKTileOverlayPath) -> URL {
// Get local custom map tile if available
let optionalUrl = Bundle.main.url(
forResource: "\(path.y)",
withExtension: "png",
subdirectory: "tiles/\(path.z)/\(path.x)",
localization: nil)
NSLog("tiles/\(path.z)/\(path.x)/\(path.y)")
guard let url = optionalUrl else {
// Local tile not available - want to drop back to an apple maps tile (as if MKTileOverlay wasn't subclassed)
return super.url(forTilePath: path) // <== RUNTIME ERROR: NetworkLoad (10): EXC_BAD_INSTRUCTION
}
// Local tile available so return
return url
}
}
在我的控制器中
func setupTileRenderer() {
let overlay = GCMapOverlay()
overlay.canReplaceMapContent = true
mapView.addOverlay(overlay, level: .aboveLabels)
tileRenderer = MKTileOverlayRenderer(tileOverlay: overlay)
}