use of org.odk.collect.android.geo.MbtilesFile.MbtilesException in project collect by opendatakit.
the class MapboxMapFragment method addMbtiles.
@SuppressWarnings("TimberExceptionLogging")
private void addMbtiles(String id, File file) {
MbtilesFile mbtiles;
try {
mbtiles = new MbtilesFile(file);
} catch (MbtilesException e) {
Timber.w(e.getMessage());
return;
}
TileSet tileSet = createTileSet(mbtiles, tileServer.getUrlTemplate(id));
tileServer.addSource(id, mbtiles);
if (mbtiles.getLayerType() == LayerType.VECTOR) {
addOverlaySource(new VectorSource(id, tileSet));
List<MbtilesFile.VectorLayer> layers = mbtiles.getVectorLayers();
for (MbtilesFile.VectorLayer layer : layers) {
// Pick a colour that's a function of the filename and layer name.
// The colour will appear essentially random; the only purpose here
// is to try to assign different colours to different layers, such
// that each individual layer appears in its own consistent colour.
int hue = (((id + "." + layer.name).hashCode()) & 0x7fffffff) % 360;
addOverlayLayer(new LineLayer(id + "/" + layer.name, id).withProperties(lineColor(Color.HSVToColor(new float[] { hue, 0.7f, 1 })), lineWidth(1f), lineOpacity(0.7f)).withSourceLayer(layer.name));
}
}
if (mbtiles.getLayerType() == LayerType.RASTER) {
addOverlaySource(new RasterSource(id, tileSet));
addOverlayLayer(new RasterLayer(id + ".raster", id));
}
Timber.i("Added %s as a %s layer at /%s", file, mbtiles.getLayerType(), id);
}
use of org.odk.collect.android.geo.MbtilesFile.MbtilesException in project collect by opendatakit.
the class MapboxMapFragment method createTileSet.
@SuppressWarnings("TimberExceptionLogging")
private TileSet createTileSet(MbtilesFile mbtiles, String urlTemplate) {
TileSet tileSet = new TileSet("2.2.0", urlTemplate);
// Configure the TileSet using the metadata in the .mbtiles file.
try {
tileSet.setName(mbtiles.getMetadata("name"));
try {
tileSet.setMinZoom(Integer.parseInt(mbtiles.getMetadata("minzoom")));
tileSet.setMaxZoom(Integer.parseInt(mbtiles.getMetadata("maxzoom")));
} catch (NumberFormatException e) {
/* ignore */
}
String[] parts = mbtiles.getMetadata("center").split(",");
if (parts.length == 3) {
// latitude, longitude, zoom
try {
tileSet.setCenter(Float.parseFloat(parts[0]), Float.parseFloat(parts[1]), (float) Integer.parseInt(parts[2]));
} catch (NumberFormatException e) {
/* ignore */
}
}
parts = mbtiles.getMetadata("bounds").split(",");
if (parts.length == 4) {
// left, bottom, right, top
try {
tileSet.setBounds(Float.parseFloat(parts[0]), Float.parseFloat(parts[1]), Float.parseFloat(parts[2]), Float.parseFloat(parts[3]));
} catch (NumberFormatException e) {
/* ignore */
}
}
} catch (MbtilesException e) {
Timber.w(e.getMessage());
}
return tileSet;
}
Aggregations