Search in sources :

Example 6 with LatLngBounds

use of com.mapbox.mapboxsdk.geometry.LatLngBounds in project osm-contributor by jawg.

the class OfflineRegionsActivity method initFloatingActionButtons.

private void initFloatingActionButtons() {
    deleteRegionFloatingActionButton.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View view) {
            if (selectedRegionItem != null && selectedRegionItem.getOfflineRegion() != null) {
                int position = adapter.getOfflineRegionItems().indexOf(selectedRegionItem);
                offlineRegionManager.deleteOfflineRegion(selectedRegionItem.getOfflineRegion(), getOfflineRegionDeletedListener());
                adapter.removeOfflineRegion(selectedRegionItem);
                if (adapter.getItemCount() == 0) {
                    switchMode(Mode.NO_REGIONS);
                } else {
                    int newPosition = position == 0 ? 0 : position == adapter.getItemCount() ? adapter.getItemCount() - 1 : position - 1;
                    selectOfflineRegion(newPosition);
                }
                closeEditMenu();
            }
        }
    });
    downloadRegionFloatingActionButton.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View view) {
            if (selectedRegionItem != null && selectedRegionItem.getOfflineRegion() != null) {
                Intent intent = new Intent(OfflineRegionsActivity.this, OfflineRegionDownloadService.class);
                intent.putStringArrayListExtra(OfflineRegionDownloadService.LIST_PARAM + 0, convertDoubleList(selectedRegionItem.getOfflineRegion(), true));
                intent.putExtra(OfflineRegionDownloadService.SIZE_PARAM, 1);
                startService(intent);
                closeEditMenu();
            }
        }
    });
    addRegionFloatingActionButton.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View view) {
            switchMode(Mode.ADD_REGION);
        }
    });
    downloadNewRegionFloatingActionButton.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View view) {
            if (mapboxMap.getCameraPosition().zoom < MIN_DOWNLOAD_ZOOM) {
                Snackbar snackbar = Snackbar.make(activityView, R.string.region_to_large, Snackbar.LENGTH_LONG);
                TextView textView = (TextView) snackbar.getView().findViewById(android.support.design.R.id.snackbar_text);
                textView.setTextColor(ContextCompat.getColor(OfflineRegionsActivity.this, R.color.error_color));
                snackbar.show();
                return;
            }
            final Intent intent = new Intent(OfflineRegionsActivity.this, OfflineRegionDownloadService.class);
            new LovelyTextInputDialog(OfflineRegionsActivity.this).setTopColorRes(R.color.colorPrimary).setTitle(R.string.enter_region_name).setIcon(R.drawable.ic_rename).setInputFilter(R.string.region_name_error, new LovelyTextInputDialog.TextFilter() {

                @Override
                public boolean check(String text) {
                    return text.length() < 20;
                }
            }).setConfirmButton(R.string.ok, new LovelyTextInputDialog.OnTextInputConfirmListener() {

                @Override
                public void onTextInputConfirmed(String text) {
                    intent.putExtra(OfflineRegionDownloadService.REGION_NAME_PARAM, text);
                    LatLngBounds bounds = mapboxMap.getProjection().getVisibleRegion().latLngBounds;
                    intent.putStringArrayListExtra(OfflineRegionDownloadService.LIST_PARAM + 0, convertDoubleList(bounds, false));
                    intent.putExtra(OfflineRegionDownloadService.SIZE_PARAM, 1);
                    startService(intent);
                }
            }).show();
        }
    });
}
Also used : LovelyTextInputDialog(com.yarolegovich.lovelydialog.LovelyTextInputDialog) OfflineRegionDownloadService(io.jawg.osmcontributor.service.OfflineRegionDownloadService) LatLngBounds(com.mapbox.mapboxsdk.geometry.LatLngBounds) Intent(android.content.Intent) TextView(android.widget.TextView) MapView(com.mapbox.mapboxsdk.maps.MapView) BindView(butterknife.BindView) View(android.view.View) RecyclerView(android.support.v7.widget.RecyclerView) TextView(android.widget.TextView) Snackbar(android.support.design.widget.Snackbar)

