use of net.osmand.plus.views.layers.ContextMenuLayer.IContextMenuProvider in project Osmand by osmandapp.
the class MapMultiSelectionMenu method openContextMenu.
public void openContextMenu(@NonNull MenuObject menuObject) {
IContextMenuProvider provider = selectedObjects.remove(menuObject.getObject());
hide();
MapActivity mapActivity = getMapActivity();
if (mapActivity != null) {
ContextMenuLayer contextMenuLayer = mapActivity.getMapLayers().getContextMenuLayer();
contextMenuLayer.showContextMenu(menuObject.getLatLon(), menuObject.getPointDescription(), menuObject.getObject(), provider);
}
}
use of net.osmand.plus.views.layers.ContextMenuLayer.IContextMenuProvider in project Osmand by osmandapp.
the class MapMultiSelectionMenu method createCollection.
private void createCollection(Map<Object, IContextMenuProvider> selectedObjects) {
this.selectedObjects.clear();
this.selectedObjects.putAll(selectedObjects);
objects.clear();
for (Map.Entry<Object, IContextMenuProvider> e : selectedObjects.entrySet()) {
Object selectedObj = e.getKey();
IContextMenuProvider contextObject = e.getValue();
LatLon ll = null;
PointDescription pointDescription = null;
if (contextObject != null) {
ll = contextObject.getObjectLocation(selectedObj);
pointDescription = contextObject.getObjectName(selectedObj);
}
if (ll == null) {
ll = latLon;
}
if (pointDescription == null) {
pointDescription = new PointDescription(latLon.getLatitude(), latLon.getLongitude());
}
MenuObject menuObject = new MenuObject(ll, pointDescription, selectedObj, getMapActivity());
objects.add(menuObject);
if (contextObject instanceof ContextMenuLayer.IContextMenuProviderSelection) {
menuObject.order = ((ContextMenuLayer.IContextMenuProviderSelection) contextObject).getOrder(selectedObj);
}
}
Collections.sort(objects, new Comparator<MenuObject>() {
@Override
public int compare(MenuObject obj1, MenuObject obj2) {
if (obj1.order == obj2.order) {
return obj1.getTitleStr().compareToIgnoreCase(obj2.getTitleStr());
} else {
return obj1.order - obj2.order;
}
}
});
}
use of net.osmand.plus.views.layers.ContextMenuLayer.IContextMenuProvider in project Osmand by osmandapp.
the class MapRouteInfoMenu method getObjectLocation.
private Pair<LatLon, PointDescription> getObjectLocation(OsmandMapTileView mapView, PointF point, RotatedTileBox tileBox) {
List<Object> objects = new ArrayList<>();
for (OsmandMapLayer layer : mapView.getLayers()) {
if (layer instanceof IContextMenuProvider) {
objects.clear();
IContextMenuProvider provider = (IContextMenuProvider) layer;
provider.collectObjectsFromPoint(point, tileBox, objects, true);
for (Object o : objects) {
if (provider.isObjectClickable(o)) {
LatLon latLon = provider.getObjectLocation(o);
PointDescription name = null;
if (o instanceof FavouritePoint) {
name = ((FavouritePoint) o).getPointDescription(mapView.getApplication());
}
return new Pair<>(latLon, name);
}
}
}
}
return null;
}
Aggregations