MapBox Android SDK的WMS授权标头

时间:2019-01-30 13:38:22

标签: java android mapbox-android

在mapBox Android SDK上调用WMS服务时如何添加授权标头。

我们有一家名为空客的卫星图像服务提供商。我们想使用mapBox Android SDK调用其WMS Restful API。问题是,空中客车要求我们在拨打安全季节电话时传递带有密钥(令牌)的授权标头。在mapBox SDK上,您只能将url源作为字符串而不是标头传递。

请不要我们调用其他不需要Authorization标头的WMS服务

代码

String airBus_source = "https://view.geoapi-airbusds.com/api/v1/map/imagery.wms?version=1.1.1&request=GetMap&service=WMS&WIDTH=256&HEIGHT=256&FORMAT=image/png&EPSG:3857&bbox={bbox-epsg-3857}";
            setHeader.builder.addHeader("Authorization",Airbus_key);
            setHeader.builder.url(airBus_source);
            setHeader.builder.tag(airBus_source.toLowerCase(MapboxConstants.MAPBOX_LOCALE));

            RasterSource airbus_image = new RasterSource("web-map-source",new TileSet("tileset",airBus_source),256);
            mapboxMap.addSource(airbus_image);

            RasterLayer webMapLayer = new RasterLayer("web-map-layer", "web-map-source");
            mapboxMap.addLayerBelow(webMapLayer, "aeroway-taxiway"); 

1 个答案:

答案 0 :(得分:0)

我认为我找到了一种替代OkHttpClient的方法。 Mapbox库允许使用com.mapbox.mapboxsdk.module.http.HttpRequestUtil

OkHttpClient okHttpClient = new OkHttpClient.Builder()
    .addNetworkInterceptor(chain -> {
        // check the request path if you need
        Request newRequest = chain.request()
            .newBuilder()
            .addHeader("Authorization", Airbus_key)
            .build();
        return chain.proceed(newRequest);
    })
    .build();
HttpRequestUtil.setOkHttpClient(okHttpClient);