use of com.google.android.gms.maps.model.LatLngBounds in project iNaturalistAndroid by inaturalist.
the class ExploreActivity method zoomMapToPlace.
private void zoomMapToPlace(JSONObject place) {
if (place == null)
return;
GeoJsonLayer layer = getGeoJsonLayer(place.optJSONObject("bounding_box_geojson"));
String location = place.optString("location");
CameraUpdate cameraUpdate = null;
if (layer != null) {
LatLngBounds bounds = layer.getBoundingBox();
if (bounds == null) {
LatLngBounds.Builder builder = LatLngBounds.builder();
for (GeoJsonFeature f : layer.getFeatures()) {
if (f.getGeometry() instanceof GeoJsonPolygon) {
GeoJsonPolygon polygon = (GeoJsonPolygon) f.getGeometry();
for (List<LatLng> coordsList : polygon.getCoordinates()) {
for (LatLng coords : coordsList) {
builder.include(coords);
}
}
}
}
bounds = builder.build();
}
mLastMapBounds = bounds;
cameraUpdate = CameraUpdateFactory.newLatLngBounds(bounds, 0);
} else if (location != null) {
String[] parts = location.split(",");
LatLng latlng = new LatLng(Double.valueOf(parts[0]), Double.valueOf(parts[1]));
cameraUpdate = CameraUpdateFactory.newLatLngZoom(latlng, MY_LOCATION_ZOOM_LEVEL);
}
if (cameraUpdate != null) {
mMapMoved = false;
mObservationsMap.moveCamera(cameraUpdate);
}
}
use of com.google.android.gms.maps.model.LatLngBounds in project iNaturalistAndroid by inaturalist.
the class ExploreActivity method refreshObservations.
private void refreshObservations() {
if (mLoadingObservationsGrid == null) {
// View hasn't loaded yet
return;
}
refreshFilterBar(mObservationsGridFilterBar);
refreshFilterBar(mObservationsMapFilterBar);
mObservationsGrid.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> arg0, View view, int position, long arg3) {
JSONObject item = (JSONObject) view.getTag();
Intent intent = new Intent(ExploreActivity.this, ObservationViewerActivity.class);
intent.putExtra("observation", item.toString());
intent.putExtra("read_only", true);
intent.putExtra("reload", true);
startActivityForResult(intent, VIEW_OBSERVATION_REQUEST_CODE);
try {
JSONObject eventParams = new JSONObject();
eventParams.put(AnalyticsClient.EVENT_PARAM_VIA, AnalyticsClient.EVENT_VALUE_EXPLORE_GRID);
AnalyticsClient.getInstance().logEvent(AnalyticsClient.EVENT_NAME_NAVIGATE_OBS_DETAILS, eventParams);
} catch (JSONException e) {
e.printStackTrace();
}
}
});
if (mTotalResults[VIEW_TYPE_OBSERVATIONS] == NOT_LOADED) {
if (mObservationsViewMode == OBSERVATIONS_VIEW_MODE_GRID) {
mLoadingObservationsGrid.setVisibility(View.VISIBLE);
} else {
mLoadingObservationsGrid.setVisibility(View.GONE);
}
mObservationsGrid.setVisibility(View.GONE);
mObservationsGridEmpty.setVisibility(View.GONE);
mObservationsMapContainer.setVisibility(View.GONE);
} else {
mLoadingObservationsGrid.setVisibility(View.GONE);
if (mResults[VIEW_TYPE_OBSERVATIONS].size() == 0) {
mObservationsGridEmpty.setVisibility(View.VISIBLE);
} else {
mObservationsGridEmpty.setVisibility(View.GONE);
}
Runnable setObsInGrid = new Runnable() {
@Override
public void run() {
if ((mGridAdapter != null) && (mCurrentResultsPage[VIEW_TYPE_OBSERVATIONS] > 1)) {
// New results appended - don't reload the entire adapter
mGridAdapter.notifyDataSetChanged();
} else if (mObservationsGrid.getColumnWidth() > 0) {
mGridAdapter = new ObservationGridAdapter(ExploreActivity.this, mObservationsGrid.getColumnWidth(), mResults[VIEW_TYPE_OBSERVATIONS]);
mObservationsGrid.setAdapter(mGridAdapter);
} else if (mObservationsGrid.getColumnWidth() == 0) {
mObservationsGrid.postDelayed(this, 100);
}
}
};
mObservationsGrid.post(setObsInGrid);
mObservationsGrid.setVisibility(View.VISIBLE);
}
loadListViewOffset(mObservationsGrid, getIntent().getExtras(), "mList" + VIEW_TYPE_OBSERVATIONS);
mObservationsGrid.setOnScrollListener(new AbsListView.OnScrollListener() {
@Override
public void onScroll(AbsListView view, int firstVisibleItem, int visibleItemCount, int totalItemCount) {
if ((firstVisibleItem + visibleItemCount >= totalItemCount - 9) && (totalItemCount > 0)) {
// The end has been reached - load more observations
loadNextResultsPage(VIEW_TYPE_OBSERVATIONS, false);
}
}
@Override
public void onScrollStateChanged(AbsListView view, int scrollState) {
}
});
if (mObservationsViewMode == OBSERVATIONS_VIEW_MODE_GRID) {
mObservationsViewModeGrid.setSelected(true);
mObservationsViewModeGrid.setColorFilter(Color.parseColor("#ffffff"));
mObservationsViewModeMap.setSelected(false);
mObservationsViewModeMap.setColorFilter(Color.parseColor("#676767"));
mLoadingObservationsGrid.setVisibility(View.VISIBLE);
mObservationsMapContainer.setVisibility(View.GONE);
} else {
mObservationsViewModeGrid.setSelected(false);
mObservationsViewModeGrid.setColorFilter(Color.parseColor("#676767"));
mObservationsViewModeMap.setSelected(true);
mObservationsViewModeMap.setColorFilter(Color.parseColor("#ffffff"));
mLoadingObservationsGrid.setVisibility(View.GONE);
mObservationsMapContainer.setVisibility(View.VISIBLE);
mMapHide.setVisibility(View.GONE);
mObservationsGrid.setVisibility(View.GONE);
mObservationsGridEmpty.setVisibility(View.GONE);
}
mObservationsViewModeGrid.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
mObservationsViewMode = OBSERVATIONS_VIEW_MODE_GRID;
refreshObservations();
}
});
mObservationsViewModeMap.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
mObservationsViewMode = OBSERVATIONS_VIEW_MODE_MAP;
refreshObservations();
}
});
mObservationsChangeMapLayers.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
if (mObservationsMapType == GoogleMap.MAP_TYPE_SATELLITE) {
mObservationsMapType = GoogleMap.MAP_TYPE_TERRAIN;
} else {
mObservationsMapType = GoogleMap.MAP_TYPE_SATELLITE;
}
refreshMapType();
}
});
refreshMapType();
mRedoObservationsSearch.setVisibility(mMapMoved ? View.VISIBLE : View.GONE);
mPerformingSearch.setVisibility(mLoadingNextResults[VIEW_TYPE_OBSERVATIONS] ? View.VISIBLE : View.GONE);
mRedoObservationSearchIcon.setVisibility(mLoadingNextResults[VIEW_TYPE_OBSERVATIONS] ? View.GONE : View.VISIBLE);
mRedoObservationsSearchText.setTextColor(mLoadingNextResults[VIEW_TYPE_OBSERVATIONS] ? Color.parseColor("#8A000000") : Color.parseColor("#000000"));
mRedoObservationsSearch.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
// Re-search under the current map bounds
VisibleRegion vr = mObservationsMap.getProjection().getVisibleRegion();
LatLngBounds bounds = new LatLngBounds(new LatLng(vr.nearLeft.latitude, vr.farLeft.longitude), new LatLng(vr.farRight.latitude, vr.farRight.longitude));
mSearchFilters.mapBounds = bounds;
// Clear out the place (search by map bounds only)
mSearchFilters.place = null;
if ((mLastMapBounds != null) && (mInitialLocationBounds != null) && (mLastMapBounds.equals(mInitialLocationBounds) == true)) {
mSearchFilters.isCurrentLocation = true;
} else {
mSearchFilters.isCurrentLocation = false;
}
resetResults(true);
loadAllResults();
mPerformingSearch.setVisibility(View.VISIBLE);
mRedoObservationSearchIcon.setVisibility(View.GONE);
mRedoObservationsSearchText.setTextColor(Color.parseColor("#8A000000"));
}
});
if (mSearchFilters.place != null) {
// Show the boundaries/border of the place on the map
addPlaceLayerToMap(mSearchFilters.place);
}
// Set the tile overlay (for the taxon's observations map)
TileProvider tileProvider = new UrlTileProvider(256, 256) {
@Override
public URL getTileUrl(int x, int y, int zoom) {
String s = String.format(INaturalistService.API_HOST + "/%s/%d/%d/%d.png?%s", zoom <= 9 ? "colored_heatmap" : "points", zoom, x, y, mSearchFilters.toUrlQueryString());
try {
return new URL(s);
} catch (MalformedURLException e) {
throw new AssertionError(e);
}
}
};
if (mObservationsMap != null) {
TileOverlay tileOverlay = mObservationsMap.addTileOverlay(new TileOverlayOptions().tileProvider(tileProvider));
}
}
use of com.google.android.gms.maps.model.LatLngBounds in project iNaturalistAndroid by inaturalist.
the class ExploreSearchFilters method readObject.
private void readObject(ObjectInputStream ois) throws ClassNotFoundException, IOException {
ois.defaultReadObject();
try {
user = userJson != null ? new JSONObject(userJson) : null;
project = projectJson != null ? new JSONObject(projectJson) : null;
place = placeJson != null ? new JSONObject(placeJson) : null;
taxon = taxonJson != null ? new JSONObject(taxonJson) : null;
} catch (JSONException e) {
e.printStackTrace();
}
if (ois.available() > 0) {
mapBounds = new LatLngBounds(new LatLng(ois.readDouble(), ois.readDouble()), new LatLng(ois.readDouble(), ois.readDouble()));
}
}
use of com.google.android.gms.maps.model.LatLngBounds in project android-samples by googlemaps.
the class TagsDemoActivity method onMapReady.
@Override
public void onMapReady(GoogleMap map) {
mMap = map;
UiSettings mUiSettings = mMap.getUiSettings();
// Turn off the map toolbar.
mUiSettings.setMapToolbarEnabled(false);
// Disable interaction with the map - other than clicking.
mUiSettings.setZoomControlsEnabled(false);
mUiSettings.setScrollGesturesEnabled(false);
mUiSettings.setZoomGesturesEnabled(false);
mUiSettings.setTiltGesturesEnabled(false);
mUiSettings.setRotateGesturesEnabled(false);
// Add a circle, a ground overlay, a marker, a polygon and a polyline to the map.
addObjectsToMap();
// Set listeners for click events. See the bottom of this class for their behavior.
mMap.setOnCircleClickListener(this);
mMap.setOnGroundOverlayClickListener(this);
mMap.setOnMarkerClickListener(this);
mMap.setOnPolygonClickListener(this);
mMap.setOnPolylineClickListener(this);
// Override the default content description on the view, for accessibility mode.
// Ideally this string would be localised.
map.setContentDescription(getString(R.string.tags_demo_map_description));
// Create bounds that include all locations of the map.
LatLngBounds bounds = new LatLngBounds.Builder().include(ADELAIDE).include(BRISBANE).include(DARWIN).include(HOBART).include(PERTH).include(SYDNEY).build();
mMap.moveCamera(CameraUpdateFactory.newLatLngBounds(bounds, 100));
}
use of com.google.android.gms.maps.model.LatLngBounds in project android-samples by googlemaps.
the class MarkerDemoActivity method onMapReady.
@Override
public void onMapReady(GoogleMap map) {
mMap = map;
// Hide the zoom controls as the button panel will cover it.
mMap.getUiSettings().setZoomControlsEnabled(false);
// Add lots of markers to the map.
addMarkersToMap();
// Setting an info window adapter allows us to change the both the contents and look of the
// info window.
mMap.setInfoWindowAdapter(new CustomInfoWindowAdapter());
// Set listeners for marker events. See the bottom of this class for their behavior.
mMap.setOnMarkerClickListener(this);
mMap.setOnInfoWindowClickListener(this);
mMap.setOnMarkerDragListener(this);
mMap.setOnInfoWindowCloseListener(this);
mMap.setOnInfoWindowLongClickListener(this);
// Override the default content description on the view, for accessibility mode.
// Ideally this string would be localised.
mMap.setContentDescription("Map with lots of markers.");
LatLngBounds bounds = new LatLngBounds.Builder().include(PERTH).include(SYDNEY).include(ADELAIDE).include(BRISBANE).include(MELBOURNE).include(DARWIN).build();
mMap.moveCamera(CameraUpdateFactory.newLatLngBounds(bounds, 50));
}
Aggregations