use of net.osmand.plus.views.OsmandMapTileView in project Osmand by osmandapp.
the class ContextMenuCardDialog method shiftMapPosition.
private void shiftMapPosition() {
OsmandMapTileView mapView = mapActivity.getMapView();
if (AndroidUiHelper.isOrientationPortrait(mapActivity)) {
if (mapView.getMapPosition() != OsmandSettings.MIDDLE_BOTTOM_CONSTANT) {
prevMapPosition = mapView.getMapPosition();
mapView.setMapPosition(OsmandSettings.MIDDLE_BOTTOM_CONSTANT);
}
} else {
mapView.setMapPositionX(1);
}
}
use of net.osmand.plus.views.OsmandMapTileView in project Osmand by osmandapp.
the class MapillaryPlugin method registerLayerContextMenuActions.
@Override
public void registerLayerContextMenuActions(final OsmandMapTileView mapView, ContextMenuAdapter adapter, final MapActivity mapActivity) {
ContextMenuAdapter.ItemClickListener listener = new ContextMenuAdapter.OnRowItemClick() {
@Override
public boolean onRowItemClick(ArrayAdapter<ContextMenuItem> adapter, View view, int itemId, int position) {
if (itemId == R.string.mapillary) {
mapActivity.getDashboard().setDashboardVisibility(true, DashboardOnMap.DashboardType.MAPILLARY, AndroidUtils.getCenterViewCoordinates(view));
return false;
}
return true;
}
@Override
public boolean onContextMenuClick(final ArrayAdapter<ContextMenuItem> adapter, int itemId, final int pos, boolean isChecked, int[] viewCoordinates) {
final OsmandSettings settings = mapActivity.getMyApplication().getSettings();
if (itemId == R.string.mapillary) {
OsmandMapTileView mapView = mapActivity.getMapView();
MapActivityLayers mapLayers = mapActivity.getMapLayers();
settings.SHOW_MAPILLARY.set(!settings.SHOW_MAPILLARY.get());
updateMapLayers(mapView, mapLayers, false);
ContextMenuItem item = adapter.getItem(pos);
if (item != null) {
item.setSelected(settings.SHOW_MAPILLARY.get());
item.setColorRes(settings.SHOW_MAPILLARY.get() ? R.color.osmand_orange : ContextMenuItem.INVALID_ID);
adapter.notifyDataSetChanged();
}
}
return false;
}
};
if (rasterLayer.getMap() == null) {
settings.SHOW_MAPILLARY.set(false);
}
adapter.addItem(new ContextMenuItem.ItemBuilder().setTitleId(R.string.mapillary, mapActivity).setSelected(settings.SHOW_MAPILLARY.get()).setColor(settings.SHOW_MAPILLARY.get() ? R.color.osmand_orange : ContextMenuItem.INVALID_ID).setIcon(R.drawable.ic_action_mapillary).setSecondaryIcon(R.drawable.ic_action_additional_option).setListener(listener).setPosition(11).createItem());
}
use of net.osmand.plus.views.OsmandMapTileView in project Osmand by osmandapp.
the class PlanRouteFragment method showRouteOnMap.
private void showRouteOnMap(List<WptPt> points) {
MapActivity mapActivity = getMapActivity();
if (points.size() > 0 && mapActivity != null) {
OsmandMapTileView mapView = mapActivity.getMapView();
double left = 0, right = 0;
double top = 0, bottom = 0;
Location myLocation = mapActivity.getMyApplication().getLocationProvider().getLastStaleKnownLocation();
if (mapActivity.getMyApplication().getMapMarkersHelper().isStartFromMyLocation() && myLocation != null) {
left = myLocation.getLongitude();
right = myLocation.getLongitude();
top = myLocation.getLatitude();
bottom = myLocation.getLatitude();
}
for (WptPt pt : points) {
if (left == 0) {
left = pt.getLongitude();
right = pt.getLongitude();
top = pt.getLatitude();
bottom = pt.getLatitude();
} else {
left = Math.min(left, pt.getLongitude());
right = Math.max(right, pt.getLongitude());
top = Math.max(top, pt.getLatitude());
bottom = Math.min(bottom, pt.getLatitude());
}
}
RotatedTileBox tb = mapView.getCurrentRotatedTileBox().copy();
int tileBoxWidthPx = 0;
int tileBoxHeightPx = 0;
if (portrait) {
tileBoxHeightPx = 3 * (tb.getPixHeight() - toolbarHeight) / 4;
} else {
tileBoxWidthPx = tb.getPixWidth() - mapActivity.getResources().getDimensionPixelSize(R.dimen.dashboard_land_width);
}
mapView.fitRectToMap(left, right, top, bottom, tileBoxWidthPx, tileBoxHeightPx, toolbarHeight * 3 / 2);
}
}
use of net.osmand.plus.views.OsmandMapTileView in project Osmand by osmandapp.
the class OsmandAidlApi method registerSetMapLocationReceiver.
private void registerSetMapLocationReceiver(final MapActivity mapActivity) {
setMapLocationReceiver = new BroadcastReceiver() {
@Override
public void onReceive(Context context, Intent intent) {
double lat = intent.getDoubleExtra(AIDL_LATITUDE, Double.NaN);
double lon = intent.getDoubleExtra(AIDL_LONGITUDE, Double.NaN);
int zoom = intent.getIntExtra(AIDL_ZOOM, 0);
boolean animated = intent.getBooleanExtra(AIDL_ANIMATED, false);
if (!Double.isNaN(lat) && !Double.isNaN(lon)) {
OsmandMapTileView mapView = mapActivity.getMapView();
if (zoom == 0) {
zoom = mapView.getZoom();
} else {
zoom = zoom > mapView.getMaxZoom() ? mapView.getMaxZoom() : zoom;
zoom = zoom < mapView.getMinZoom() ? mapView.getMinZoom() : zoom;
}
if (animated) {
mapView.getAnimatedDraggingThread().startMoving(lat, lon, zoom, true);
} else {
mapView.setLatLon(lat, lon);
mapView.setIntZoom(zoom);
}
}
mapActivity.refreshMap();
}
};
mapActivity.registerReceiver(setMapLocationReceiver, new IntentFilter(AIDL_SET_MAP_LOCATION));
}
use of net.osmand.plus.views.OsmandMapTileView in project Osmand by osmandapp.
the class ParkingPositionPlugin method createParkingPlaceInfoControl.
/**
* @return the control to be added on a MapInfoLayer
* that shows a distance between
* the current position on the map
* and the location of the parked car
*/
private TextInfoWidget createParkingPlaceInfoControl(final MapActivity map) {
TextInfoWidget parkingPlaceControl = new TextInfoWidget(map) {
private float[] calculations = new float[1];
private int cachedMeters = 0;
@Override
public boolean updateInfo(DrawSettings drawSettings) {
LatLon parkingPoint = parkingLayer.getParkingPoint();
if (parkingPoint != null && !map.getRoutingHelper().isFollowingMode()) {
OsmandMapTileView view = map.getMapView();
int d = 0;
if (d == 0) {
net.osmand.Location.distanceBetween(view.getLatitude(), view.getLongitude(), parkingPoint.getLatitude(), parkingPoint.getLongitude(), calculations);
d = (int) calculations[0];
}
if (distChanged(cachedMeters, d)) {
cachedMeters = d;
if (cachedMeters <= 20) {
cachedMeters = 0;
setText(null, null);
} else {
String ds = OsmAndFormatter.getFormattedDistance(cachedMeters, map.getMyApplication());
int ls = ds.lastIndexOf(' ');
if (ls == -1) {
setText(ds, null);
} else {
setText(ds.substring(0, ls), ds.substring(ls + 1));
}
}
return true;
}
} else if (cachedMeters != 0) {
cachedMeters = 0;
setText(null, null);
return true;
}
return false;
}
/**
* Utility method.
* @param oldDist
* @param dist
* @return
*/
private boolean distChanged(int oldDist, int dist) {
if (oldDist != 0 && Math.abs(oldDist - dist) < 30) {
return false;
}
return true;
}
};
parkingPlaceControl.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
OsmandMapTileView view = map.getMapView();
AnimateDraggingMapThread thread = view.getAnimatedDraggingThread();
LatLon parkingPoint = parkingPosition;
if (parkingPoint != null) {
int fZoom = view.getZoom() < 15 ? 15 : view.getZoom();
thread.startMoving(parkingPoint.getLatitude(), parkingPoint.getLongitude(), fZoom, true);
}
}
});
parkingPlaceControl.setText(null, null);
parkingPlaceControl.setIcons(R.drawable.widget_parking_day, R.drawable.widget_parking_night);
return parkingPlaceControl;
}
Aggregations