use of com.google.android.gms.maps.model.TileOverlayOptions in project wigle-wifi-wardriving by wiglenet.
the class MappingFragment method setupMapView.
private void setupMapView(final View view, final LatLng oldCenter, final int oldZoom) {
// view
final RelativeLayout rlView = (RelativeLayout) view.findViewById(R.id.map_rl);
if (mapView != null) {
ViewGroup.LayoutParams params = new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT);
mapView.setLayoutParams(params);
}
// conditionally replace the tile source
final SharedPreferences prefs = getActivity().getSharedPreferences(ListFragment.SHARED_PREFS, 0);
rlView.addView(mapView);
// guard against not having google play services
mapView.getMapAsync(new OnMapReadyCallback() {
@Override
public void onMapReady(final GoogleMap googleMap) {
if (ActivityCompat.checkSelfPermission(MappingFragment.this.getContext(), android.Manifest.permission.ACCESS_FINE_LOCATION) == PackageManager.PERMISSION_GRANTED || ActivityCompat.checkSelfPermission(MappingFragment.this.getContext(), android.Manifest.permission.ACCESS_COARSE_LOCATION) == PackageManager.PERMISSION_GRANTED) {
googleMap.setMyLocationEnabled(true);
}
googleMap.setBuildingsEnabled(true);
final boolean showTraffic = prefs.getBoolean(ListFragment.PREF_MAP_TRAFFIC, true);
googleMap.setTrafficEnabled(showTraffic);
final int mapType = prefs.getInt(ListFragment.PREF_MAP_TYPE, GoogleMap.MAP_TYPE_NORMAL);
googleMap.setMapType(mapType);
mapRender = new MapRender(getActivity(), googleMap, false);
googleMap.setOnMyLocationButtonClickListener(new GoogleMap.OnMyLocationButtonClickListener() {
@Override
public boolean onMyLocationButtonClick() {
if (!state.locked) {
state.locked = true;
if (menu != null) {
MenuItem item = menu.findItem(MENU_TOGGLE_LOCK);
String name = state.locked ? getString(R.string.menu_turn_off_lockon) : getString(R.string.menu_turn_on_lockon);
item.setTitle(name);
MainActivity.info("on-my-location received - activating lock");
}
}
return false;
}
});
googleMap.setOnCameraMoveStartedListener(new GoogleMap.OnCameraMoveStartedListener() {
@Override
public void onCameraMoveStarted(int reason) {
if (reason == REASON_GESTURE) {
if (state.locked) {
state.locked = false;
if (menu != null) {
MenuItem item = menu.findItem(MENU_TOGGLE_LOCK);
String name = state.locked ? getString(R.string.menu_turn_off_lockon) : getString(R.string.menu_turn_on_lockon);
item.setTitle(name);
}
}
} else if (reason == REASON_API_ANIMATION) {
// DEBUG: MainActivity.info("Camera moved due to user tap");
// TODO: should we combine this case with REASON_GESTURE?
} else if (reason == REASON_DEVELOPER_ANIMATION) {
// MainActivity.info("Camera moved due to app directive");
}
}
});
// controller
final LatLng centerPoint = getCenter(getActivity(), oldCenter, previousLocation);
float zoom = DEFAULT_ZOOM;
if (oldZoom >= 0) {
zoom = oldZoom;
} else {
zoom = prefs.getFloat(ListFragment.PREF_PREV_ZOOM, zoom);
}
final CameraPosition cameraPosition = new CameraPosition.Builder().target(centerPoint).zoom(zoom).build();
googleMap.moveCamera(CameraUpdateFactory.newCameraPosition(cameraPosition));
if (!ListFragment.PREF_MAP_NO_TILE.equals(prefs.getString(ListFragment.PREF_SHOW_DISCOVERED, ListFragment.PREF_MAP_NO_TILE))) {
final int providerTileRes = MainActivity.isHighDefinition() ? 512 : 256;
// TODO: DRY up token composition vs AbstractApiRequest?
String ifAuthToken = null;
try {
final String authname = prefs.getString(ListFragment.PREF_AUTHNAME, null);
final String token = TokenAccess.getApiToken(prefs);
if ((null != authname) && (null != token)) {
final String encoded = Base64.encodeToString((authname + ":" + token).getBytes("UTF-8"), Base64.NO_WRAP);
ifAuthToken = "Basic " + encoded;
}
} catch (UnsupportedEncodingException ueex) {
MainActivity.error("map tiles: unable to encode credentials for mine/others", ueex);
} catch (UnsupportedOperationException uoex) {
MainActivity.error("map tiles: unable to access credentials for mine/others", uoex);
}
final String authToken = ifAuthToken;
final String userAgent = AbstractApiRequest.getUserAgentString();
TileProvider tileProvider = new TileProvider() {
@Override
public Tile getTile(int x, int y, int zoom) {
if (!checkTileExists(x, y, zoom)) {
return null;
}
final Long since = prefs.getLong(ListFragment.PREF_SHOW_DISCOVERED_SINCE, 2001);
int thisYear = Calendar.getInstance().get(Calendar.YEAR);
String tileContents = prefs.getString(ListFragment.PREF_SHOW_DISCOVERED, ListFragment.PREF_MAP_NO_TILE);
String sinceString = String.format("%d0000-00000", since);
String toString = String.format("%d0000-00000", thisYear + 1);
String s = String.format(MAP_TILE_URL_FORMAT, zoom, x, y, sinceString, toString);
if (MainActivity.isHighDefinition()) {
s += HIGH_RES_TILE_TRAILER;
}
// ALIBI: defaults to "ALL"
if (ListFragment.PREF_MAP_ONLYMINE_TILE.equals(tileContents)) {
s += ONLY_MINE_TILE_TRAILER;
} else if (ListFragment.PREF_MAP_NOTMINE_TILE.equals(tileContents)) {
s += NOT_MINE_TILE_TRAILER;
}
try {
final byte[] data = downloadData(new URL(s), userAgent, authToken);
if (data != null) {
return new Tile(providerTileRes, providerTileRes, data);
}
} catch (MalformedURLException e) {
throw new AssertionError(e);
}
return null;
}
/*
* depends on supported levels on the server
*/
private boolean checkTileExists(int x, int y, int zoom) {
int minZoom = 0;
int maxZoom = 24;
if ((zoom < minZoom || zoom > maxZoom)) {
return false;
}
return true;
}
private byte[] downloadData(final URL url, final String userAgent, final String authToken) {
ByteArrayOutputStream baos = new ByteArrayOutputStream();
InputStream is = null;
try {
HttpURLConnection conn = (HttpURLConnection) url.openConnection();
if (null != authToken) {
conn.setRequestProperty("Authorization", authToken);
}
conn.setRequestProperty("User-Agent", userAgent);
is = conn.getInputStream();
byte[] byteChunk = new byte[4096];
int n;
while ((n = is.read(byteChunk)) > 0) {
baos.write(byteChunk, 0, n);
}
} catch (IOException e) {
MainActivity.error("Failed while reading bytes from " + url.toExternalForm() + ": " + e.getMessage());
e.printStackTrace();
} finally {
if (is != null) {
try {
is.close();
} catch (IOException ioex) {
MainActivity.error("Failed while closing InputStream " + url.toExternalForm() + ": " + ioex.getMessage());
ioex.printStackTrace();
}
}
}
return baos.toByteArray();
}
};
tileOverlay = googleMap.addTileOverlay(new TileOverlayOptions().tileProvider(tileProvider).transparency(0.35f));
}
}
});
MainActivity.info("done setupMapView.");
}
use of com.google.android.gms.maps.model.TileOverlayOptions in project iosched by google.
the class MapFragment method onTilesLoaded.
/**
* Add the first TileOverlay to the map.
*/
private void onTilesLoaded(List<TileLoadingTask.TileEntry> list) {
if (list.isEmpty()) {
return;
}
// Get the first entry and make it visible
TileLoadingTask.TileEntry entry = list.get(0);
TileOverlayOptions tileOverlay = new TileOverlayOptions().tileProvider(entry.provider).visible(true);
// Store the tile overlay and provider
mTileProvider = entry.provider;
mTileOverlay = mMap.addTileOverlay(tileOverlay);
}
use of com.google.android.gms.maps.model.TileOverlayOptions in project iNaturalistAndroid by inaturalist.
the class TaxonActivity method onCreate.
@Override
public void onCreate(Bundle savedInstanceState) {
requestWindowFeature(Window.FEATURE_INDETERMINATE_PROGRESS);
requestWindowFeature(Window.FEATURE_PROGRESS);
super.onCreate(savedInstanceState);
final ActionBar actionBar = getSupportActionBar();
mApp = (INaturalistApp) getApplicationContext();
mHelper = new ActivityHelper(this);
Intent intent = getIntent();
if (savedInstanceState == null) {
mTaxon = (BetterJSONObject) intent.getSerializableExtra(TAXON);
mObservation = (BetterJSONObject) intent.getSerializableExtra(OBSERVATION);
mDownloadTaxon = intent.getBooleanExtra(DOWNLOAD_TAXON, false);
mTaxonSuggestion = intent.getIntExtra(TAXON_SUGGESTION, TAXON_SUGGESTION_NONE);
mMapBoundsSet = false;
mIsTaxonomyListExpanded = false;
} else {
mTaxon = (BetterJSONObject) savedInstanceState.getSerializable(TAXON);
mObservation = (BetterJSONObject) savedInstanceState.getSerializable(OBSERVATION);
mDownloadTaxon = savedInstanceState.getBoolean(DOWNLOAD_TAXON);
mMapBoundsSet = savedInstanceState.getBoolean("mMapBoundsSet");
mTaxonSuggestion = savedInstanceState.getInt(TAXON_SUGGESTION);
mIsTaxonomyListExpanded = savedInstanceState.getBoolean("mIsTaxonomyListExpanded");
}
setContentView(R.layout.taxon_page);
mScrollView = (ScrollView) findViewById(R.id.scroll_view);
mPhotosContainer = (ViewGroup) findViewById(R.id.taxon_photos_container);
mNoPhotosContainer = (ViewGroup) findViewById(R.id.no_taxon_photos_container);
mPhotosViewPager = (HackyViewPager) findViewById(R.id.taxon_photos);
mPhotosIndicator = (CirclePageIndicator) findViewById(R.id.photos_indicator);
mTaxonName = (TextView) findViewById(R.id.taxon_name);
mTaxonScientificName = (TextView) findViewById(R.id.taxon_scientific_name);
mWikipediaSummary = (TextView) findViewById(R.id.wikipedia_summary);
mConservationStatusContainer = (ViewGroup) findViewById(R.id.conservation_status_container);
mConservationStatus = (TextView) findViewById(R.id.conservation_status);
mConservationSource = (TextView) findViewById(R.id.conservation_source);
((ScrollableMapFragment) getSupportFragmentManager().findFragmentById(R.id.observations_map)).getMapAsync(new OnMapReadyCallback() {
@Override
public void onMapReady(GoogleMap googleMap) {
mMap = googleMap;
mMap.setMyLocationEnabled(false);
mMap.setMapType(GoogleMap.MAP_TYPE_NORMAL);
mMap.getUiSettings().setAllGesturesEnabled(false);
mMap.getUiSettings().setZoomControlsEnabled(false);
// Set the tile overlay (for the taxon's observations map)
TileProvider tileProvider = new UrlTileProvider(512, 512) {
@Override
public URL getTileUrl(int x, int y, int zoom) {
String s = String.format(INaturalistService.API_HOST + "/colored_heatmap/%d/%d/%d.png?taxon_id=%d", zoom, x, y, mTaxon.getInt("id"));
try {
return new URL(s);
} catch (MalformedURLException e) {
throw new AssertionError(e);
}
}
};
TileOverlay tileOverlay = mMap.addTileOverlay(new TileOverlayOptions().tileProvider(tileProvider));
mMap.setOnMapClickListener(new GoogleMap.OnMapClickListener() {
@Override
public void onMapClick(LatLng latLng) {
Intent intent = new Intent(TaxonActivity.this, TaxonMapActivity.class);
intent.putExtra(TaxonMapActivity.TAXON_ID, mTaxon.getInt("id"));
intent.putExtra(TaxonMapActivity.TAXON_NAME, actionBar.getTitle());
CameraPosition position = mMap.getCameraPosition();
intent.putExtra(TaxonMapActivity.MAP_LATITUDE, position.target.latitude);
intent.putExtra(TaxonMapActivity.MAP_LONGITUDE, position.target.longitude);
intent.putExtra(TaxonMapActivity.MAP_ZOOM, position.zoom);
intent.putExtra(TaxonMapActivity.OBSERVATION, mObservation);
startActivity(intent);
}
});
}
});
mViewOnINat = (ViewGroup) findViewById(R.id.view_on_inat);
mLoadingPhotos = (ProgressBar) findViewById(R.id.loading_photos);
mTaxonButtons = (ViewGroup) findViewById(R.id.taxon_buttons);
mSelectTaxon = (ViewGroup) findViewById(R.id.select_taxon);
mCompareTaxon = (ViewGroup) findViewById(R.id.compare_taxon);
mTaxonicIcon = (ImageView) findViewById(R.id.taxon_iconic_taxon);
mTaxonInactive = (ViewGroup) findViewById(R.id.taxon_inactive);
mTaxonButtons.setVisibility(mTaxonSuggestion != TAXON_SUGGESTION_NONE ? View.VISIBLE : View.GONE);
mSelectTaxon.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
// Taxon selected - return that taxon back
Intent intent = new Intent();
Bundle bundle = new Bundle();
JSONObject taxon = mTaxon.getJSONObject();
bundle.putString(TaxonSearchActivity.ID_NAME, TaxonUtils.getTaxonName(TaxonActivity.this, taxon));
bundle.putString(TaxonSearchActivity.TAXON_NAME, taxon.optString("name"));
bundle.putString(TaxonSearchActivity.ICONIC_TAXON_NAME, taxon.optString("iconic_taxon_name"));
if (taxon.has("default_photo") && !taxon.isNull("default_photo"))
bundle.putString(TaxonSearchActivity.ID_PIC_URL, taxon.optJSONObject("default_photo").optString("square_url"));
bundle.putBoolean(TaxonSearchActivity.IS_CUSTOM, false);
bundle.putInt(TaxonSearchActivity.TAXON_ID, taxon.optInt("id"));
intent.putExtras(bundle);
setResult(RESULT_OK, intent);
finish();
}
});
mCompareTaxon.setVisibility(mTaxonSuggestion == TAXON_SUGGESTION_COMPARE_AND_SELECT ? View.VISIBLE : View.GONE);
mCompareTaxon.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
// Show taxon comparison screen - we do this by indicating the calling activity (TaxonSuggestions/CompareSuggestions)
// that the user select this taxon for comparison
Intent intent = new Intent();
setResult(RESULT_COMPARE_TAXON, intent);
finish();
}
});
mViewOnINat.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
String inatNetwork = mApp.getInaturalistNetworkMember();
String inatHost = mApp.getStringResourceByName("inat_host_" + inatNetwork);
Locale deviceLocale = getResources().getConfiguration().locale;
String deviceLanguage = deviceLocale.getLanguage();
String taxonUrl = String.format("%s/taxa/%d?locale=%s", inatHost, mTaxon.getInt("id"), deviceLanguage);
Intent i = new Intent(Intent.ACTION_VIEW);
i.setData(Uri.parse(taxonUrl));
startActivity(i);
}
});
mTaxonomyIcon = (ImageView) findViewById(R.id.taxonomy_info);
mTaxonomyList = (ListView) findViewById(R.id.taxonomy_list);
mTaxonomyIcon.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
mHelper.confirm(getString(R.string.about_this_section), getString(R.string.taxonomy_info), new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
dialog.dismiss();
}
}, null, R.string.got_it, 0);
}
});
// Make sure the user will be able to scroll/zoom the map (since it's inside a ScrollView)
((ScrollableMapFragment) getSupportFragmentManager().findFragmentById(R.id.observations_map)).setListener(new ScrollableMapFragment.OnTouchListener() {
@Override
public void onTouch() {
mScrollView.requestDisallowInterceptTouchEvent(true);
}
});
actionBar.setHomeButtonEnabled(true);
actionBar.setLogo(R.drawable.ic_arrow_back);
actionBar.setDisplayHomeAsUpEnabled(true);
loadTaxon();
}
use of com.google.android.gms.maps.model.TileOverlayOptions in project iNaturalistAndroid by inaturalist.
the class TaxonMapActivity method onCreate.
@Override
public void onCreate(Bundle savedInstanceState) {
requestWindowFeature(Window.FEATURE_INDETERMINATE_PROGRESS);
requestWindowFeature(Window.FEATURE_PROGRESS);
super.onCreate(savedInstanceState);
ActionBar actionBar = getSupportActionBar();
mApp = (INaturalistApp) getApplicationContext();
mHelper = new ActivityHelper(this);
Intent intent = getIntent();
if (savedInstanceState == null) {
mTaxonId = intent.getIntExtra(TAXON_ID, 0);
mTaxonName = intent.getStringExtra(TAXON_NAME);
mMapLongitude = intent.getDoubleExtra(MAP_LONGITUDE, 0);
mMapLatitude = intent.getDoubleExtra(MAP_LATITUDE, 0);
mMapZoom = intent.getFloatExtra(MAP_ZOOM, 0);
mObservation = (BetterJSONObject) intent.getSerializableExtra(OBSERVATION);
} else {
mTaxonId = savedInstanceState.getInt(TAXON_ID);
mTaxonName = savedInstanceState.getString(TAXON_NAME);
mMapLongitude = savedInstanceState.getDouble(MAP_LONGITUDE, 0);
mMapLatitude = savedInstanceState.getDouble(MAP_LATITUDE, 0);
mMapZoom = savedInstanceState.getFloat(MAP_ZOOM, 0);
mObservation = (BetterJSONObject) savedInstanceState.getSerializable(OBSERVATION);
}
setContentView(R.layout.taxon_map);
((SupportMapFragment) getSupportFragmentManager().findFragmentById(R.id.observations_map)).getMapAsync(new OnMapReadyCallback() {
@Override
public void onMapReady(GoogleMap googleMap) {
mMap = googleMap;
mMap.setMyLocationEnabled(true);
mMap.getUiSettings().setZoomControlsEnabled(true);
mMap.setMapType(GoogleMap.MAP_TYPE_NORMAL);
// 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 + "/colored_heatmap/%d/%d/%d.png?taxon_id=%d", zoom, x, y, mTaxonId);
try {
return new URL(s);
} catch (MalformedURLException e) {
throw new AssertionError(e);
}
}
};
TileOverlay tileOverlay = mMap.addTileOverlay(new TileOverlayOptions().tileProvider(tileProvider));
if (mObservation != null) {
boolean markerOnly = false;
boolean updateCamera = false;
final Observation obs = new Observation(mObservation);
mHelper.addMapPosition(mMap, obs, mObservation, markerOnly, updateCamera);
mHelper.centerObservationImmediate(mMap, obs);
}
}
});
actionBar.setHomeButtonEnabled(true);
actionBar.setLogo(R.drawable.ic_arrow_back);
actionBar.setDisplayHomeAsUpEnabled(true);
actionBar.setTitle(mTaxonName);
}
use of com.google.android.gms.maps.model.TileOverlayOptions 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));
}
}
Aggregations