我尝试使用Mapbox在地图上添加图像。我按照这个链接:https://docs.mapbox.com/ios/maps/examples/image-source/
如果图像大小大于2048 * 2048,图像将显示为黑色,如下所示:
如何使图像没有限制地显示为黑色?
您似乎在使用iOS Maps SDK遇到了这个已知问题:https://github.com/mapbox/mapbox-gl-native/issues/12989。
一种可能的解决方法是将地理参考图像上传到Mapbox帐户,然后在运行时将其作为MGLRasterStyleLayer
添加到地图中。你可以在这里看到这种方法的一个例子:https://docs.mapbox.com/ios/maps/examples/image-source/
Mapbox的iOS Maps SDK允许您在运行时应用栅格切片。您还可以将upload geo-referenced images (a.k.a. GeoTiffs) to your Mapbox account和Mapbox转换为栅格图块集,并为您提供“地图ID”,允许您从Mapbox的API中检索此图块集。地图ID如下所示:riastrad.1ckjd53j
(即“username.unique_id”)。
获得Map ID后,您可以使用此功能在运行时使用其中一个GL SDK将栅格tileset添加到任何地图。
在iOS上,它的样板代码如下所示:
import Mapbox
class RasterSourceExample: UIViewController, MGLMapViewDelegate {
override func viewDidLoad() {
super.viewDidLoad()
let mapView = MGLMapView(frame: view.bounds, styleURL: MGLStyle.darkStyleURL)
mapView.setCenter(CLLocationCoordinate2D(latitude: 43.457, longitude: -75.789), zoomLevel: 4, animated: false)
mapView.autoresizingMask = [.flexibleHeight, .flexibleWidth]
mapView.tintColor = .darkGray
// Set the map view‘s delegate property.
mapView.delegate = self
view.addSubview(mapView)
}
func mapView(_ mapView: MGLMapView, didFinishLoading style: MGLStyle) {
// Create the raster tile source object
let source = MGLRasterTileSource(identifier: "tileset-source", configurationURL: URL(string: "mapbox://riastrad.1ckjd53j"))
style.addSource(source)
// Create a raster layer from the MGLRasterTileSource.
let rasterLayer = MGLRasterStyleLayer(identifier: "raster-layer", source: source)
style.addLayer(rasterLayer)
}
}
⚠️免责声明:我目前在Mapbox⚠️工作