Example 7 with LatLngBounds

use of com.mapbox.mapboxsdk.geometry.LatLngBounds in project osm-contributor by jawg.

the class MapFragment method downloadAreaForEdition.

// get data from overpass
private void downloadAreaForEdition() {
    if (getZoomLevel() >= zoomVectorial) {
        // progressBar.setVisibility(View.VISIBLE);
        LatLngBounds viewLatLngBounds = getViewLatLngBounds();
        eventBus.post(new SyncDownloadWayEvent(viewLatLngBounds));
    } else {
        Toast.makeText(getActivity(), getString(R.string.zoom_to_edit), Toast.LENGTH_SHORT).show();
    }
}
Also used : LatLngBounds(com.mapbox.mapboxsdk.geometry.LatLngBounds) SyncDownloadWayEvent(io.jawg.osmcontributor.rest.events.SyncDownloadWayEvent)

Example 8 with LatLngBounds

use of com.mapbox.mapboxsdk.geometry.LatLngBounds in project osm-contributor by jawg.

the class OfflineRegionDownloadService method startDownloadIfNeeded.

private void startDownloadIfNeeded(Intent intent, final List<OfflineRegion> presentOfflineRegions) {
    if (intent == null) {
        return;
    }
    final int size = intent.getIntExtra(SIZE_PARAM, -1);
    if (size != -1) {
        int c = 0;
        // There is some regions to download
        for (int i = 0; i < size; i++) {
            ArrayList<String> areasString = intent.getStringArrayListExtra(LIST_PARAM + i);
            LatLngBounds bounds = convertToLatLngBounds(areasString);
            OfflineRegion presentOfflineRegion = containsInOfflineRegion(presentOfflineRegions, bounds);
            if (presentOfflineRegion == null) {
                // The region has never been downloaded
                String regionName = intent.getStringExtra(REGION_NAME_PARAM);
                regionName = regionName == null ? "Region " + (presentOfflineRegions.size() + c) : regionName;
                c++;
                downloadOfflineRegion(bounds, regionName);
            } else {
                // The region is already downloaded, we check if it was completed
                checkIfRegionDownloadIsCompleted(presentOfflineRegion);
            }
        }
    }
}
Also used : OfflineRegion(com.mapbox.mapboxsdk.offline.OfflineRegion) LatLngBounds(com.mapbox.mapboxsdk.geometry.LatLngBounds)

Example 9 with LatLngBounds

use of com.mapbox.mapboxsdk.geometry.LatLngBounds in project mapbox-navigation-android by mapbox.

the class NavigationViewActivity method boundCameraToRoute.

public void boundCameraToRoute() {
    if (route != null) {
        List<Point> routeCoords = LineString.fromPolyline(route.geometry(), Constants.PRECISION_6).coordinates();
        List<LatLng> bboxPoints = new ArrayList<>();
        for (Point point : routeCoords) {
            bboxPoints.add(new LatLng(point.latitude(), point.longitude()));
        }
        if (bboxPoints.size() > 1) {
            try {
                LatLngBounds bounds = new LatLngBounds.Builder().includes(bboxPoints).build();
                // left, top, right, bottom
                int topPadding = launchBtnFrame.getHeight() * 2;
                animateCameraBbox(bounds, CAMERA_ANIMATION_DURATION, new int[] { 50, topPadding, 50, 100 });
            } catch (InvalidLatLngBoundsException exception) {
                Toast.makeText(this, R.string.error_valid_route_not_found, Toast.LENGTH_SHORT).show();
            }
        }
    }
}
Also used : InvalidLatLngBoundsException(com.mapbox.mapboxsdk.exceptions.InvalidLatLngBoundsException) ArrayList(java.util.ArrayList) LatLngBounds(com.mapbox.mapboxsdk.geometry.LatLngBounds) Point(com.mapbox.geojson.Point) LatLng(com.mapbox.mapboxsdk.geometry.LatLng) Point(com.mapbox.geojson.Point)

