use of net.osmand.osm.PoiType in project Osmand by osmandapp.
the class EditPOIMenuController method getRightIconId.
@Override
public int getRightIconId() {
if (osmPoint.getGroup() == OsmPoint.Group.POI) {
OpenstreetmapPoint osmP = (OpenstreetmapPoint) osmPoint;
int iconResId = 0;
String poiTranslation = osmP.getEntity().getTag(EditPoiData.POI_TYPE_TAG);
if (poiTranslation != null) {
Map<String, PoiType> poiTypeMap = getMapActivity().getMyApplication().getPoiTypes().getAllTranslatedNames(false);
PoiType poiType = poiTypeMap.get(poiTranslation.toLowerCase());
if (poiType != null) {
String id = null;
if (RenderingIcons.containsBigIcon(poiType.getIconKeyName())) {
id = poiType.getIconKeyName();
} else if (RenderingIcons.containsBigIcon(poiType.getOsmTag() + "_" + poiType.getOsmValue())) {
id = poiType.getOsmTag() + "_" + poiType.getOsmValue();
}
if (id != null) {
iconResId = RenderingIcons.getBigIconResourceId(id);
}
}
}
if (iconResId == 0) {
iconResId = R.drawable.ic_type_info;
}
return iconResId;
} else if (osmPoint.getGroup() == OsmPoint.Group.BUG) {
return R.drawable.ic_type_bug;
} else {
return 0;
}
}
use of net.osmand.osm.PoiType in project Osmand by osmandapp.
the class EditPoiData method updateTypeTag.
public void updateTypeTag(String string, boolean userChanges) {
tagValues.put(POI_TYPE_TAG, string);
if (userChanges) {
changedTags.add(POI_TYPE_TAG);
}
retrieveType();
PoiType pt = getPoiTypeDefined();
if (pt != null) {
tagValues.put(REMOVE_TAG_PREFIX + pt.getOsmTag(), REMOVE_TAG_VALUE);
tagValues.put(REMOVE_TAG_PREFIX + pt.getOsmTag2(), REMOVE_TAG_VALUE);
tagValues.remove(pt.getOsmTag());
tagValues.remove(pt.getOsmTag2());
changedTags.removeAll(Arrays.asList(pt.getOsmTag(), pt.getOsmTag2()));
category = pt.getCategory();
}
notifyDatasetChanged(POI_TYPE_TAG);
}
use of net.osmand.osm.PoiType in project Osmand by osmandapp.
the class EditPoiDialogFragment method save.
private void save() {
Node original = editPoiData.getEntity();
final boolean offlineEdit = mOpenstreetmapUtil instanceof OpenstreetmapLocalUtil;
Node node = new Node(original.getLatitude(), original.getLongitude(), original.getId());
Action action = node.getId() < 0 ? Action.CREATE : Action.MODIFY;
for (Map.Entry<String, String> tag : editPoiData.getTagValues().entrySet()) {
if (!Algorithms.isEmpty(tag.getKey()) && !Algorithms.isEmpty(tag.getValue()) && !tag.getKey().equals(EditPoiData.POI_TYPE_TAG)) {
node.putTagNoLC(tag.getKey(), tag.getValue());
}
}
String poiTypeTag = editPoiData.getTagValues().get(EditPoiData.POI_TYPE_TAG);
String comment = "";
if (poiTypeTag != null) {
final PoiType poiType = editPoiData.getAllTranslatedSubTypes().get(poiTypeTag.trim().toLowerCase());
if (poiType != null) {
node.putTagNoLC(poiType.getOsmTag(), poiType.getOsmValue());
node.removeTag(EditPoiData.REMOVE_TAG_PREFIX + poiType.getOsmTag());
if (poiType.getOsmTag2() != null) {
node.putTagNoLC(poiType.getOsmTag2(), poiType.getOsmValue2());
node.removeTag(EditPoiData.REMOVE_TAG_PREFIX + poiType.getOsmTag2());
}
} else if (!Algorithms.isEmpty(poiTypeTag)) {
node.putTagNoLC(editPoiData.getPoiCategory().getDefaultTag(), poiTypeTag);
}
if (offlineEdit && !Algorithms.isEmpty(poiTypeTag)) {
node.putTagNoLC(EditPoiData.POI_TYPE_TAG, poiTypeTag);
}
String actionString = action == Action.CREATE ? getString(R.string.default_changeset_add) : getString(R.string.default_changeset_edit);
comment = actionString + " " + poiTypeTag;
}
commitNode(action, node, mOpenstreetmapUtil.getEntityInfo(node.getId()), comment, false, new CallbackWithObject<Node>() {
@Override
public boolean processResult(Node result) {
if (result != null) {
OsmEditingPlugin plugin = OsmandPlugin.getPlugin(OsmEditingPlugin.class);
if (plugin != null && offlineEdit) {
List<OpenstreetmapPoint> points = plugin.getDBPOI().getOpenstreetmapPoints();
if (getActivity() instanceof MapActivity && points.size() > 0) {
OsmPoint point = points.get(points.size() - 1);
MapActivity mapActivity = (MapActivity) getActivity();
mapActivity.getContextMenu().showOrUpdate(new LatLon(point.getLatitude(), point.getLongitude()), plugin.getOsmEditsLayer(mapActivity).getObjectName(point), point);
}
}
if (getActivity() instanceof MapActivity) {
((MapActivity) getActivity()).getMapView().refreshMap(true);
}
dismiss();
} else {
OsmEditingPlugin plugin = OsmandPlugin.getPlugin(OsmEditingPlugin.class);
mOpenstreetmapUtil = plugin.getPoiModificationLocalUtil();
Button saveButton = (Button) view.findViewById(R.id.saveButton);
saveButton.setText(mOpenstreetmapUtil instanceof OpenstreetmapRemoteUtil ? R.string.shared_string_upload : R.string.shared_string_save);
}
return false;
}
}, getActivity(), mOpenstreetmapUtil, action == Action.MODIFY ? editPoiData.getChangedTags() : null);
}
use of net.osmand.osm.PoiType in project Osmand by osmandapp.
the class OpenstreetmapLocalUtil method loadNode.
@Override
public Node loadNode(Amenity n) {
PoiType poiType = n.getType().getPoiTypeByKeyName(n.getSubType());
if (n.getId() % 2 == 1 || poiType == null) {
// that's way id
return null;
}
long nodeId = n.getId() >> 1;
// EntityId id = new Entity.EntityId(EntityType.NODE, nodeId);
Node entity = new Node(n.getLocation().getLatitude(), n.getLocation().getLongitude(), nodeId);
entity.putTagNoLC(EditPoiData.POI_TYPE_TAG, poiType.getTranslation());
if (poiType.getOsmTag2() != null) {
entity.putTagNoLC(poiType.getOsmTag2(), poiType.getOsmValue2());
}
if (!Algorithms.isEmpty(n.getName())) {
entity.putTagNoLC(OSMTagKey.NAME.getValue(), n.getName());
}
if (!Algorithms.isEmpty(n.getOpeningHours())) {
entity.putTagNoLC(OSMTagKey.OPENING_HOURS.getValue(), n.getOpeningHours());
}
for (Map.Entry<String, String> entry : n.getAdditionalInfo().entrySet()) {
AbstractPoiType abstractPoi = MapPoiTypes.getDefault().getAnyPoiAdditionalTypeByKey(entry.getKey());
if (abstractPoi != null && abstractPoi instanceof PoiType) {
PoiType p = (PoiType) abstractPoi;
if (!p.isNotEditableOsm() && !Algorithms.isEmpty(p.getOsmTag())) {
entity.putTagNoLC(p.getOsmTag(), entry.getValue());
}
}
}
// check whether this is node (because id of node could be the same as relation)
if (entity != null && MapUtils.getDistance(entity.getLatLon(), n.getLocation()) < 50) {
return entity;
}
return null;
}
use of net.osmand.osm.PoiType in project Osmand by osmandapp.
the class OsmEditingPlugin method registerMapContextMenuActions.
@Override
public void registerMapContextMenuActions(final MapActivity mapActivity, final double latitude, final double longitude, ContextMenuAdapter adapter, final Object selectedObj) {
ContextMenuAdapter.ItemClickListener listener = new ContextMenuAdapter.ItemClickListener() {
@Override
public boolean onContextMenuClick(ArrayAdapter<ContextMenuItem> adapter, int resId, int pos, boolean isChecked, int[] viewCoordinates) {
if (resId == R.string.context_menu_item_create_poi) {
// getPoiActions(mapActivity).showCreateDialog(latitude, longitude);
EditPoiDialogFragment editPoiDialogFragment = EditPoiDialogFragment.createAddPoiInstance(latitude, longitude, mapActivity.getMyApplication());
editPoiDialogFragment.show(mapActivity.getSupportFragmentManager(), EditPoiDialogFragment.TAG);
} else if (resId == R.string.context_menu_item_open_note) {
openOsmNote(mapActivity, latitude, longitude);
} else if (resId == R.string.context_menu_item_modify_note) {
modifyOsmNote(mapActivity, (OsmNotesPoint) selectedObj);
} else if (resId == R.string.poi_context_menu_modify) {
EditPoiDialogFragment.showEditInstance((Amenity) selectedObj, mapActivity);
} else if (resId == R.string.poi_context_menu_modify_osm_change) {
final Node entity = ((OpenstreetmapPoint) selectedObj).getEntity();
EditPoiDialogFragment.createInstance(entity, false).show(mapActivity.getSupportFragmentManager(), EditPoiDialogFragment.TAG);
}
return true;
}
};
boolean isEditable = false;
if (selectedObj instanceof Amenity) {
Amenity amenity = (Amenity) selectedObj;
final PoiType poiType = amenity.getType().getPoiTypeByKeyName(amenity.getSubType());
isEditable = !amenity.getType().isWiki() && poiType != null && !poiType.isNotEditableOsm();
}
if (isEditable) {
adapter.addItem(new ContextMenuItem.ItemBuilder().setTitleId(R.string.poi_context_menu_modify, mapActivity).setIcon(R.drawable.ic_action_edit_dark).setOrder(MODIFY_POI_ITEM_ORDER).setListener(listener).createItem());
} else if (selectedObj instanceof OpenstreetmapPoint && ((OpenstreetmapPoint) selectedObj).getAction() != Action.DELETE) {
adapter.addItem(new ContextMenuItem.ItemBuilder().setTitleId(R.string.poi_context_menu_modify_osm_change, mapActivity).setIcon(R.drawable.ic_action_edit_dark).setOrder(MODIFY_OSM_CHANGE_ITEM_ORDER).setListener(listener).createItem());
} else {
adapter.addItem(new ContextMenuItem.ItemBuilder().setTitleId(R.string.context_menu_item_create_poi, mapActivity).setIcon(R.drawable.ic_action_plus_dark).setOrder(CREATE_POI_ITEM_ORDER).setListener(listener).createItem());
}
if (selectedObj instanceof OsmNotesPoint) {
adapter.addItem(new ContextMenuItem.ItemBuilder().setTitleId(R.string.context_menu_item_modify_note, mapActivity).setIcon(R.drawable.ic_action_edit_dark).setOrder(MODIFY_OSM_NOTE_ITEM_ORDER).setListener(listener).createItem());
} else {
adapter.addItem(new ContextMenuItem.ItemBuilder().setTitleId(R.string.context_menu_item_open_note, mapActivity).setIcon(R.drawable.ic_action_bug_dark).setOrder(OPEN_OSM_NOTE_ITEM_ORDER).setListener(listener).createItem());
}
}
Aggregations