Search in sources :

Example 1 with LatLong

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();
}
Also used : LatLong(org.mapsforge.core.model.LatLong)

Example 2 with LatLong

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));
}
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 3 with LatLong

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());
    }
}
Also used : MapDataStore(org.mapsforge.map.datastore.MapDataStore) TileRendererLayer(org.mapsforge.map.layer.renderer.TileRendererLayer) TileDownloadLayer(org.mapsforge.map.layer.download.TileDownloadLayer) Point(org.mapsforge.core.model.Point) Uri(android.net.Uri) LatLong(org.mapsforge.core.model.LatLong) AbstractTileSource(org.mapsforge.map.layer.download.tilesource.AbstractTileSource)

Example 4 with LatLong

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

Example 5 with LatLong

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();
}
Also used : Station(de.bahnhoefe.deutschlands.bahnhofsfotos.model.Station) LatLong(org.mapsforge.core.model.LatLong)

Aggregations

LatLong (org.mapsforge.core.model.LatLong)12 Location (android.location.Location)6 Point (org.mapsforge.core.model.Point)4 Marker (org.mapsforge.map.layer.overlay.Marker)4 Paint (org.mapsforge.core.graphics.Paint)3 TileDownloadLayer (org.mapsforge.map.layer.download.TileDownloadLayer)3 TileRendererLayer (org.mapsforge.map.layer.renderer.TileRendererLayer)3 Context (android.content.Context)2 Intent (android.content.Intent)2 Drawable (android.graphics.drawable.Drawable)2 Uri (android.net.Uri)2 Bundle (android.os.Bundle)2 View (android.view.View)2 Window (android.view.Window)2 MapDataStore (org.mapsforge.map.datastore.MapDataStore)2 AbstractTileSource (org.mapsforge.map.layer.download.tilesource.AbstractTileSource)2 Circle (org.mapsforge.map.layer.overlay.Circle)2 Manifest (android.Manifest)1 Activity (android.app.Activity)1 SharedPreferences (android.content.SharedPreferences)1