use of org.osmdroid.views.overlay.mylocation.MyLocationNewOverlay in project collect by opendatakit.
the class GeoPointOsmMapActivity method onCreate.
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
requestWindowFeature(Window.FEATURE_NO_TITLE);
if (savedInstanceState != null) {
locationCount = savedInstanceState.getInt(LOCATION_COUNT);
}
try {
setContentView(R.layout.geopoint_osm_layout);
} catch (NoClassDefFoundError e) {
ToastUtils.showShortToast(R.string.google_play_services_error_occured);
finish();
return;
}
map = findViewById(R.id.omap);
if (helper == null) {
// For testing:
helper = new MapHelper(this, map, this);
map.setMultiTouchControls(true);
map.setBuiltInZoomControls(true);
map.setTilesScaledToDpi(true);
}
marker = new Marker(map);
marker.setIcon(ContextCompat.getDrawable(getApplicationContext(), R.drawable.ic_place_black_36dp));
myLocationOverlay = new MyLocationNewOverlay(map);
handler.postDelayed(new Runnable() {
public void run() {
GeoPoint point = new GeoPoint(34.08145, -39.85007);
map.getController().setZoom(4);
map.getController().setCenter(point);
}
}, 100);
locationStatus = findViewById(R.id.location_status);
TextView locationInfo = findViewById(R.id.location_info);
locationClient = LocationClients.clientForContext(this);
locationClient.setListener(this);
ImageButton saveLocationButton = findViewById(R.id.accept_location);
saveLocationButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Collect.getInstance().getActivityLogger().logInstanceAction(this, "acceptLocation", "OK");
returnLocation();
}
});
reloadLocationButton = findViewById(R.id.reload_location);
reloadLocationButton.setEnabled(false);
reloadLocationButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
map.getOverlays().add(marker);
setClear = false;
latLng = new GeoPoint(location.getLatitude(), location.getLongitude());
marker.setPosition(latLng);
captureLocation = true;
isDragged = false;
zoomToPoint();
}
});
// Focuses on marked location
showLocationButton = findViewById(R.id.show_location);
showLocationButton.setVisibility(View.VISIBLE);
showLocationButton.setEnabled(false);
showLocationButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Collect.getInstance().getActivityLogger().logInstanceAction(this, "showLocation", "onClick");
showZoomDialog();
}
});
// not clickable until we have a marker set....
showLocationButton.setClickable(false);
// Menu Layer Toggle
ImageButton layersButton = findViewById(R.id.layer_menu);
layersButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
helper.showLayersDialog(GeoPointOsmMapActivity.this);
}
});
zoomDialogView = getLayoutInflater().inflate(R.layout.geopoint_zoom_dialog, null);
zoomLocationButton = zoomDialogView.findViewById(R.id.zoom_location);
zoomLocationButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
zoomToLocation();
map.invalidate();
zoomDialog.dismiss();
}
});
zoomPointButton = zoomDialogView.findViewById(R.id.zoom_point);
zoomPointButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
zoomToPoint();
map.invalidate();
zoomDialog.dismiss();
}
});
ImageButton clearPointButton = findViewById(R.id.clear);
clearPointButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
map.getOverlays().remove(marker);
marker.remove(map);
if (location != null) {
reloadLocationButton.setEnabled(true);
// locationStatus.setVisibility(View.VISIBLE);
}
locationStatus.setVisibility(View.VISIBLE);
map.getOverlays().remove(marker);
marker.remove(map);
setClear = true;
isDragged = false;
captureLocation = false;
draggable = intentDraggable;
locationFromIntent = false;
overlayMyLocationLayers();
map.invalidate();
}
});
Intent intent = getIntent();
if (intent != null && intent.getExtras() != null) {
if (intent.hasExtra(GeoPointWidget.DRAGGABLE_ONLY)) {
draggable = intent.getBooleanExtra(GeoPointWidget.DRAGGABLE_ONLY, false);
intentDraggable = draggable;
if (!intentDraggable) {
// Not Draggable, set text for Map else leave as placement-map text
locationInfo.setText(getString(R.string.geopoint_no_draggable_instruction));
}
}
if (intent.hasExtra(GeoPointWidget.READ_ONLY)) {
readOnly = intent.getBooleanExtra(GeoPointWidget.READ_ONLY, false);
if (readOnly) {
captureLocation = true;
clearPointButton.setEnabled(false);
}
}
if (intent.hasExtra(GeoPointWidget.LOCATION)) {
double[] location = intent.getDoubleArrayExtra(GeoPointWidget.LOCATION);
latLng = new GeoPoint(location[0], location[1]);
reloadLocationButton.setEnabled(false);
captureLocation = true;
isDragged = true;
// If data loaded, must clear first
draggable = false;
locationFromIntent = true;
}
}
if (latLng != null) {
marker.setPosition(latLng);
map.getOverlays().add(marker);
map.invalidate();
captureLocation = true;
foundFirstLocation = true;
zoomToPoint();
}
}
use of org.osmdroid.views.overlay.mylocation.MyLocationNewOverlay in project collect by opendatakit.
the class GeoShapeOsmMapActivity method onCreate.
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
requestWindowFeature(Window.FEATURE_NO_TITLE);
setContentView(R.layout.geoshape_osm_layout);
// Setting title of the action
setTitle(getString(R.string.geoshape_title));
ImageButton saveButton = findViewById(R.id.save);
clearButton = findViewById(R.id.clear);
map = findViewById(R.id.geoshape_mapview);
helper = new MapHelper(this, map, this);
map.setMultiTouchControls(true);
map.setBuiltInZoomControls(true);
map.setTilesScaledToDpi(true);
map.setMapListener(mapViewListener);
overlayPointPathListener();
saveButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
returnLocation();
}
});
clearButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
if (mapMarkers.size() != 0) {
showClearDialog();
}
}
});
ImageButton layersButton = findViewById(R.id.layers);
layersButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
helper.showLayersDialog(GeoShapeOsmMapActivity.this);
}
});
locationButton = findViewById(R.id.gps);
locationButton.setEnabled(false);
locationButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(final View v) {
showZoomDialog();
}
});
GpsMyLocationProvider imlp = new GpsMyLocationProvider(this.getBaseContext());
imlp.setLocationUpdateMinDistance(1000);
imlp.setLocationUpdateMinTime(60000);
myLocationOverlay = new MyLocationNewOverlay(map);
Intent intent = getIntent();
if (intent != null && intent.getExtras() != null) {
if (intent.hasExtra(GeoShapeWidget.SHAPE_LOCATION)) {
clearButton.setEnabled(true);
dataLoaded = true;
String s = intent.getStringExtra(GeoShapeWidget.SHAPE_LOCATION);
overlayIntentPolygon(s);
// zoomToCentroid();
locationButton.setEnabled(true);
zoomToBounds();
}
} else {
myLocationOverlay.runOnFirstFix(centerAroundFix);
clearButton.setEnabled(false);
final Handler handler = new Handler();
handler.postDelayed(new Runnable() {
public void run() {
GeoPoint point = new GeoPoint(34.08145, -39.85007);
map.getController().setZoom(3);
map.getController().setCenter(point);
}
}, 100);
}
map.invalidate();
zoomDialogView = getLayoutInflater().inflate(R.layout.geoshape_zoom_dialog, null);
zoomLocationButton = zoomDialogView.findViewById(R.id.zoom_location);
zoomLocationButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
zoomToMyLocation();
map.invalidate();
zoomDialog.dismiss();
}
});
zoomPointButton = zoomDialogView.findViewById(R.id.zoom_shape);
zoomPointButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
// zoomToCentroid();
zoomToBounds();
map.invalidate();
zoomDialog.dismiss();
}
});
}
use of org.osmdroid.views.overlay.mylocation.MyLocationNewOverlay in project collect by opendatakit.
the class GeoTraceOsmMapActivity method onCreate.
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
requestWindowFeature(Window.FEATURE_NO_TITLE);
setContentView(R.layout.geotrace_osm_layout);
// Setting title of the action
setTitle(getString(R.string.geotrace_title));
// For testing purposes:
if (mapView == null) {
mapView = findViewById(R.id.geotrace_mapview);
}
if (helper == null) {
helper = new MapHelper(this, mapView, this);
}
if (myLocationOverlay == null) {
myLocationOverlay = new MyLocationNewOverlay(mapView);
}
mapView.setMultiTouchControls(true);
mapView.setBuiltInZoomControls(true);
mapView.setTilesScaledToDpi(true);
mapView.getController().setZoom(zoomLevel);
inflater = this.getLayoutInflater();
traceSettingsView = inflater.inflate(R.layout.geotrace_dialog, null);
polygonPolylineView = inflater.inflate(R.layout.polygon_polyline_dialog, null);
timeDelay = traceSettingsView.findViewById(R.id.trace_delay);
timeDelay.setSelection(3);
timeUnits = traceSettingsView.findViewById(R.id.trace_scale);
layersButton = findViewById(R.id.layers);
layersButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
helper.showLayersDialog(GeoTraceOsmMapActivity.this);
}
});
locationButton = findViewById(R.id.show_location);
locationButton.setEnabled(false);
locationButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
reset_trace_settings();
showZoomDialog();
}
});
clearButton = findViewById(R.id.clear);
clearButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
showClearDialog();
}
});
ImageButton saveButton = findViewById(R.id.geotrace_save);
saveButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
if (mapMarkers.size() != 0) {
alertDialog.show();
} else {
saveGeoTrace();
}
}
});
if (mapMarkers == null || mapMarkers.size() == 0) {
clearButton.setEnabled(false);
}
manualCaptureButton = findViewById(R.id.manual_button);
manualCaptureButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
addLocationMarker();
}
});
pauseButton = findViewById(R.id.pause);
playButton = findViewById(R.id.play);
playButton.setEnabled(false);
beenPaused = false;
traceMode = 1;
playButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(final View v) {
if (!playCheck) {
if (!beenPaused) {
alert.show();
} else {
RadioGroup rb = traceSettingsView.findViewById(R.id.radio_group);
int radioButtonID = rb.getCheckedRadioButtonId();
View radioButton = rb.findViewById(radioButtonID);
traceMode = rb.indexOfChild(radioButton);
if (traceMode == 0) {
setupManualMode();
} else if (traceMode == 1) {
setupAutomaticMode();
} else {
reset_trace_settings();
}
}
playCheck = true;
} else {
playCheck = false;
startGeoTrace();
}
}
});
pauseButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(final View v) {
playButton.setVisibility(View.VISIBLE);
if (mapMarkers != null && mapMarkers.size() > 0) {
clearButton.setEnabled(true);
}
pauseButton.setVisibility(View.GONE);
manualCaptureButton.setVisibility(View.GONE);
playCheck = true;
modeActive = false;
myLocationOverlay.disableFollowLocation();
try {
schedulerHandler.cancel(true);
} catch (Exception e) {
// Do nothing
}
}
});
overlayMapLayerListener();
buildDialogs();
Intent intent = getIntent();
if (intent != null && intent.getExtras() != null) {
if (intent.hasExtra(GeoTraceWidget.TRACE_LOCATION)) {
String s = intent.getStringExtra(GeoTraceWidget.TRACE_LOCATION);
playButton.setEnabled(false);
clearButton.setEnabled(true);
overlayIntentTrace(s);
locationButton.setEnabled(true);
// zoomToCentroid();
zoomToBounds();
}
} else {
myLocationOverlay.runOnFirstFix(centerAroundFix);
}
Button polygonSaveButton = polygonPolylineView.findViewById(R.id.polygon_save);
polygonSaveButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
if (mapMarkers.size() > 2) {
createPolygon();
alertDialog.dismiss();
saveGeoTrace();
} else {
alertDialog.dismiss();
showPolygonErrorDialog();
}
}
});
Button polylineSaveButton = polygonPolylineView.findViewById(R.id.polyline_save);
polylineSaveButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
alertDialog.dismiss();
saveGeoTrace();
}
});
zoomDialogView = getLayoutInflater().inflate(R.layout.geoshape_zoom_dialog, null);
zoomLocationButton = zoomDialogView.findViewById(R.id.zoom_location);
zoomLocationButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
zoomToMyLocation();
mapView.invalidate();
zoomDialog.dismiss();
}
});
zoomPointButton = zoomDialogView.findViewById(R.id.zoom_shape);
zoomPointButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
// zoomToCentroid();
zoomToBounds();
mapView.invalidate();
zoomDialog.dismiss();
}
});
mapView.invalidate();
locationClient = LocationClients.clientForContext(this);
locationClient.setListener(this);
}
use of org.osmdroid.views.overlay.mylocation.MyLocationNewOverlay in project OpenBikeSharing by bparmentier.
the class MapActivity method onCreate.
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_map);
getActionBar().setDisplayHomeAsUpEnabled(true);
SharedPreferences settings = PreferenceManager.getDefaultSharedPreferences(this);
stationsDataSource = new StationsDataSource(this);
ArrayList<Station> stations = stationsDataSource.getStations();
map = (MapView) findViewById(R.id.mapView);
stationMarkerInfoWindow = new StationMarkerInfoWindow(R.layout.bonuspack_bubble, map);
/* handling map events */
MapEventsOverlay mapEventsOverlay = new MapEventsOverlay(this, this);
map.getOverlays().add(0, mapEventsOverlay);
/* markers list */
GridMarkerClusterer stationsMarkers = new GridMarkerClusterer();
Drawable clusterIconD = getResources().getDrawable(R.drawable.marker_cluster);
Bitmap clusterIcon = ((BitmapDrawable) clusterIconD).getBitmap();
map.getOverlays().add(stationsMarkers);
stationsMarkers.setIcon(clusterIcon);
stationsMarkers.setGridSize(100);
for (final Station station : stations) {
stationsMarkers.add(createStationMarker(station));
}
map.invalidate();
map.setMultiTouchControls(true);
map.setBuiltInZoomControls(true);
map.setMinZoomLevel(3);
/* map tile source */
String mapLayer = settings.getString(PREF_KEY_MAP_LAYER, "");
switch(mapLayer) {
case MAP_LAYER_MAPNIK:
map.setTileSource(TileSourceFactory.MAPNIK);
break;
case MAP_LAYER_CYCLEMAP:
map.setTileSource(TileSourceFactory.CYCLEMAP);
break;
case MAP_LAYER_OSMPUBLICTRANSPORT:
map.setTileSource(TileSourceFactory.PUBLIC_TRANSPORT);
break;
default:
map.setTileSource(TileSourceFactory.DEFAULT_TILE_SOURCE);
break;
}
GpsMyLocationProvider imlp = new GpsMyLocationProvider(this.getBaseContext());
imlp.setLocationUpdateMinDistance(1000);
imlp.setLocationUpdateMinTime(60000);
map.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
}
});
myLocationOverlay = new MyLocationNewOverlay(imlp, this.map);
myLocationOverlay.enableMyLocation();
map.getOverlays().add(this.myLocationOverlay);
mapController = map.getController();
if (savedInstanceState != null) {
mapController.setZoom(savedInstanceState.getInt(MAP_CURRENT_ZOOM_KEY));
mapController.setCenter(new GeoPoint(savedInstanceState.getDouble(MAP_CENTER_LAT_KEY), savedInstanceState.getDouble(MAP_CENTER_LON_KEY)));
} else {
LocationManager locationManager = (LocationManager) this.getSystemService(Context.LOCATION_SERVICE);
Location userLocation = locationManager.getLastKnownLocation(LocationManager.NETWORK_PROVIDER);
if (userLocation != null) {
mapController.setZoom(16);
mapController.animateTo(new GeoPoint(userLocation));
} else {
double bikeNetworkLatitude = Double.longBitsToDouble(settings.getLong(PREF_KEY_NETWORK_LATITUDE, 0));
double bikeNetworkLongitude = Double.longBitsToDouble(settings.getLong(PREF_KEY_NETWORK_LONGITUDE, 0));
mapController.setZoom(13);
mapController.setCenter(new GeoPoint(bikeNetworkLatitude, bikeNetworkLongitude));
Toast.makeText(this, R.string.location_not_found, Toast.LENGTH_LONG).show();
}
}
}
use of org.osmdroid.views.overlay.mylocation.MyLocationNewOverlay in project collect by opendatakit.
the class OsmDroidMapFragment method onCreateView.
@Override
public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
View view = inflater.inflate(R.layout.osm_map_layout, container, false);
map = view.findViewById(R.id.osm_map_view);
if (webMapService != null) {
map.setTileSource(webMapService.asOnlineTileSource());
}
map.setMultiTouchControls(true);
map.setBuiltInZoomControls(true);
map.setMinZoomLevel(2.0);
map.setMaxZoomLevel(22.0);
map.getController().setCenter(toGeoPoint(INITIAL_CENTER));
map.getController().setZoom((int) INITIAL_ZOOM);
map.setTilesScaledToDpi(true);
map.setFlingEnabled(false);
addAttributionAndMapEventsOverlays();
loadReferenceOverlay();
addMapLayoutChangeListener(map);
locationClient.setListener(this);
osmLocationClientWrapper = new OsmLocationClientWrapper(locationClient);
myLocationOverlay = new MyLocationNewOverlay(osmLocationClientWrapper, map);
myLocationOverlay.setDrawAccuracyEnabled(true);
Bitmap crosshairs = IconUtils.getBitmap(getActivity(), R.drawable.ic_crosshairs);
myLocationOverlay.setDirectionArrow(crosshairs, crosshairs);
myLocationOverlay.setPersonHotspot(crosshairs.getWidth() / 2.0f, crosshairs.getHeight() / 2.0f);
new Handler().postDelayed(() -> {
// call the ReadyListener if this fragment is still attached.
if (readyListener != null && getActivity() != null) {
readyListener.onReady(this);
}
}, 100);
return view;
}
Aggregations