Java Code Examples for com.mapbox.mapboxsdk.geometry.LatLngBounds
The following examples show how to use
com.mapbox.mapboxsdk.geometry.LatLngBounds.
These examples are extracted from open source projects.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source Project: graphhopper-navigation-android Author: graphhopper File: DynamicCamera.java License: MIT License | 6 votes |
/** * 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}; return mapboxMap.getCameraForLatLngBounds(cameraBounds, padding); } return mapboxMap.getCameraPosition(); }
Example #2
Source Project: graphhopper-navigation-android Author: graphhopper File: NavigationLauncherActivity.java License: MIT License | 6 votes |
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(); } } } }
Example #3
Source Project: graphhopper-navigation-example Author: graphhopper File: NavigationLauncherActivity.java License: Apache License 2.0 | 6 votes |
private 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 animateCameraBbox(bounds, CAMERA_ANIMATION_DURATION, padding); } catch (InvalidLatLngBoundsException exception) { Toast.makeText(this, R.string.error_valid_route_not_found, Toast.LENGTH_SHORT).show(); } } } }
Example #4
Source Project: mapbox-plugins-android Author: mapbox File: RegionSelectionFragment.java License: BSD 2-Clause "Simplified" License | 6 votes |
OfflineRegionDefinition 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.getStyle().getUrl(), bounds, cameraZoom - 2, cameraZoom + 2, pixelRatio ); }
Example #5
Source Project: deltachat-android Author: deltachat File: DataCollectionTask.java License: GNU General Public License v3.0 | 6 votes |
public DataCollectionTask(DcContext context, int chatId, int[] contactIds, ConcurrentHashMap<Integer, MapSource> contactMapSources, ConcurrentHashMap featureCollections, ConcurrentHashMap<Integer, Feature> lastPositions, LatLngBounds.Builder boundingBuilder, DataCollectionCallback callback) { this.chatId = chatId; this.contactMapSources = contactMapSources; this.featureCollections = featureCollections; this.lastPositions = lastPositions; this.boundingBuilder = boundingBuilder; this.dcContext = context; this.callback = callback; this.contactIds = contactIds; instances.add(this); }
Example #6
Source Project: deltachat-android Author: deltachat File: MapDataManager.java License: GNU General Public License v3.0 | 6 votes |
public MapDataManager(Context context, @NonNull Style mapboxMapStyle, LocationComponent locationComponent, int chatId, MapDataState updateCallback) { Log.d(TAG, "performance test - create map manager"); this.mapboxStyle = mapboxMapStyle; this.context = context; this.dcContext = DcHelper.getContext(context); this.chatId = chatId; boundingBuilder = new LatLngBounds.Builder(); this.callback = updateCallback; this.locationComponent = locationComponent; initInfoWindowLayer(); initLastPositionLayer(); initLocationComponent(); filterProvider.setMessageFilter(true); filterProvider.setLastPositionFilter(System.currentTimeMillis() - DEFAULT_LAST_POSITION_DELTA); applyLastPositionFilter(); updateSources(); dcContext.eventCenter.addObserver(DC_EVENT_LOCATION_CHANGED, this); Log.d(TAG, "performance test - create map manager finished"); }
Example #7
Source Project: deltachat-android Author: deltachat File: MapDataManager.java License: GNU General Public License v3.0 | 6 votes |
@Override public void onDataCollectionFinished() { for (MapSource source : contactMapSources.values()) { initContactBasedLayers(source); refreshSource(source.getContactId()); applyMarkerFilter(source); applyLineFilter(source); } if (boundingBuilder != null && callback != null) { LatLngBounds bound = null; try { bound = boundingBuilder.build(); } catch (InvalidLatLngBoundsException e) { Log.w(TAG, e.getLocalizedMessage()); } callback.onDataInitialized(bound); } }
Example #8
Source Project: graphhopper-navigation-android Author: graphhopper File: NavigationCamera.java License: MIT License | 5 votes |
@NonNull private CameraUpdate buildOverviewCameraUpdate(int[] padding, List<Point> routePoints) { final LatLngBounds routeBounds = convertRoutePointsToLatLngBounds(routePoints); return CameraUpdateFactory.newLatLngBounds( routeBounds, padding[0], padding[1], padding[2], padding[3] ); }
Example #9
Source Project: graphhopper-navigation-android Author: graphhopper File: NavigationCamera.java License: MIT License | 5 votes |
private LatLngBounds convertRoutePointsToLatLngBounds(List<Point> routePoints) { List<LatLng> latLngs = new ArrayList<>(); for (Point routePoint : routePoints) { latLngs.add(new LatLng(routePoint.latitude(), routePoint.longitude())); } return new LatLngBounds.Builder() .includes(latLngs) .build(); }
Example #10
Source Project: graphhopper-navigation-android Author: graphhopper File: ComponentNavigationActivity.java License: MIT License | 5 votes |
private void moveCameraToInclude(Point destination) { LatLng origin = new LatLng(lastLocation); LatLngBounds bounds = new LatLngBounds.Builder() .include(origin) .include(new LatLng(destination.latitude(), destination.longitude())) .build(); Resources resources = getResources(); int routeCameraPadding = (int) resources.getDimension(R.dimen.component_navigation_route_camera_padding); int[] padding = {routeCameraPadding, routeCameraPadding, routeCameraPadding, routeCameraPadding}; CameraPosition cameraPosition = navigationMap.retrieveMap().getCameraForLatLngBounds(bounds, padding); navigationMap.retrieveMap().animateCamera( CameraUpdateFactory.newCameraPosition(cameraPosition), TWO_SECONDS_IN_MILLISECONDS ); }
Example #11
Source Project: mapbox-plugins-android Author: mapbox File: LocalizationPlugin.java License: BSD 2-Clause "Simplified" License | 5 votes |
/** * 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 the {@link MapLocale} object which contains the desired map bounds * @param padding camera padding * @since 0.1.0 */ public void setCameraToLocaleCountry(MapLocale mapLocale, int padding) { 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, padding)); }
Example #12
Source Project: AirMapSDK-Android Author: airmap File: LineContainer.java License: Apache License 2.0 | 5 votes |
@Override public LatLngBounds getLatLngBoundsForZoom() { LatLngBounds.Builder latLngBounds = new LatLngBounds.Builder(); for (List<Point> list : polygon.coordinates()) { for (Point position : list) { latLngBounds.include(new LatLng(position.latitude(), position.longitude())); } } return latLngBounds.build(); }
Example #13
Source Project: AirMapSDK-Android Author: airmap File: PolygonContainer.java License: Apache License 2.0 | 5 votes |
@Override public LatLngBounds getLatLngBoundsForZoom() { LatLngBounds.Builder latLngBounds = new LatLngBounds.Builder(); for (List<Point> list : polygon.coordinates()) { for (Point position : list) { latLngBounds.include(new LatLng(position.latitude(), position.longitude())); } } return latLngBounds.build(); }
Example #14
Source Project: AirMapSDK-Android Author: airmap File: PolygonContainer.java License: Apache License 2.0 | 5 votes |
public LatLng getVisualCenter() { LatLngBounds latLngBounds = new LatLngBounds.Builder().includes(path).build(); LatLng center = latLngBounds.getCenter(); if (TurfJoins.inside(Point.fromLngLat(center.getLongitude(), center.getLatitude()), polygon)) { return center; } return path.get(0); }
Example #15
Source Project: AirMapSDK-Android Author: airmap File: AirMapMapView.java License: Apache License 2.0 | 5 votes |
private void zoomToFeatureIfNecessary(Feature featureClicked) { LatLngBounds cameraBounds = getMap().getProjection().getVisibleRegion().latLngBounds; LatLngBounds.Builder advisoryLatLngsBuilder = new LatLngBounds.Builder(); boolean zoom = false; Geometry geometry = featureClicked.geometry(); List<Point> points = new ArrayList<>(); if (geometry instanceof Polygon) { points.addAll(((Polygon) geometry).outer().coordinates()); } else if (geometry instanceof MultiPolygon) { List<Polygon> polygons = ((MultiPolygon) geometry).polygons(); for (Polygon polygon : polygons) { points.addAll(polygon.outer().coordinates()); } } for (Point position : points) { LatLng latLng = new LatLng(position.latitude(), position.longitude()); advisoryLatLngsBuilder.include(latLng); if (!cameraBounds.contains(latLng)) { Timber.d("Camera position doesn't contain point"); zoom = true; } } if (zoom) { int padding = Utils.dpToPixels(getContext(), 72).intValue(); getMap().moveCamera(CameraUpdateFactory.newLatLngBounds(advisoryLatLngsBuilder.build(), padding)); } }
Example #16
Source Project: AirMapSDK-Android Author: airmap File: MapDataController.java License: Apache License 2.0 | 5 votes |
protected AirMapPolygon getPolygon() { VisibleRegion region = map.getMap().getProjection().getVisibleRegion(); LatLngBounds bounds = region.latLngBounds; List<Coordinate> coordinates = new ArrayList<>(); coordinates.add(new Coordinate(bounds.getLatNorth(), bounds.getLonWest())); coordinates.add(new Coordinate(bounds.getLatNorth(), bounds.getLonEast())); coordinates.add(new Coordinate(bounds.getLatSouth(), bounds.getLonEast())); coordinates.add(new Coordinate(bounds.getLatSouth(), bounds.getLonWest())); coordinates.add(new Coordinate(bounds.getLatNorth(), bounds.getLonWest())); return new AirMapPolygon(coordinates); }
Example #17
Source Project: AirMapSDK-Android Author: airmap File: AirMapConfig.java License: Apache License 2.0 | 5 votes |
public static LatLngBounds getMapBounds(){ try{ return new LatLngBounds.Builder() .include(new LatLng(AirMap.getConfig().getJSONObject("app").getJSONObject("map").getJSONObject("bounds").getJSONObject("northeast").getDouble("latitude"), AirMap.getConfig().getJSONObject("app").getJSONObject("map").getJSONObject("bounds").getJSONObject("northeast").getDouble("longitude"))) .include(new LatLng(AirMap.getConfig().getJSONObject("app").getJSONObject("map").getJSONObject("bounds").getJSONObject("southwest").getDouble("latitude"), AirMap.getConfig().getJSONObject("app").getJSONObject("map").getJSONObject("bounds").getJSONObject("southwest").getDouble("longitude"))) .build(); } catch (JSONException e){ Timber.e(e); return null; } }
Example #18
Source Project: deltachat-android Author: deltachat File: DataCollector.java License: GNU General Public License v3.0 | 5 votes |
public DataCollector(DcContext dcContext, ConcurrentHashMap<Integer, MapSource> contactMapSources, ConcurrentHashMap<String, LinkedList<Feature>> featureCollections, ConcurrentHashMap<Integer, Feature> lastPositions, LatLngBounds.Builder boundingBuilder) { this.dcContext = dcContext; this.contactMapSources = contactMapSources; this.featureCollections = featureCollections; this.lastPositions = lastPositions; this.boundingBuilder = boundingBuilder; }
Example #19
Source Project: dhis2-android-capture-app Author: dhis2 File: ProgramEventDetailActivity.java License: BSD 3-Clause "New" or "Revised" License | 4 votes |
private void initCameraPosition(MapboxMap map,Context context, BoundingBox bbox) { LatLngBounds bounds = LatLngBounds.from(bbox.north(), bbox.east(), bbox.south(), bbox.west()); MapboxExtensionKt.initDefaultCamera(map, context, bounds); }
Example #20
Source Project: dhis2-android-capture-app Author: dhis2 File: SearchTEActivity.java License: BSD 3-Clause "New" or "Revised" License | 4 votes |
private void loadDataForStyle(Style style, HashMap<String, FeatureCollection> teiFeatureCollection, BoundingBox bbox) { binding.mapLayerButton.setVisibility(View.VISIBLE); if (!changingStyle) { MapLayerManager.Companion.init(style, "teis", featureType); MapLayerManager.Companion.instance().setEnrollmentLayerData( presenter.getProgram() != null ? ColorUtils.getColorFrom(presenter.getProgram().style() != null ? presenter.getProgram().style().color() : null, ColorUtils.getPrimaryColor(getContext(), ColorUtils.ColorType.PRIMARY)) : ColorUtils.getPrimaryColor(getContext(), ColorUtils.ColorType.PRIMARY), ColorUtils.getPrimaryColor(this, ColorUtils.ColorType.PRIMARY_DARK), presenter.getProgram() != null ? presenter.getProgram().featureType() != null ? presenter.getProgram().featureType() : FeatureType.NONE : FeatureType.NONE ); MapLayerManager.Companion.instance().showEnrollmentLayer().observe(this, show -> { if (show) presenter.getEnrollmentMapData(); }); } else { MapLayerManager.Companion.instance().updateStyle(style); } map.addOnMapClickListener(this); style.addImage("ICON_ID", MarkerUtils.INSTANCE.getMarker(this, presenter.getSymbolIcon(), presenter.getTEIColor())); style.addImage("ICON_ENROLLMENT_ID", MarkerUtils.INSTANCE.getMarker(this, presenter.getEnrollmentSymbolIcon(), presenter.getEnrollmentColor())); setSource(style, teiFeatureCollection); setLayer(style); LatLngBounds bounds = LatLngBounds.from(bbox.north(), bbox.east(), bbox.south(), bbox.west()); MapboxExtensionKt.initDefaultCamera(map, this, bounds); if (markerViewManager == null) { markerViewManager = new MarkerViewManager(binding.mapView, map); } if (symbolManager == null) { symbolManager = new SymbolManager(binding.mapView, map, style, null, new GeoJsonOptions().withTolerance(0.4f)); symbolManager.setIconAllowOverlap(true); symbolManager.setTextAllowOverlap(true); symbolManager.setIconIgnorePlacement(true); symbolManager.setTextIgnorePlacement(true); symbolManager.setSymbolPlacement("line-center"); symbolManager.create(teiFeatureCollection.get("TEI")); } }
Example #21
Source Project: graphhopper-navigation-android Author: graphhopper File: NavigationLauncherActivity.java License: MIT License | 4 votes |
private void animateCameraBbox(LatLngBounds bounds, int animationTime, int[] padding) { CameraPosition position = mapboxMap.getCameraForLatLngBounds(bounds, padding); mapboxMap.animateCamera(CameraUpdateFactory.newCameraPosition(position), animationTime); }
Example #22
Source Project: graphhopper-navigation-example Author: graphhopper File: NavigationLauncherActivity.java License: Apache License 2.0 | 4 votes |
private void animateCameraBbox(LatLngBounds bounds, int animationTime, int[] padding) { CameraPosition position = mapboxMap.getCameraForLatLngBounds(bounds, padding); mapboxMap.animateCamera(CameraUpdateFactory.newCameraPosition(position), animationTime); }
Example #23
Source Project: graphhopper-navigation-example Author: graphhopper File: NavigationLauncherActivity.java License: Apache License 2.0 | 4 votes |
@Override public void onPostExecuteGeocodingSearch(List<GeocodingLocation> locations) { clearGeocodingResults(); markers = new ArrayList<>(locations.size()); if (locations.isEmpty()) { onError(R.string.error_geocoding_no_location); return; } List<LatLng> bounds = new ArrayList<>(); Location lastKnownLocation = getLastKnownLocation(); if (lastKnownLocation != null) bounds.add(new LatLng(lastKnownLocation.getLatitude(), lastKnownLocation.getLongitude())); for (GeocodingLocation location : locations) { GeocodingPoint point = location.getPoint(); MarkerOptions markerOptions = new MarkerOptions(); LatLng latLng = new LatLng(point.getLat(), point.getLng()); markerOptions.position(latLng); bounds.add(latLng); markerOptions.title(location.getName()); String snippet = ""; if (location.getStreet() != null) { snippet += location.getStreet(); if (location.getHousenumber() != null) snippet += " " + location.getHousenumber(); snippet += "\n"; } if (location.getCity() != null) { if (location.getPostcode() != null) snippet += location.getPostcode() + " "; snippet += location.getCity() + "\n"; } if (location.getCountry() != null) snippet += location.getCountry() + "\n"; if (location.getOsmId() != null) { snippet += "OSM-Id: " + location.getOsmId() + "\n"; if (location.getOsmKey() != null) snippet += "OSM-Key: " + location.getOsmKey() + "\n"; if (location.getOsmType() != null) snippet += "OSM-Type: " + location.getOsmType() + "\n"; } snippet += "\n\n Tap on info window\n to add point to route"; if (!snippet.isEmpty()) markerOptions.snippet(snippet); markerOptions.icon(IconFactory.getInstance(this.getApplicationContext()).fromResource(R.drawable.ic_map_marker)); markers.add(mapboxMap.addMarker(markerOptions)); } // For bounds we need at least 2 entries if (bounds.size() >= 2) { LatLngBounds.Builder boundsBuilder = new LatLngBounds.Builder(); boundsBuilder.includes(bounds); animateCameraBbox(boundsBuilder.build(), CAMERA_ANIMATION_DURATION, padding); } else if (bounds.size() == 1) { // If there is only 1 result (=>current location unknown), we just zoom to that result animateCamera(bounds.get(0)); } hideLoading(); }
Example #24
Source Project: mapbox-plugins-android Author: mapbox File: PlacePickerOptions.java License: BSD 2-Clause "Simplified" License | 4 votes |
@Nullable public abstract LatLngBounds startingBounds();
Example #25
Source Project: AirMapSDK-Android Author: airmap File: CircleContainer.java License: Apache License 2.0 | 4 votes |
@Override public LatLngBounds getLatLngBoundsForZoom() { Analytics.logDebug("center", center.toString()); Analytics.logDebug("points", TextUtils.join(" - ", points)); return new LatLngBounds.Builder().includes(points).build(); }
Example #26
Source Project: mapbox-plugins-android Author: mapbox File: MapLocale.java License: BSD 2-Clause "Simplified" License | 2 votes |
/** * Construct a new MapLocale instance by passing in a LatLngBounds object. * * @param countryBounds non-null {@link LatLngBounds} object which wraps around the country * @since 0.1.0 */ public MapLocale(@NonNull LatLngBounds countryBounds) { this(LOCAL_NAME, countryBounds); }
Example #27
Source Project: mapbox-plugins-android Author: mapbox File: MapLocale.java License: BSD 2-Clause "Simplified" License | 2 votes |
/** * /** * Construct a new MapLocale instance using one of the map languages found in {@link Languages} * and also passing in a LatLngBounds object. * * @param mapLanguage a non-null string which is allowed from {@link Languages} * @param countryBounds {@link LatLngBounds} object which wraps around the country * @since 0.1.0 */ public MapLocale(@NonNull @Languages String mapLanguage, @Nullable LatLngBounds countryBounds) { this.countryBounds = countryBounds; this.mapLanguage = mapLanguage; }
Example #28
Source Project: mapbox-plugins-android Author: mapbox File: MapLocale.java License: BSD 2-Clause "Simplified" License | 2 votes |
/** * Returns a {@link LatLngBounds} which represents the viewport bounds which allow for the entire * viewing of a country within the devices viewport. * * @return a {@link LatLngBounds} which can be used when user locations unknown but locale is * @since 0.1.0 */ @Nullable public LatLngBounds getCountryBounds() { return countryBounds; }
Example #29
Source Project: mapbox-plugins-android Author: mapbox File: RegionSelectionOptions.java License: BSD 2-Clause "Simplified" License | 2 votes |
/** * Define the map's starting camera position by providing a bounding box * * @return the bounding box which is where the {@link OfflineActivity} initial map's camera * position will be placed * @since 0.2.0 */ @Nullable public abstract LatLngBounds startingBounds();
Example #30
Source Project: mapbox-plugins-android Author: mapbox File: RegionSelectionOptions.java License: BSD 2-Clause "Simplified" License | 2 votes |
/** * Define the map's starting camera position by providing a bounding box * * @param bounds the bounding box which is where the {@link OfflineActivity} initial map's camera * position will be placed * @return this builder for chaining options together * @since 0.2.0 */ public abstract Builder startingBounds(@NonNull LatLngBounds bounds);