use of org.mapsforge.core.model.LatLong in project RSAndroidApp by RailwayStations.
the class MapsActivity method onLocationChanged.
@Override
public void onLocationChanged(final Location location) {
myPos = new LatLong(location.getLatitude(), location.getLongitude());
updatePosition();
}
use of org.mapsforge.core.model.LatLong in project RSAndroidApp by RailwayStations.
the class MapsActivity method onLongPress.
private void onLongPress(final LatLong tapLatLong) {
if (missingMarker == null) {
// marker to show at the location
final Drawable drawable = ContextCompat.getDrawable(this, R.drawable.marker_missing);
assert drawable != null;
final Bitmap bitmap = AndroidGraphicFactory.convertToBitmap(drawable);
missingMarker = new Marker(tapLatLong, bitmap, -(bitmap.getWidth() / 2), -bitmap.getHeight()) {
@Override
public boolean onTap(final LatLong tapLatLong, final Point layerXY, final Point tapXY) {
new SimpleDialogs().confirm(MapsActivity.this, R.string.add_missing_station, (dialogInterface, i) -> {
final Intent intent = new Intent(MapsActivity.this, DetailsActivity.class);
intent.putExtra(DetailsActivity.EXTRA_LATITUDE, getLatLong().latitude);
intent.putExtra(DetailsActivity.EXTRA_LONGITUDE, getLatLong().longitude);
startActivity(intent);
});
return false;
}
};
binding.map.mapView.getLayerManager().getLayers().add(missingMarker);
} else {
missingMarker.setLatLong(tapLatLong);
missingMarker.requestRedraw();
}
// feedback for long click
((Vibrator) getSystemService(VIBRATOR_SERVICE)).vibrate(VibrationEffect.createOneShot(150, VibrationEffect.DEFAULT_AMPLITUDE));
}
use of org.mapsforge.core.model.LatLong in project RSAndroidApp by RailwayStations.
the class MapsActivity method createLayers.
protected void createLayers() {
final String map = baseApplication.getMap();
final Uri mapUri = baseApplication.toUri(map);
final MapDataStore mapFile = getMapFile(mapUri);
if (mapFile != null) {
final TileRendererLayer rendererLayer = new TileRendererLayer(this.tileCaches.get(0), mapFile, this.binding.map.mapView.getModel().mapViewPosition, false, true, false, AndroidGraphicFactory.INSTANCE) {
@Override
public boolean onLongPress(final LatLong tapLatLong, final Point thisXY, final Point tapXY) {
MapsActivity.this.onLongPress(tapLatLong);
return true;
}
};
rendererLayer.setXmlRenderTheme(getRenderTheme());
this.layer = rendererLayer;
binding.map.mapView.getLayerManager().getLayers().add(this.layer);
} else {
AbstractTileSource tileSource = onlineTileSources.get(map);
if (tileSource == null) {
tileSource = OpenStreetMapMapnik.INSTANCE;
}
tileSource.setUserAgent(USER_AGENT);
this.layer = new TileDownloadLayer(this.tileCaches.get(0), this.binding.map.mapView.getModel().mapViewPosition, tileSource, AndroidGraphicFactory.INSTANCE) {
@Override
public boolean onLongPress(final LatLong tapLatLong, final Point thisXY, final Point tapXY) {
MapsActivity.this.onLongPress(tapLatLong);
return true;
}
};
binding.map.mapView.getLayerManager().getLayers().add(this.layer);
binding.map.mapView.setZoomLevelMin(tileSource.getZoomLevelMin());
binding.map.mapView.setZoomLevelMax(tileSource.getZoomLevelMax());
}
}
use of org.mapsforge.core.model.LatLong in project RSAndroidApp by RailwayStations.
the class MapsActivity method onCreate.
@Override
protected void onCreate(final Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
AndroidGraphicFactory.createInstance(this.getApplication());
binding = ActivityMapsBinding.inflate(getLayoutInflater());
setContentView(binding.getRoot());
final Window window = getWindow();
window.addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS);
window.setStatusBarColor(Color.parseColor("#c71c4d"));
setSupportActionBar(binding.mapsToolbar);
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
baseApplication = (BaseApplication) getApplication();
dbAdapter = baseApplication.getDbAdapter();
nickname = baseApplication.getNickname();
final Intent intent = getIntent();
Marker extraMarker = null;
if (intent != null) {
final Double latitude = (Double) intent.getSerializableExtra(EXTRAS_LATITUDE);
final Double longitude = (Double) intent.getSerializableExtra(EXTRAS_LONGITUDE);
setMyLocSwitch(false);
if (latitude != null && longitude != null) {
myPos = new LatLong(latitude, longitude);
}
final Integer markerRes = (Integer) intent.getSerializableExtra(EXTRAS_MARKER);
if (markerRes != null) {
extraMarker = createBitmapMarker(myPos, markerRes);
}
}
addDBSTileSource(R.string.dbs_osm_basic, "/styles/dbs-osm-basic/");
addDBSTileSource(R.string.dbs_osm_railway, "/styles/dbs-osm-railway/");
createMapViews();
createTileCaches();
checkPermissionsAndCreateLayersAndControls();
if (extraMarker != null) {
binding.map.mapView.getLayerManager().getLayers().add(extraMarker);
}
}
use of org.mapsforge.core.model.LatLong in project RSAndroidApp by RailwayStations.
the class MapsActivity method addMarkers.
private void addMarkers(final List<Station> stationMarker, final List<Upload> uploadList) {
double minLat = 0;
double maxLat = 0;
double minLon = 0;
double maxLon = 0;
for (final Station station : stationMarker) {
final boolean isPendingUpload = isPendingUpload(station, uploadList);
final BahnhofGeoItem geoItem = new BahnhofGeoItem(station, isPendingUpload);
final LatLong bahnhofPos = geoItem.getLatLong();
if (minLat == 0.0) {
minLat = bahnhofPos.latitude;
maxLat = bahnhofPos.latitude;
minLon = bahnhofPos.longitude;
maxLon = bahnhofPos.longitude;
} else {
minLat = Math.min(minLat, bahnhofPos.latitude);
maxLat = Math.max(maxLat, bahnhofPos.latitude);
minLon = Math.min(minLon, bahnhofPos.longitude);
maxLon = Math.max(maxLon, bahnhofPos.longitude);
}
clusterer.addItem(geoItem);
}
clusterer.redraw();
if (myPos == null || (myPos.latitude == 0.0 && myPos.longitude == 0.0)) {
myPos = new LatLong((minLat + maxLat) / 2, (minLon + maxLon) / 2);
}
updatePosition();
}
Aggregations