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();
}
});
}
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();
}
}
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);
}
}
}
}
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();
}
}
}
}
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();
}
Aggregations