Mapbox WMS支持iOS

问题描述 投票:0回答:1

mapbox是否支持WMS服务?我在iOS文档中没有找到任何内容,但在Android部分我发现了这个:https://docs.mapbox.com/android/maps/examples/add-a-wms-source/。我已经把这个代码应用到iOS平台,但我的解决方案不起作用。我遇到的第一个问题是URL的构造的问题。

let url = URL(string: wms1)! 

Url构造函数在传递的字符串中遇到{bbox-epsg-3857}的问题。

我通过允许非法字符省略了问题:

let urlString = wms1.addingPercentEncoding(withAllowedCharacters: .illegalCharacters)
let url = URL(string: urlString!)! 

然后我尝试添加wms源来映射,但这提供了一些错误

let source = MGLShapeSource(identifier: "test1", url: url, options: nil)
style.addSource(source)

let layer = MGLRasterStyleLayer(identifier: "test1", source: source)
style.addLayer(layer) 

错误:[错误] {} [样式]:无法加载源test1:

ios swift mapbox wms mapbox-ios
1个回答
1
投票

虽然没有与使用Mapbox网站上的iOS Maps SDK将WMS作为RasterTileSource相关的具体示例,但肯定可以这样做。唯一的要求是使用正确的Tile URL模板初始化源对象。除了url模板,实现与此示例相同:https://docs.mapbox.com/ios/maps/examples/source-custom-raster/

唯一的区别是你需要修改这一行:

let source = MGLRasterTileSource(identifier: "stamen-watercolor", tileURLTemplates: ["https://stamen-tiles.a.ssl.fastly.net/watercolor/{z}/{x}/{y}.jpg"], options: [ .tileSize: 256 ])

要反映您的WMS源的Tile URL模板,即:

let source = MGLRasterTileSource(identifier: "stamen-watercolor", tileURLTemplates: ["https://geodata.state.nj.us/imagerywms/Natural2015?bbox={bbox-epsg-3857}&format=image/png&service=WMS&version=1.1.1&request=GetMap&srs=EPSG:3857&width=256&height=256&layers=Natural2015"], options: [ .tileSize: 256 ])

⚠️免责声明:我目前在Mapbox⚠️工作

© www.soinside.com 2019 - 2024. All rights reserved.