Language
OneAtlas Basemap Guide
  1. Integration with Mobile
    1. WhirlyGlobe
    2. Tangram

Integration With Mobile

WhirlyGlobe

WhirlyGlobe is a Java SDK for Android used to display imagery layers, Vector maps, 3D markers and many more.


With a simple class that extends RemoteTileInfo to provide an API key, you can use the OneAtlas API with WhirlyGlobe. If you never used the WhirlyGlobe SDK, we suggest that you follow the tutorial available here to start. Then you only need to use the class below to add you OneAtlas layers.

class OneAtlasTileInfo extends RemoteTileInfo {
    private String apiKey;
    public OneAtlasTileInfo(String url, String apiKey, int minZoom, int maxZoom) {
        super(url, "png", minZoom, maxZoom);
        if(!apiKey.startsWith("Bearer ")) {
            apiKey = "Bearer " + apiKey;
        }
        this.apiKey = apiKey;
    }
    public OneAtlasTileInfo(String url, String apiKey, String ext, int minZoom, int maxZoom) {
        super(url, ext, minZoom, maxZoom);
        if(!apiKey.startsWith("Bearer ")) {
            apiKey = "Bearer " + apiKey;
        }
        this.apiKey = apiKey;
    }

    @Override
    public Request buildRequest(URL url) {
        return new Request.Builder().url(url).addHeader("Authorization", this.apiKey).build();
    }
}

Screenshot

mobile.png

Tangram

Tangram is a flexible mapping engine for Android used to display imagery layers, Vector maps, 3D markers and many more.


If you never used Tangram, we suggest that you follow the official walkthrough then you can add your OneAtlas source layers in your scene.yaml file as following:

sources:
    oneatlas:
        type: Raster
        url: https://view.geoapi-airbusds.com/api/v1/map/imagery.wmts?tilematrixset=3857&Service=WMTS&Request=GetTile&Version=1.0.0&Format=image/png&TileMatrix={z}&TileCol={x}&TileRow={y}

You’ll also need to redefine the default HttpHandler to add the required Authorization header. As you can see in the following example, we check that the URL is the API’s one to avoid sending your token to other providers:

class OneAtlasHttpHandler extends HttpHandler {

    public OneAtlasHttpHandler() {
        super();
    }

    public OneAtlasHttpHandler(File directory, long maxSize, CachePolicy policy) {
        super(directory, maxSize, policy);
    }

    @Override
    public boolean onRequest(String url, Callback cb) {
        HttpUrl httpUrl = HttpUrl.parse(url);
        Request.Builder builder = new Request.Builder().url(httpUrl);
        CacheControl cacheControl = cachePolicy.apply(httpUrl);
        if (cacheControl != null) {
            builder.cacheControl(cacheControl);
        }
        if(httpUrl.host().equals("view.geoapi-airbusds.com")) {
            String tok = readTokenFile();
            builder.addHeader("Authorization", tok);
        }
        Request request = builder.build();
        okClient.newCall(request).enqueue(cb);
        return true;
    }

    public String readTokenFile() {
        String tContents = "";

        try {
            InputStream stream = getAssets().open("oneatlas.tok");
            int size = stream.available();
            byte[] buffer = new byte[size];
            stream.read(buffer);
            stream.close();
            tContents = new String(buffer);
        } catch (IOException e) {
            runOnUiThread(new Runnable() {
                @Override
                public void run() {
                    Toast.makeText(MapActivity.this, "Cannot read token file ! ", Toast.LENGTH_LONG).show();
                }
            });
        }
        if(!tContents.startsWith("Bearer ")) {
            tContents = "Bearer " + tContents;
        }
        return tContents;
    }
}

Finally, you need to set the new HttpHandler on your map controller from your MapActivity:

mapController.setHttpHandler(new OneAtlasHttpHandler());

Screenshot

tangram_mob.png