use of org.mapsforge.map.layer.overlay.Marker 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.map.layer.overlay.Marker 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.map.layer.overlay.Marker in project satstat by mvglasow.
the class MapSectionFragment method applyLocationProviderStyle.
/**
* Applies a style to the map overlays associated with a given location provider.
*
* This method changes the style (effectively, the color) of the circle and
* marker overlays. Its main purpose is to switch the color of the overlays
* between gray and the provider color.
*
* @param context The context of the caller
* @param provider The name of the location provider, as returned by
* {@link LocationProvider.getName()}.
* @param styleName The name of the style to apply. If it is null, the
* default style for the provider as returned by
* assignLocationProviderStyle() is applied.
*/
protected void applyLocationProviderStyle(Context context, String provider, String styleName) {
String sn = (styleName != null) ? styleName : assignLocationProviderStyle(provider);
Boolean isStyleChanged = !sn.equals(providerAppliedStyles.get(provider));
Boolean needsRedraw = false;
Resources res = context.getResources();
TypedArray style = res.obtainTypedArray(res.getIdentifier(sn, "array", context.getPackageName()));
// Circle layer
Circle circle = mapCircles.get(provider);
if (circle != null) {
circle.getPaintFill().setColor(style.getColor(Const.STYLE_FILL, R.color.circle_gray_fill));
circle.getPaintStroke().setColor(style.getColor(Const.STYLE_STROKE, R.color.circle_gray_stroke));
needsRedraw = isStyleChanged && circle.isVisible();
}
// Marker layer
Marker marker = mapMarkers.get(provider);
if (marker != null) {
Drawable drawable = style.getDrawable(Const.STYLE_MARKER);
Bitmap bitmap = AndroidGraphicFactory.convertToBitmap(drawable);
marker.setBitmap(bitmap);
needsRedraw = needsRedraw || (isStyleChanged && marker.isVisible());
}
if (needsRedraw) {
LayerManager manager = mapMap.getLayerManager();
if (manager != null)
manager.redrawLayers();
}
providerAppliedStyles.put(provider, sn);
style.recycle();
}
use of org.mapsforge.map.layer.overlay.Marker in project RSAndroidApp by RailwayStations.
the class MapsActivity method createBitmapMarker.
private Marker createBitmapMarker(final LatLong latLong, final int markerRes) {
final Drawable drawable = ContextCompat.getDrawable(this, markerRes);
assert drawable != null;
final Bitmap bitmap = AndroidGraphicFactory.convertToBitmap(drawable);
return new Marker(latLong, bitmap, -(bitmap.getWidth() / 2), -bitmap.getHeight());
}
use of org.mapsforge.map.layer.overlay.Marker in project satstat by mvglasow.
the class MapSectionFragment method onLocationProvidersChanged.
/**
* Updates internal data structures when the user's selection of location providers has changed.
* @param providers The new set of location providers
*/
public void onLocationProvidersChanged(Set<String> providers) {
Context context = this.getContext();
List<String> allProviders = mainActivity.locationManager.getAllProviders();
ArrayList<String> removedProviders = new ArrayList<String>();
for (String pr : providerLocations.keySet()) if (!providers.contains(pr))
removedProviders.add(pr);
// remove cached locations and invalidators for providers which are no longer selected
for (String pr : removedProviders) {
providerLocations.remove(pr);
providerInvalidators.remove(pr);
}
// ensure there is a cached location for each chosen provider (can be null)
for (String pr : providers) {
if ((allProviders.indexOf(pr) >= 0) && !providerLocations.containsKey(pr)) {
Location location = new Location("");
providerLocations.put(pr, location);
}
}
// add overlays
updateLocationProviderStyles();
mapCircles = new HashMap<String, Circle>();
mapMarkers = new HashMap<String, Marker>();
Log.d(TAG, "Provider location cache: " + providerLocations.keySet().toString());
Layers layers = mapMap.getLayerManager().getLayers();
// remove all layers other than tile render layer from map
for (Layer layer : layers) if (!(layer instanceof TileRendererLayer) && !(layer instanceof TileDownloadLayer)) {
layer.onDestroy();
layers.remove(layer);
}
for (String pr : providers) {
// no invalidator for GPS, which is invalidated through GPS status
if ((!pr.equals(LocationManager.GPS_PROVIDER)) && (providerInvalidators.get(pr)) == null) {
final String provider = pr;
final Context ctx = context;
providerInvalidators.put(pr, new Runnable() {
private String mProvider = provider;
@Override
public void run() {
Location location = providerLocations.get(mProvider);
if (location != null)
markLocationAsStale(location);
applyLocationProviderStyle(ctx, mProvider, Const.LOCATION_PROVIDER_GRAY);
}
});
}
String styleName = assignLocationProviderStyle(pr);
LatLong latLong;
float acc;
boolean visible;
if ((providerLocations.get(pr) != null) && (providerLocations.get(pr).getProvider() != "")) {
latLong = new LatLong(providerLocations.get(pr).getLatitude(), providerLocations.get(pr).getLongitude());
if (providerLocations.get(pr).hasAccuracy())
acc = providerLocations.get(pr).getAccuracy();
else
acc = 0;
visible = true;
if (isLocationStale(providerLocations.get(pr)))
styleName = Const.LOCATION_PROVIDER_GRAY;
Log.d("MainActivity", pr + " has " + latLong.toString());
} else {
latLong = new LatLong(0, 0);
acc = 0;
visible = false;
Log.d("MainActivity", pr + " has no location, hiding");
}
// Circle layer
Resources res = context.getResources();
TypedArray style = res.obtainTypedArray(res.getIdentifier(styleName, "array", context.getPackageName()));
Paint fill = AndroidGraphicFactory.INSTANCE.createPaint();
float density = context.getResources().getDisplayMetrics().density;
fill.setColor(style.getColor(Const.STYLE_FILL, R.color.circle_gray_fill));
fill.setStyle(Style.FILL);
Paint stroke = AndroidGraphicFactory.INSTANCE.createPaint();
stroke.setColor(style.getColor(Const.STYLE_STROKE, R.color.circle_gray_stroke));
stroke.setStrokeWidth(Math.max(1.5f * density, 1));
stroke.setStyle(Style.STROKE);
Circle circle = new Circle(latLong, acc, fill, stroke);
mapCircles.put(pr, circle);
layers.add(circle);
circle.setVisible(visible);
// Marker layer
Drawable drawable = style.getDrawable(Const.STYLE_MARKER);
Bitmap bitmap = AndroidGraphicFactory.convertToBitmap(drawable);
Marker marker = new Marker(latLong, bitmap, 0, -bitmap.getHeight() * 10 / 24);
mapMarkers.put(pr, marker);
layers.add(marker);
marker.setVisible(visible);
style.recycle();
}
// move layers into view
updateMap();
}
Aggregations