Search in sources :

Example 1 with Marker

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));
}
Also used : Bundle(android.os.Bundle) PackageManager(android.content.pm.PackageManager) NonNull(androidx.annotation.NonNull) StationFilter(de.bahnhoefe.deutschlands.bahnhofsfotos.util.StationFilter) Uri(android.net.Uri) WindowManager(android.view.WindowManager) LocationListener(android.location.LocationListener) Drawable(android.graphics.drawable.Drawable) AppCompatActivity(androidx.appcompat.app.AppCompatActivity) Align(org.mapsforge.core.graphics.Align) GeoItem(de.bahnhoefe.deutschlands.bahnhofsfotos.mapsforge.GeoItem) NONE(android.view.Menu.NONE) Manifest(android.Manifest) CheckBox(android.widget.CheckBox) Map(java.util.Map) AndroidGraphicFactory(org.mapsforge.map.android.graphics.AndroidGraphicFactory) TileRendererLayer(org.mapsforge.map.layer.renderer.TileRendererLayer) View(android.view.View) IMapViewPosition(org.mapsforge.map.model.IMapViewPosition) ContextCompat(androidx.core.content.ContextCompat) Log(android.util.Log) Station(de.bahnhoefe.deutschlands.bahnhofsfotos.model.Station) MapFile(org.mapsforge.map.reader.MapFile) DbAdapter(de.bahnhoefe.deutschlands.bahnhofsfotos.db.DbAdapter) Layer(org.mapsforge.map.layer.Layer) SubMenu(android.view.SubMenu) MapPosition(org.mapsforge.core.model.MapPosition) XmlRenderTheme(org.mapsforge.map.rendertheme.XmlRenderTheme) FileNotFoundException(java.io.FileNotFoundException) MapZoomControls(org.mapsforge.map.android.input.MapZoomControls) AbstractTileSource(org.mapsforge.map.layer.download.tilesource.AbstractTileSource) List(java.util.List) DocumentFile(androidx.documentfile.provider.DocumentFile) Marker(org.mapsforge.map.layer.overlay.Marker) ActivityResultContracts(androidx.activity.result.contract.ActivityResultContracts) TileCache(org.mapsforge.map.layer.cache.TileCache) Location(android.location.Location) LocationManager(android.location.LocationManager) Window(android.view.Window) Context(android.content.Context) ResourcesCompat(androidx.core.content.res.ResourcesCompat) Intent(android.content.Intent) FontStyle(org.mapsforge.core.graphics.FontStyle) HashMap(java.util.HashMap) TapHandler(de.bahnhoefe.deutschlands.bahnhofsfotos.mapsforge.TapHandler) Point(org.mapsforge.core.model.Point) MenuItem(android.view.MenuItem) ArrayList(java.util.ArrayList) VibrationEffect(android.os.VibrationEffect) Bitmap(org.mapsforge.core.graphics.Bitmap) InternalRenderTheme(org.mapsforge.map.rendertheme.InternalRenderTheme) Toast(android.widget.Toast) FontFamily(org.mapsforge.core.graphics.FontFamily) Menu(android.view.Menu) StreamRenderTheme(org.mapsforge.map.rendertheme.StreamRenderTheme) DbsTileSource(de.bahnhoefe.deutschlands.bahnhofsfotos.mapsforge.DbsTileSource) MarkerBitmap(de.bahnhoefe.deutschlands.bahnhofsfotos.mapsforge.MarkerBitmap) WeakReference(java.lang.ref.WeakReference) AndroidUtil(org.mapsforge.map.android.util.AndroidUtil) OnlineTileSource(org.mapsforge.map.layer.download.tilesource.OnlineTileSource) ActivityResultLauncher(androidx.activity.result.ActivityResultLauncher) ActivityCompat(androidx.core.app.ActivityCompat) TileDownloadLayer(org.mapsforge.map.layer.download.TileDownloadLayer) FileInputStream(java.io.FileInputStream) StationFilterBar(de.bahnhoefe.deutschlands.bahnhofsfotos.dialogs.StationFilterBar) LatLong(org.mapsforge.core.model.LatLong) ActivityMapsBinding(de.bahnhoefe.deutschlands.bahnhofsfotos.databinding.ActivityMapsBinding) MapDataStore(org.mapsforge.map.datastore.MapDataStore) ClusterManager(de.bahnhoefe.deutschlands.bahnhofsfotos.mapsforge.ClusterManager) MapInfoFragment(de.bahnhoefe.deutschlands.bahnhofsfotos.dialogs.MapInfoFragment) Color(android.graphics.Color) Paint(org.mapsforge.core.graphics.Paint) Upload(de.bahnhoefe.deutschlands.bahnhofsfotos.model.Upload) SimpleDialogs(de.bahnhoefe.deutschlands.bahnhofsfotos.dialogs.SimpleDialogs) Vibrator(android.os.Vibrator) Style(org.mapsforge.core.graphics.Style) OpenStreetMapMapnik(org.mapsforge.map.layer.download.tilesource.OpenStreetMapMapnik) Activity(android.app.Activity) Bitmap(org.mapsforge.core.graphics.Bitmap) MarkerBitmap(de.bahnhoefe.deutschlands.bahnhofsfotos.mapsforge.MarkerBitmap) SimpleDialogs(de.bahnhoefe.deutschlands.bahnhofsfotos.dialogs.SimpleDialogs) Drawable(android.graphics.drawable.Drawable) Intent(android.content.Intent) Marker(org.mapsforge.map.layer.overlay.Marker) Point(org.mapsforge.core.model.Point) Vibrator(android.os.Vibrator) LatLong(org.mapsforge.core.model.LatLong)

