ios - Mapbox WMS 对 iOS 的支持
问题描述
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)
错误:[ERROR] {}[Style]:无法加载源 test1:
解决方案
虽然在 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 工作⚠️
推荐阅读
- python - 将 scipy 与复杂值函数结合使用时,如何避免多次调用慢速函数?
- sockets - 谁能告诉我如何在 Wireshark 上激活环回?
- flutter - 我应该在一页/屏幕中使用多个块在 Flutter 中加载不同的状态吗?
- python - pip 安装了 biopython,但它不会编译 Bio 模块
- python - 如何在 Python 中为 Linux 创建 URL 快捷方式?
- php - 使用本地 php.ini 文件运行 Cron 作业 - Laravel 5.8
- php - 通过变量分隔符拆分和捕获文本
- excel - 通过名称管理器动态更改文件名
- wordpress - 如何在 Wordpress search.php 文件中添加 Widget 区域?
- reactjs - Twilio Flex UI - WebRTC/ORTC 部署错误