generated from Grigo/AndroidTemplate
Daily checkup
This commit is contained in:
@@ -0,0 +1,103 @@
|
||||
package com.grigowashere.aismap.maps;
|
||||
|
||||
import android.util.Log;
|
||||
|
||||
import org.maplibre.android.camera.CameraPosition;
|
||||
import org.maplibre.android.camera.CameraUpdateFactory;
|
||||
import org.maplibre.android.geometry.LatLng;
|
||||
import org.maplibre.android.maps.MapLibreMap;
|
||||
import org.maplibre.android.maps.MapView;
|
||||
|
||||
/**
|
||||
* Минимальная инициализация MapLibre для режима картплоттера:
|
||||
* только береговые тайлы, без маркеров AIS и без жестов.
|
||||
*/
|
||||
public class RadarMapHelper {
|
||||
|
||||
private static final String TAG = "RadarMapHelper";
|
||||
private static final String STYLE_URL =
|
||||
"https://basemaps.cartocdn.com/gl/positron-gl-style/style.json";
|
||||
|
||||
private final MapView mapView;
|
||||
private MapLibreMap map;
|
||||
private boolean styleLoaded;
|
||||
|
||||
public RadarMapHelper(MapView mapView) {
|
||||
this.mapView = mapView;
|
||||
}
|
||||
|
||||
public void initialize(Runnable onReady) {
|
||||
mapView.getMapAsync(loadedMap -> {
|
||||
map = loadedMap;
|
||||
try {
|
||||
if (map.getUiSettings() != null) {
|
||||
map.getUiSettings().setCompassEnabled(false);
|
||||
map.getUiSettings().setAttributionEnabled(false);
|
||||
map.getUiSettings().setLogoEnabled(false);
|
||||
map.getUiSettings().setRotateGesturesEnabled(false);
|
||||
map.getUiSettings().setScrollGesturesEnabled(false);
|
||||
map.getUiSettings().setZoomGesturesEnabled(false);
|
||||
map.getUiSettings().setTiltGesturesEnabled(false);
|
||||
}
|
||||
} catch (Exception e) {
|
||||
Log.w(TAG, "UI settings: " + e.getMessage());
|
||||
}
|
||||
map.setStyle(STYLE_URL, style -> {
|
||||
styleLoaded = true;
|
||||
if (onReady != null) onReady.run();
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
public void onStart() {
|
||||
mapView.onStart();
|
||||
}
|
||||
|
||||
public void onResume() {
|
||||
mapView.onResume();
|
||||
}
|
||||
|
||||
public void onPause() {
|
||||
mapView.onPause();
|
||||
}
|
||||
|
||||
public void onStop() {
|
||||
mapView.onStop();
|
||||
}
|
||||
|
||||
public void onDestroy() {
|
||||
mapView.onDestroy();
|
||||
}
|
||||
|
||||
public void onSaveInstanceState(android.os.Bundle outState) {
|
||||
mapView.onSaveInstanceState(outState);
|
||||
}
|
||||
|
||||
public void onLowMemory() {
|
||||
mapView.onLowMemory();
|
||||
}
|
||||
|
||||
/**
|
||||
* Центрирует карту на собственном судне; bearing задаёт режим «курс вверх».
|
||||
*
|
||||
* @param rangeMeters радиус PPI для подбора зума
|
||||
*/
|
||||
public void centerOnOwnShip(double lat, double lon, float bearingDeg, double rangeMeters) {
|
||||
if (map == null || !styleLoaded) return;
|
||||
if (Double.isNaN(lat) || Double.isNaN(lon)) return;
|
||||
double zoom = zoomForRangeMeters(rangeMeters);
|
||||
CameraPosition position = new CameraPosition.Builder()
|
||||
.target(new LatLng(lat, lon))
|
||||
.zoom(zoom)
|
||||
.bearing(bearingDeg)
|
||||
.tilt(0.0)
|
||||
.build();
|
||||
map.easeCamera(CameraUpdateFactory.newCameraPosition(position), 400);
|
||||
}
|
||||
|
||||
/** Подбирает зум так, чтобы весь радиус PPI помещался в круговой области. */
|
||||
static double zoomForRangeMeters(double rangeMeters) {
|
||||
double nm = Math.max(0.25, rangeMeters / 1852.0);
|
||||
return 14.8 - Math.log10(nm) * 2.35;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user