Example 2 with Marker

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);
    }
}
Also used : Window(android.view.Window) Intent(android.content.Intent) Marker(org.mapsforge.map.layer.overlay.Marker) LatLong(org.mapsforge.core.model.LatLong)

Example 3 with Marker

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();
}
Also used : Circle(org.mapsforge.map.layer.overlay.Circle) Bitmap(org.mapsforge.core.graphics.Bitmap) TypedArray(android.content.res.TypedArray) Drawable(android.graphics.drawable.Drawable) Resources(android.content.res.Resources) Marker(org.mapsforge.map.layer.overlay.Marker) LayerManager(org.mapsforge.map.layer.LayerManager)

Example 4 with Marker

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());
}
Also used : Bitmap(org.mapsforge.core.graphics.Bitmap) MarkerBitmap(de.bahnhoefe.deutschlands.bahnhofsfotos.mapsforge.MarkerBitmap) Drawable(android.graphics.drawable.Drawable) Marker(org.mapsforge.map.layer.overlay.Marker)

Example 5 with Marker

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();
}
Also used : Context(android.content.Context) Circle(org.mapsforge.map.layer.overlay.Circle) TileRendererLayer(org.mapsforge.map.layer.renderer.TileRendererLayer) ArrayList(java.util.ArrayList) TileDownloadLayer(org.mapsforge.map.layer.download.TileDownloadLayer) Drawable(android.graphics.drawable.Drawable) Marker(org.mapsforge.map.layer.overlay.Marker) Paint(org.mapsforge.core.graphics.Paint) TileRendererLayer(org.mapsforge.map.layer.renderer.TileRendererLayer) Layer(org.mapsforge.map.layer.Layer) TileDownloadLayer(org.mapsforge.map.layer.download.TileDownloadLayer) Bitmap(org.mapsforge.core.graphics.Bitmap) TypedArray(android.content.res.TypedArray) Resources(android.content.res.Resources) Layers(org.mapsforge.map.layer.Layers) LatLong(org.mapsforge.core.model.LatLong) Location(android.location.Location)

Aggregations

Marker (org.mapsforge.map.layer.overlay.Marker)6 Drawable (android.graphics.drawable.Drawable)4 Bitmap (org.mapsforge.core.graphics.Bitmap)4 LatLong (org.mapsforge.core.model.LatLong)4 Location (android.location.Location)3 Context (android.content.Context)2 Intent (android.content.Intent)2 Resources (android.content.res.Resources)2 TypedArray (android.content.res.TypedArray)2 Window (android.view.Window)2 Circle (org.mapsforge.map.layer.overlay.Circle)2 Manifest (android.Manifest)1 Activity (android.app.Activity)1 PackageManager (android.content.pm.PackageManager)1 Color (android.graphics.Color)1 LocationListener (android.location.LocationListener)1 LocationManager (android.location.LocationManager)1 Uri (android.net.Uri)1 Bundle (android.os.Bundle)1 VibrationEffect (android.os.VibrationEffect)1