Search in sources :

Example 1 with LatLngBounds

use of com.mapbox.mapboxsdk.geometry.LatLngBounds 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 LatLngBounds

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

the class LocalizationPlugin method setCameraToLocaleCountry.

/**
 * You can pass in a {@link MapLocale} directly into this method which uses the country bounds
 * defined in it to represent the language found on the map.
 *
 * @param mapLocale he {@link MapLocale} object which contains the desired map bounds
 * @throws NullPointerException thrown when it was expecting a {@link LatLngBounds} but instead
 *                              it was null
 * @since 0.1.0
 */
public void setCameraToLocaleCountry(MapLocale mapLocale) {
    LatLngBounds bounds = mapLocale.getCountryBounds();
    if (bounds == null) {
        throw new NullPointerException("Expected a LatLngBounds object but received null instead. Mak" + "e sure your MapLocale instance also has a country bounding box defined.");
    }
    mapboxMap.moveCamera(CameraUpdateFactory.newLatLngBounds(bounds, 50));
}
Also used : LatLngBounds(com.mapbox.mapboxsdk.geometry.LatLngBounds)

Example 3 with LatLngBounds

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

the class MapFragmentPresenter method loadPoi.

private void loadPoi(boolean refreshData, boolean forceRefresh) {
    if (poiTypes == null) {
        Timber.v("PleaseLoadPoiTypes");
        eventBus.post(new PleaseLoadPoiTypes());
    }
    LatLngBounds viewLatLngBounds = mapFragment.getViewLatLngBounds();
    if (viewLatLngBounds != null) {
        if (mapFragment.getZoomLevel() > BuildConfig.ZOOM_MARKER_MIN) {
            if (shouldReload(viewLatLngBounds) || refreshData || forceRefresh) {
                previousZoom = mapFragment.getZoomLevel();
                triggerReloadPoiLatLngBounds = LatLngBoundsUtils.enlarge(viewLatLngBounds, 1.2);
                LatLngBounds latLngToLoad = LatLngBoundsUtils.enlarge(viewLatLngBounds, 1.2);
                getPoisAndNotes.unsubscribe();
                Timber.e("Unsubscribe current loading");
                if (getPoisSubscriber != null) {
                    getPoisSubscriber.unsubscribe();
                }
                getPoisSubscriber = new GetPoisSubscriber();
                getPoisAndNotes.init(Box.convertFromLatLngBounds(latLngToLoad), refreshData).execute(getPoisSubscriber);
                mapFragment.displayZoomTooLargeError(false);
            }
        } else {
            forceRefreshPoi = true;
            cleanAllZoomTooLarge();
        }
    }
}
Also used : LatLngBounds(com.mapbox.mapboxsdk.geometry.LatLngBounds) PleaseLoadPoiTypes(io.jawg.osmcontributor.model.events.PleaseLoadPoiTypes)

Example 4 with LatLngBounds

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

the class LatLngBoundsUtils method enlarge.

public static LatLngBounds enlarge(LatLngBounds viewLatLngBounds, double factor) {
    double n = viewLatLngBounds.getLatNorth();
    double e = viewLatLngBounds.getLonEast();
    double s = viewLatLngBounds.getLatSouth();
    double w = viewLatLngBounds.getLonWest();
    double f = (factor - 1) / 2;
    return new LatLngBounds.Builder().include(new LatLng(n + f * (n - s), e + f * (e - w))).include(new LatLng(s - f * (n - s), w - f * (e - w))).build();
}
Also used : LatLngBounds(com.mapbox.mapboxsdk.geometry.LatLngBounds) LatLng(com.mapbox.mapboxsdk.geometry.LatLng)

Example 5 with LatLngBounds

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

the class Box method enlarge.

/**
 * Enlarge the Box.
 *
 * @param viewLatLngBounds The box to enlarge.
 * @param factor The factor to enlarge the box.
 * @return Box the Box enlarged.
 */
public static LatLngBounds enlarge(LatLngBounds viewLatLngBounds, double factor) {
    double n = viewLatLngBounds.getLatNorth();
    double e = viewLatLngBounds.getLonEast();
    double s = viewLatLngBounds.getLatSouth();
    double w = viewLatLngBounds.getLonWest();
    double f = (factor - 1) / 2;
    return new LatLngBounds.Builder().include(new LatLng(n + f * (n - s), e + f * (e - w))).include(new LatLng(s - f * (n - s), w - f * (e - w))).build();
}
Also used : LatLngBounds(com.mapbox.mapboxsdk.geometry.LatLngBounds) LatLng(com.mapbox.mapboxsdk.geometry.LatLng)

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