iOS MapBox v10(四)HttpServiceInterface/HttpServiceInterceptorInterface拦截修改网络请求
环境
- Mapbox v10.5.0
- Xcode 14.3.1
HttpServiceInterface自定义网络请求
设置网络请求类
1 | MapboxCommon.HttpServiceFactory.setUserDefinedForCustom(HttpServiceInterface) |
实现网络请求类
MapboxCommon.HttpServiceFactory.getInstance()返回的是自定义请求类,所以不能直接返回网络请求
1 | class CustomHttpServiceInterface:HttpServiceInterface{ |
HttpServiceInterceptorInterface拦截修改网络请求
设置网络请求代理
1 | MapboxCommon.HttpServiceFactory.getInstance().setInterceptorForInterceptor(HttpServiceInterceptorInterface) |
实现网络请求代理
1 | class HttpServiceHack:HttpServiceInterceptorInterface{ |
N个瓦片涂层合并
需求
N个本地地图包和M个在线地图包链接,根据时间叠加,显示为一个layer图层
实现
- 自定义
local:///localtiles?x={x}&y={y}&z={y}链接标识 (这里不能使用file:///,因为不能拦截) - 修改设置
HttpServiceInterceptorInterface,在onRequest中修改HttpRequest到本地文件链接,或者在前请求图片保存为本地后,再设置本地文件链接 - 因为本地图片请求,返回码是
0,所以需要在onResponse中将,将返回码设置为200
其他实现方式
使用第三方库GCDWebServer,作为中间人,进行请求拦截,自定义返回
本博客所有文章除特别声明外,均采用 CC BY-NC-SA 4.0 许可协议。转载请注明来源 Maktub_Blog!