Search in sources :

Example 1 with OfflineTilePyramidRegionDefinition

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);
}
Also used : RectF(android.graphics.RectF) OfflineTilePyramidRegionDefinition(com.mapbox.mapboxsdk.offline.OfflineTilePyramidRegionDefinition) PointF(android.graphics.PointF) LatLngBounds(com.mapbox.mapboxsdk.geometry.LatLngBounds) LatLng(com.mapbox.mapboxsdk.geometry.LatLng)

Example 2 with OfflineTilePyramidRegionDefinition

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);
}
Also used : OfflineTilePyramidRegionDefinition(com.mapbox.mapboxsdk.offline.OfflineTilePyramidRegionDefinition)

Example 3 with OfflineTilePyramidRegionDefinition

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);
        }
    });
}
Also used : OfflineRegion(com.mapbox.mapboxsdk.offline.OfflineRegion) OfflineTilePyramidRegionDefinition(com.mapbox.mapboxsdk.offline.OfflineTilePyramidRegionDefinition) OfflineManager(com.mapbox.mapboxsdk.offline.OfflineManager)

Example 4 with OfflineTilePyramidRegionDefinition

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());
}
Also used : NotificationOptions(com.mapbox.mapboxsdk.plugins.offline.model.NotificationOptions) OfflineTilePyramidRegionDefinition(com.mapbox.mapboxsdk.offline.OfflineTilePyramidRegionDefinition) LatLng(com.mapbox.mapboxsdk.geometry.LatLng) OnClick(butterknife.OnClick)

Example 5 with OfflineTilePyramidRegionDefinition

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());
        }
    });
}
Also used : OfflineRegion(com.mapbox.mapboxsdk.offline.OfflineRegion) OfflineTilePyramidRegionDefinition(com.mapbox.mapboxsdk.offline.OfflineTilePyramidRegionDefinition) OfflineRegionCreatedEvent(io.jawg.osmcontributor.offline.events.OfflineRegionCreatedEvent) OfflineRegionManager(io.jawg.osmcontributor.offline.OfflineRegionManager)

Aggregations

OfflineTilePyramidRegionDefinition (com.mapbox.mapboxsdk.offline.OfflineTilePyramidRegionDefinition)6 LatLng (com.mapbox.mapboxsdk.geometry.LatLng)2 OfflineRegion (com.mapbox.mapboxsdk.offline.OfflineRegion)2 PointF (android.graphics.PointF)1 RectF (android.graphics.RectF)1 OnClick (butterknife.OnClick)1 LatLngBounds (com.mapbox.mapboxsdk.geometry.LatLngBounds)1 OfflineManager (com.mapbox.mapboxsdk.offline.OfflineManager)1 NotificationOptions (com.mapbox.mapboxsdk.plugins.offline.model.NotificationOptions)1 OfflineRegionManager (io.jawg.osmcontributor.offline.OfflineRegionManager)1 OfflineRegionCreatedEvent (io.jawg.osmcontributor.offline.events.OfflineRegionCreatedEvent)1