use of org.mapsforge.core.model.Point 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.Point 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.Point in project RSAndroidApp by RailwayStations.
the class MapsActivity method getMarkerBitmap.
private List<MarkerBitmap> getMarkerBitmap() {
final List<MarkerBitmap> markerBitmaps = new ArrayList<>();
// prepare for marker icons.
// small icon for maximum single item
final Bitmap bitmapWithPhoto = loadBitmap(R.drawable.marker_green);
final Bitmap markerWithoutPhoto = loadBitmap(R.drawable.marker_red);
final Bitmap markerOwnPhoto = loadBitmap(R.drawable.marker_violet);
final Bitmap markerPendingUpload = loadBitmap(R.drawable.marker_yellow);
final Bitmap markerWithPhotoInactive = loadBitmap(R.drawable.marker_green_inactive);
final Bitmap markerWithoutPhotoInactive = loadBitmap(R.drawable.marker_red_inactive);
final Bitmap markerOwnPhotoInactive = loadBitmap(R.drawable.marker_violet_inactive);
final Paint paint1 = AndroidGraphicFactory.INSTANCE.createPaint();
paint1.setStyle(Style.FILL);
paint1.setTextAlign(Align.CENTER);
FontFamily fontFamily = FontFamily.DEFAULT;
FontStyle fontStyle = FontStyle.BOLD;
paint1.setTypeface(fontFamily, fontStyle);
paint1.setColor(Color.RED);
markerBitmaps.add(new MarkerBitmap(this.getApplicationContext(), markerWithoutPhoto, bitmapWithPhoto, markerOwnPhoto, markerWithoutPhotoInactive, markerWithPhotoInactive, markerOwnPhotoInactive, markerPendingUpload, new Point(0, -(markerWithoutPhoto.getHeight() / 2.0)), 10f, 1, paint1));
// small cluster icon. for 10 or less items.
final Bitmap bitmapBalloonSN = loadBitmap(R.drawable.balloon_s_n);
final Paint paint2 = AndroidGraphicFactory.INSTANCE.createPaint();
paint2.setStyle(Style.FILL);
paint2.setTextAlign(Align.CENTER);
fontFamily = FontFamily.DEFAULT;
fontStyle = FontStyle.BOLD;
paint2.setTypeface(fontFamily, fontStyle);
paint2.setColor(Color.BLACK);
markerBitmaps.add(new MarkerBitmap(this.getApplicationContext(), bitmapBalloonSN, new Point(0, 0), 9f, 10, paint2));
// large cluster icon. 100 will be ignored.
final Bitmap bitmapBalloonMN = loadBitmap(R.drawable.balloon_m_n);
final Paint paint3 = AndroidGraphicFactory.INSTANCE.createPaint();
paint3.setStyle(Style.FILL);
paint3.setTextAlign(Align.CENTER);
fontFamily = FontFamily.DEFAULT;
fontStyle = FontStyle.BOLD;
paint3.setTypeface(fontFamily, fontStyle);
paint3.setColor(Color.BLACK);
markerBitmaps.add(new MarkerBitmap(this.getApplicationContext(), bitmapBalloonMN, new Point(0, 0), 11f, 100, paint3));
return markerBitmaps;
}
use of org.mapsforge.core.model.Point in project RSAndroidApp by RailwayStations.
the class ClusterMarker method draw.
@Override
public synchronized void draw(final BoundingBox boundingBox, final byte zoomLevel, final org.mapsforge.core.graphics.Canvas canvas, final Point topLeftPoint) {
if (cluster.getClusterManager() == null || this.getLatLong() == null) {
return;
}
setMarkerBitmap();
final long mapSize = MercatorProjection.getMapSize(zoomLevel, this.displayModel.getTileSize());
final double pixelX = MercatorProjection.longitudeToPixelX(this.getLatLong().longitude, mapSize);
final double pixelY = MercatorProjection.latitudeToPixelY(this.getLatLong().latitude, mapSize);
final double halfBitmapWidth;
final double halfBitmapHeight;
final var markerBitmap = cluster.getClusterManager().markerIconBmps.get(markerType);
final var bitmap = markerBitmap.getBitmap(hasPhoto(), ownPhoto(), stationActive(), isPendingUpload());
try {
halfBitmapWidth = bitmap.getWidth() / 2f;
halfBitmapHeight = bitmap.getHeight() / 2f;
} catch (final NullPointerException e) {
Log.e(ClusterMarker.TAG, e.getMessage(), e);
return;
}
final int left = (int) (pixelX - topLeftPoint.x - halfBitmapWidth + markerBitmap.getIconOffset().x);
final int top = (int) (pixelY - topLeftPoint.y - halfBitmapHeight + markerBitmap.getIconOffset().y);
final int right = (left + bitmap.getWidth());
final int bottom = (top + bitmap.getHeight());
final var bitmapRectangle = new Rectangle(left, top, right, bottom);
final var canvasRectangle = new Rectangle(0, 0, canvas.getWidth(), canvas.getHeight());
if (!canvasRectangle.intersects(bitmapRectangle)) {
return;
}
// Draw bitmap
canvas.drawBitmap(bitmap, left, top);
// Draw Text
if (markerType == 0) {
// Draw bitmap
final var bubble = MarkerBitmap.getBitmapFromTitle(cluster.getTitle(), markerBitmap.getPaint());
canvas.drawBitmap(bubble, (int) (left + halfBitmapWidth - bubble.getWidth() / 2), (top - bubble.getHeight()));
} else {
final int x = (int) (left + bitmap.getWidth() * 1.3);
final int y = (int) (top + bitmap.getHeight() * 1.3 + markerBitmap.getPaint().getTextHeight(cluster.getTitle()) / 2);
canvas.drawText(cluster.getTitle(), x, y, markerBitmap.getPaint());
}
}
use of org.mapsforge.core.model.Point in project satstat by mvglasow.
the class MapSectionFragment method updateMap.
/**
* Updates the map view so that all markers are visible.
*/
public void updateMap() {
boolean needsRedraw = false;
Dimension dimension = mapMap.getModel().mapViewDimension.getDimension();
// just trigger a redraw if we're not going to pan or zoom
if ((dimension == null) || (!isMapViewAttached)) {
mapMap.getLayerManager().redrawLayers();
return;
}
// move locations into view and zoom out as needed
int tileSize = mapMap.getModel().displayModel.getTileSize();
BoundingBox bb = null;
BoundingBox bb2 = null;
for (Location l : providerLocations.values()) if ((l != null) && (l.getProvider() != "")) {
double lat = l.getLatitude();
double lon = l.getLongitude();
double yRadius = l.hasAccuracy() ? ((l.getAccuracy() * 360.0f) / Const.EARTH_CIRCUMFERENCE) : 0;
double xRadius = l.hasAccuracy() ? (yRadius * Math.abs(Math.cos(lat))) : 0;
double minLon = Math.max(lon - xRadius, -180);
double maxLon = Math.min(lon + xRadius, 180);
double minLat = Math.max(lat - yRadius, -90);
double maxLat = Math.min(lat + yRadius, 90);
if (!isLocationStale(l)) {
// location is up to date, add to main BoundingBox
if (bb != null) {
minLat = Math.min(bb.minLatitude, minLat);
maxLat = Math.max(bb.maxLatitude, maxLat);
minLon = Math.min(bb.minLongitude, minLon);
maxLon = Math.max(bb.maxLongitude, maxLon);
}
bb = new BoundingBox(minLat, minLon, maxLat, maxLon);
} else {
// location is stale, add to stale BoundingBox
if (bb2 != null) {
minLat = Math.min(bb2.minLatitude, minLat);
maxLat = Math.max(bb2.maxLatitude, maxLat);
minLon = Math.min(bb2.minLongitude, minLon);
maxLon = Math.max(bb2.maxLongitude, maxLon);
}
bb2 = new BoundingBox(minLat, minLon, maxLat, maxLon);
}
}
// all locations are stale, center to them
if (bb == null)
bb = bb2;
if (bb == null) {
needsRedraw = true;
} else {
byte newZoom = LatLongUtils.zoomForBounds(dimension, bb, tileSize);
if (newZoom < 0)
newZoom = 0;
if (newZoom < mapMap.getModel().mapViewPosition.getZoomLevel()) {
mapMap.getModel().mapViewPosition.setZoomLevel(newZoom);
} else {
needsRedraw = true;
}
MapViewProjection proj = new MapViewProjection(mapMap);
Point nw = proj.toPixels(new LatLong(bb.maxLatitude, bb.minLongitude));
Point se = proj.toPixels(new LatLong(bb.minLatitude, bb.maxLongitude));
// move only if bb is not entirely visible
if ((nw.x < 0) || (nw.y < 0) || (se.x > dimension.width) || (se.y > dimension.height)) {
mapMap.getModel().mapViewPosition.setCenter(bb.getCenterPoint());
} else {
needsRedraw = true;
}
}
if (needsRedraw)
mapMap.getLayerManager().redrawLayers();
}
Aggregations