Support custom / HTTPS tile data source with Nutiteq SDK

110 views Asked by At

I tried Nutiteq SDK with custom tile URL which uses HTTPS, but it did not work. Does Nutiteq Maps SDK support HTTPS?

1

There are 1 answers

0
JaakL On

Nutiteq Maps SDK does not support internally HTTPS in cross-platform API level. To be exact, only Windows Phone API version supports it, but not other platforms (Android, iOS, Xamarin). For the other platforms you would need to write custom DataSource. It is quite simple, if you base it to existing HTTPTileDataSource. You only need to override public TileData loadTile(MapTile tile) method with custom code which does HTTP in Java or ObjC API level, and these supports HTTPS automatically.

Here is minimal class for Java. In .NET/Xamarin and iOS it would be very similar:

public class MyHttpTileDataSource extends HTTPTileDataSource {

public MyHttpTileDataSource(int minZoom, int maxZoom, String baseURL) {
    super(minZoom, maxZoom, baseURL);
}

public TileData loadTile(MapTile tile) {

    String urlString = super.buildTileUrl(tile);

    Log.debug("requesting tile: "+urlString);

    Bitmap bmp = null;
    try {
        URL url = new URL(urlString);
        bmp = BitmapFactory.decodeStream(url.openConnection().getInputStream());
    } catch (IOException e) {
        e.printStackTrace();
        return null;
    }

    return new TileData(BitmapUtils.createBitmapFromAndroidBitmap(bmp).compressToInternal());
  }

}

With same approach you can also have other custom logic, e.g. add HTTP headers for authentication, control custom caching etc.