use of com.mapbox.mapboxsdk.offline.OfflineTilePyramidRegionDefinition in project mapbox-plugins-android by mapbox.
the class RegionSelectionFragment method createRegion.
OfflineTilePyramidRegionDefinition createRegion() {
if (mapboxMap == null) {
throw new NullPointerException("MapboxMap is null and can't be used to create Offline region" + "definition.");
}
RectF rectF = getSelectionRegion();
LatLng northEast = mapboxMap.getProjection().fromScreenLocation(new PointF(rectF.right, rectF.top));
LatLng southWest = mapboxMap.getProjection().fromScreenLocation(new PointF(rectF.left, rectF.bottom));
LatLngBounds bounds = new LatLngBounds.Builder().include(northEast).include(southWest).build();
double cameraZoom = mapboxMap.getCameraPosition().zoom;
float pixelRatio = getActivity().getResources().getDisplayMetrics().density;
return new OfflineTilePyramidRegionDefinition(mapboxMap.getStyleUrl(), bounds, cameraZoom - 2, cameraZoom + 2, pixelRatio);
}
use of com.mapbox.mapboxsdk.offline.OfflineTilePyramidRegionDefinition in project osm-contributor by jawg.
the class OfflineRegionItem method equals.
@Override
public boolean equals(Object o) {
if (this == o) {
return true;
}
if (!(o instanceof OfflineRegionItem)) {
return false;
}
OfflineRegionItem that = (OfflineRegionItem) o;
if (that.offlineRegion == null || offlineRegion == null) {
return false;
}
OfflineTilePyramidRegionDefinition thatDefinition = (OfflineTilePyramidRegionDefinition) that.offlineRegion.getDefinition();
OfflineTilePyramidRegionDefinition definition = (OfflineTilePyramidRegionDefinition) offlineRegion.getDefinition();
return thatDefinition.getBounds().equals(definition.getBounds()) || (offlineRegion != null ? offlineRegion.equals(that.offlineRegion) : that.offlineRegion == null);
}
use of com.mapbox.mapboxsdk.offline.OfflineTilePyramidRegionDefinition in project mapbox-plugins-android by mapbox.
the class OfflineDownloadService method createDownload.
private void createDownload(final OfflineDownloadOptions offlineDownload) {
final OfflineTilePyramidRegionDefinition definition = offlineDownload.definition();
final byte[] metadata = offlineDownload.metadata();
OfflineManager.getInstance(getApplicationContext()).createOfflineRegion(definition, metadata, new OfflineManager.CreateOfflineRegionCallback() {
@Override
public void onCreate(OfflineRegion offlineRegion) {
offlineDownload.setRegionId(offlineRegion.getID());
OfflineDownloadStateReceiver.dispatchStartBroadcast(getApplicationContext(), offlineDownload);
regionLongSparseArray.put(offlineDownload.getServiceId(), offlineRegion);
launchDownload(offlineDownload, offlineRegion);
showNotification(offlineDownload);
}
@Override
public void onError(String error) {
OfflineDownloadStateReceiver.dispatchErrorBroadcast(getApplicationContext(), offlineDownload, error);
}
});
}
use of com.mapbox.mapboxsdk.offline.OfflineTilePyramidRegionDefinition in project mapbox-plugins-android by mapbox.
the class OfflineDownloadActivity method onDownloadRegion.
@OnClick(R.id.fab)
public void onDownloadRegion() {
// get data from UI
String regionName = regionNameView.getText().toString();
double latitudeNorth = Double.parseDouble(latNorthView.getText().toString());
double longitudeEast = Double.parseDouble(lonEastView.getText().toString());
double latitudeSouth = Double.parseDouble(latSouthView.getText().toString());
double longitudeWest = Double.parseDouble(lonWestView.getText().toString());
String styleUrl = (String) styleUrlView.getSelectedItem();
float maxZoom = maxZoomView.getProgress();
float minZoom = minZoomView.getProgress();
if (!validCoordinates(latitudeNorth, longitudeEast, latitudeSouth, longitudeWest)) {
Toast.makeText(this, "coordinates need to be in valid range", Toast.LENGTH_LONG).show();
return;
}
// create offline definition from data
OfflineTilePyramidRegionDefinition definition = new OfflineTilePyramidRegionDefinition(styleUrl, new LatLngBounds.Builder().include(new LatLng(latitudeNorth, longitudeEast)).include(new LatLng(latitudeSouth, longitudeWest)).build(), minZoom, maxZoom, getResources().getDisplayMetrics().density);
// customize notification appearance
NotificationOptions notificationOptions = NotificationOptions.builder(this).smallIconRes(R.drawable.mapbox_logo_icon).returnActivity(OfflineRegionDetailActivity.class.getName()).build();
// start offline download
OfflinePlugin.getInstance().startDownload(this, OfflineDownloadOptions.builder().definition(definition).metadata(OfflineUtils.convertRegionName(regionName)).notificationOptions(notificationOptions).build());
}
use of com.mapbox.mapboxsdk.offline.OfflineTilePyramidRegionDefinition in project osm-contributor by jawg.
the class OfflineRegionDownloadService method downloadOfflineRegion.
public void downloadOfflineRegion(LatLngBounds latLngBounds, final String regionName) {
final OfflineTilePyramidRegionDefinition definition = new OfflineTilePyramidRegionDefinition(BuildConfig.MAP_STYLE_URL, latLngBounds, MIN_ZOOM, MAX_ZOOM, this.getResources().getDisplayMetrics().density);
// Build the notification
buildNotification(regionName);
offlineRegionManager.createOfflineRegion(definition, regionName, new OfflineRegionManager.OnOfflineRegionCreatedListener() {
@Override
public void onOfflineRegionCreated(OfflineRegion offlineRegion, String regionName) {
// Monitor the download progress using setObserver
offlineRegion.setObserver(getOfflineRegionObserver(regionName));
startDownloadOfflineRegion(offlineRegion);
eventBus.post(new OfflineRegionCreatedEvent());
}
});
}
Aggregations