Example 10 with LatLngBounds

use of com.mapbox.mapboxsdk.geometry.LatLngBounds in project mapbox-navigation-android by mapbox.

the class DynamicCamera method createCameraPosition.

/**
 * Creates a camera position with the current location and upcoming maneuver location.
 * <p>
 * Using {@link MapboxMap#getCameraForLatLngBounds(LatLngBounds, int[])} with a {@link LatLngBounds}
 * that includes the current location and upcoming maneuver location.
 *
 * @param location      for current location
 * @param routeProgress for upcoming maneuver location
 * @return camera position that encompasses both locations
 */
private CameraPosition createCameraPosition(Location location, RouteProgress routeProgress) {
    LegStep upComingStep = routeProgress.currentLegProgress().upComingStep();
    if (upComingStep != null) {
        Point stepManeuverPoint = upComingStep.maneuver().location();
        List<LatLng> latLngs = new ArrayList<>();
        LatLng currentLatLng = new LatLng(location);
        LatLng maneuverLatLng = new LatLng(stepManeuverPoint.latitude(), stepManeuverPoint.longitude());
        latLngs.add(currentLatLng);
        latLngs.add(maneuverLatLng);
        if (latLngs.size() < 1 || currentLatLng.equals(maneuverLatLng)) {
            return mapboxMap.getCameraPosition();
        }
        LatLngBounds cameraBounds = new LatLngBounds.Builder().includes(latLngs).build();
        int[] padding = { 0, 0, 0, 0 };
        CameraPosition positionForLatLngBounds = mapboxMap.getCameraForLatLngBounds(cameraBounds, padding);
        if (positionForLatLngBounds != null) {
            return positionForLatLngBounds;
        }
    }
    return mapboxMap.getCameraPosition();
}
Also used : CameraPosition(com.mapbox.mapboxsdk.camera.CameraPosition) ArrayList(java.util.ArrayList) LatLngBounds(com.mapbox.mapboxsdk.geometry.LatLngBounds) Point(com.mapbox.geojson.Point) LatLng(com.mapbox.mapboxsdk.geometry.LatLng) LegStep(com.mapbox.api.directions.v5.models.LegStep)

Aggregations

LatLngBounds (com.mapbox.mapboxsdk.geometry.LatLngBounds)10 LatLng (com.mapbox.mapboxsdk.geometry.LatLng)5 Point (com.mapbox.geojson.Point)2 ArrayList (java.util.ArrayList)2 Intent (android.content.Intent)1 PointF (android.graphics.PointF)1 RectF (android.graphics.RectF)1 Snackbar (android.support.design.widget.Snackbar)1 RecyclerView (android.support.v7.widget.RecyclerView)1 View (android.view.View)1 TextView (android.widget.TextView)1 BindView (butterknife.BindView)1 LegStep (com.mapbox.api.directions.v5.models.LegStep)1 CameraPosition (com.mapbox.mapboxsdk.camera.CameraPosition)1 InvalidLatLngBoundsException (com.mapbox.mapboxsdk.exceptions.InvalidLatLngBoundsException)1 MapView (com.mapbox.mapboxsdk.maps.MapView)1 OfflineRegion (com.mapbox.mapboxsdk.offline.OfflineRegion)1 OfflineTilePyramidRegionDefinition (com.mapbox.mapboxsdk.offline.OfflineTilePyramidRegionDefinition)1 LovelyTextInputDialog (com.yarolegovich.lovelydialog.LovelyTextInputDialog)1 PleaseLoadPoiTypes (io.jawg.osmcontributor.model.events.PleaseLoadPoiTypes)1