要获得我的磁贴,我会这样做:
style(styleUri = Style.MAPBOX_STREETS) {
+vectorSource(id = "parcel-source") {
url("http://example.com/{z}/{x}/{y}.png")
}但是我需要向一个瓦片提供者提供一个令牌,它带有一个像Authorization: bearer [token]这样的HTTP头。
documentation显示了一个超文本传输协议拦截器的框架,但是对于如何实现要实现的接口的5个功能几乎没有给出任何线索。我在API reference中也找不到涉及到的接口。记录了类似问题的open issue。
此外,solution working for v9.5似乎在v10中不再可用(缺少HttpRequestUtil)。
发布于 2021-10-28 12:36:46
对于正在为此而苦苦挣扎的人,我的实现方式如下:
@MapboxModule(type = CommonHttpClient)
class CustomMapboxOkHttpService : HttpServiceInterface {
val map = MapboxOkHttpService()
override fun setInterceptor(interceptor: HttpServiceInterceptorInterface?) {
map.setInterceptor(interceptor)
}
override fun setMaxRequestsPerHost(max: Byte) {
map.setMaxRequestsPerHost(max)
}
override fun request(request: HttpRequest, callback: HttpResponseCallback): Long {
token?.let {
request.headers["Authorization"] = "Bearer $it"
}
return map.request(request, callback)
}
override fun cancelRequest(id: Long, callback: ResultCallback) {
map.cancelRequest(id, callback)
}
override fun supportsKeepCompression(): Boolean {
return map.supportsKeepCompression()
}
override fun download(options: DownloadOptions, callback: DownloadStatusCallback): Long {
return map.download(options, callback)
}
companion object {
var token: String? = null
}
}不要按照documentation here中的说明排除通用库
https://stackoverflow.com/questions/67616505
复制相似问题