use of net.osmand.osm.PoiType in project Osmand by osmandapp.
the class SendPoiDialogFragment method createDefaultChangeSet.
private String createDefaultChangeSet() {
Map<String, PoiType> allTranslatedSubTypes = getMyApplication().getPoiTypes().getAllTranslatedNames(true);
if (allTranslatedSubTypes == null) {
return "";
}
Map<String, Integer> addGroup = new HashMap<>();
Map<String, Integer> editGroup = new HashMap<>();
Map<String, Integer> deleteGroup = new HashMap<>();
Map<String, Integer> reopenGroup = new HashMap<>();
String comment = "";
for (OsmPoint p : poi) {
if (p.getGroup() == OsmPoint.Group.POI) {
OsmPoint.Action action = p.getAction();
String type = ((OpenstreetmapPoint) p).getEntity().getTag(EditPoiData.POI_TYPE_TAG);
if (type == null) {
continue;
}
PoiType localizedPoiType = allTranslatedSubTypes.get(type.toLowerCase().trim());
if (localizedPoiType != null) {
type = Algorithms.capitalizeFirstLetter(localizedPoiType.getKeyName().replace('_', ' '));
}
if (action == OsmPoint.Action.CREATE) {
if (!addGroup.containsKey(type)) {
addGroup.put(type, 1);
} else {
addGroup.put(type, addGroup.get(type) + 1);
}
} else if (action == OsmPoint.Action.MODIFY) {
if (!editGroup.containsKey(type)) {
editGroup.put(type, 1);
} else {
editGroup.put(type, editGroup.get(type) + 1);
}
} else if (action == OsmPoint.Action.DELETE) {
if (!deleteGroup.containsKey(type)) {
deleteGroup.put(type, 1);
} else {
deleteGroup.put(type, deleteGroup.get(type) + 1);
}
} else if (action == OsmPoint.Action.REOPEN) {
if (!reopenGroup.containsKey(type)) {
reopenGroup.put(type, 1);
} else {
reopenGroup.put(type, reopenGroup.get(type) + 1);
}
}
}
}
int modifiedItemsOutOfLimit = 0;
for (int i = 0; i < 4; i++) {
String action;
Map<String, Integer> group;
switch(i) {
case 0:
action = getString(R.string.default_changeset_add);
group = addGroup;
break;
case 1:
action = getString(R.string.default_changeset_edit);
group = editGroup;
break;
case 2:
action = getString(R.string.default_changeset_delete);
group = deleteGroup;
break;
case 3:
action = getString(R.string.default_changeset_reopen);
group = reopenGroup;
break;
default:
action = "";
group = new HashMap<>();
}
if (!group.isEmpty()) {
int pos = 0;
for (Map.Entry<String, Integer> entry : group.entrySet()) {
String type = entry.getKey();
int quantity = entry.getValue();
if (comment.length() > 200) {
modifiedItemsOutOfLimit += quantity;
} else {
if (pos == 0) {
comment = comment.concat(comment.length() == 0 ? "" : "; ").concat(action).concat(" ").concat(quantity == 1 ? "" : quantity + " ").concat(type);
} else {
comment = comment.concat(", ").concat(quantity == 1 ? "" : quantity + " ").concat(type);
}
}
pos++;
}
}
}
if (modifiedItemsOutOfLimit != 0) {
comment = comment.concat("; ").concat(modifiedItemsOutOfLimit + " ").concat(getString(R.string.items_modified)).concat(".");
} else if (!comment.equals("")) {
comment = comment.concat(".");
}
return comment;
}
use of net.osmand.osm.PoiType in project Osmand by osmandapp.
the class OsmEditsAdapter method getIcon.
private Drawable getIcon(OsmPoint point) {
if (point.getGroup() == OsmPoint.Group.POI) {
OpenstreetmapPoint osmPoint = (OpenstreetmapPoint) point;
int iconResId = 0;
String poiTranslation = osmPoint.getEntity().getTag(EditPoiData.POI_TYPE_TAG);
if (poiTranslation != null) {
Map<String, PoiType> poiTypeMap = app.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;
}
int colorResId = R.color.color_distance;
if (point.getAction() == OsmPoint.Action.CREATE) {
colorResId = R.color.color_osm_edit_create;
} else if (point.getAction() == OsmPoint.Action.MODIFY) {
colorResId = R.color.color_osm_edit_modify;
} else if (point.getAction() == OsmPoint.Action.DELETE) {
colorResId = R.color.color_osm_edit_delete;
} else if (point.getAction() == OsmPoint.Action.REOPEN) {
colorResId = R.color.color_osm_edit_modify;
}
return app.getIconsCache().getIcon(iconResId, colorResId);
} else if (point.getGroup() == OsmPoint.Group.BUG) {
return app.getIconsCache().getIcon(R.drawable.ic_type_bug, R.color.color_distance);
}
return null;
}
use of net.osmand.osm.PoiType in project Osmand by osmandapp.
the class AmenityMenuController method getTypeStr.
public static String getTypeStr(Amenity amenity) {
PoiCategory pc = amenity.getType();
PoiType pt = pc.getPoiTypeByKeyName(amenity.getSubType());
String typeStr = amenity.getSubType();
if (pt != null) {
typeStr = pt.getTranslation();
} else if (typeStr != null) {
typeStr = Algorithms.capitalizeFirstLetterAndLowercase(typeStr.replace('_', ' '));
}
return typeStr;
}
use of net.osmand.osm.PoiType in project Osmand by osmandapp.
the class QuickSearchListItem method getTypeName.
public static String getTypeName(SampleApplication app, SearchResult searchResult) {
switch(searchResult.objectType) {
case CITY:
City city = (City) searchResult.object;
return getCityTypeStr(app, city.getType());
case POSTCODE:
return app.getString("postcode");
case VILLAGE:
city = (City) searchResult.object;
if (!Algorithms.isEmpty(searchResult.localeRelatedObjectName)) {
if (searchResult.distRelatedObjectName > 0) {
return getCityTypeStr(app, city.getType()) + " • " + SampleFormatter.getFormattedDistance((float) searchResult.distRelatedObjectName, app) + " " + app.getString("shared_string_from") + " " + searchResult.localeRelatedObjectName;
} else {
return getCityTypeStr(app, city.getType()) + ", " + searchResult.localeRelatedObjectName;
}
} else {
return getCityTypeStr(app, city.getType());
}
case STREET:
StringBuilder streetBuilder = new StringBuilder();
if (searchResult.localeName.endsWith(")")) {
int i = searchResult.localeName.indexOf('(');
if (i > 0) {
streetBuilder.append(searchResult.localeName.substring(i + 1, searchResult.localeName.length() - 1));
}
}
if (!Algorithms.isEmpty(searchResult.localeRelatedObjectName)) {
if (streetBuilder.length() > 0) {
streetBuilder.append(", ");
}
streetBuilder.append(searchResult.localeRelatedObjectName);
}
return streetBuilder.toString();
case HOUSE:
if (searchResult.relatedObject != null) {
Street relatedStreet = (Street) searchResult.relatedObject;
if (relatedStreet.getCity() != null) {
return searchResult.localeRelatedObjectName + ", " + relatedStreet.getCity().getName(searchResult.requiredSearchPhrase.getSettings().getLang(), true);
} else {
return searchResult.localeRelatedObjectName;
}
}
return "";
case STREET_INTERSECTION:
Street street = (Street) searchResult.object;
if (street.getCity() != null) {
return street.getCity().getName(searchResult.requiredSearchPhrase.getSettings().getLang(), true);
}
return "";
case POI_TYPE:
String res = "";
if (searchResult.object instanceof AbstractPoiType) {
AbstractPoiType abstractPoiType = (AbstractPoiType) searchResult.object;
if (abstractPoiType instanceof PoiCategory) {
res = "";
} else if (abstractPoiType instanceof PoiFilter) {
PoiFilter poiFilter = (PoiFilter) abstractPoiType;
res = poiFilter.getPoiCategory() != null ? poiFilter.getPoiCategory().getTranslation() : "";
} else if (abstractPoiType instanceof PoiType) {
PoiType poiType = (PoiType) abstractPoiType;
res = poiType.getParentType() != null ? poiType.getParentType().getTranslation() : null;
if (res == null) {
res = poiType.getCategory() != null ? poiType.getCategory().getTranslation() : null;
}
if (res == null) {
res = "";
}
} else {
res = "";
}
} else if (searchResult.object instanceof CustomSearchPoiFilter) {
res = ((CustomSearchPoiFilter) searchResult.object).getName();
}
return res;
case POI:
Amenity amenity = (Amenity) searchResult.object;
PoiCategory pc = amenity.getType();
PoiType pt = pc.getPoiTypeByKeyName(amenity.getSubType());
String typeStr = amenity.getSubType();
if (pt != null) {
typeStr = pt.getTranslation();
} else if (typeStr != null) {
typeStr = Algorithms.capitalizeFirstLetterAndLowercase(typeStr.replace('_', ' '));
}
return typeStr;
case LOCATION:
LatLon latLon = searchResult.location;
if (searchResult.localeRelatedObjectName == null) {
String locationCountry = app.getRegions().getCountryName(latLon);
searchResult.localeRelatedObjectName = locationCountry == null ? "" : locationCountry;
}
return searchResult.localeRelatedObjectName;
case REGION:
BinaryMapIndexReader binaryMapIndexReader = (BinaryMapIndexReader) searchResult.object;
System.out.println(binaryMapIndexReader.getFile().getAbsolutePath() + " " + binaryMapIndexReader.getCountryName());
break;
case UNKNOWN_NAME_FILTER:
break;
}
return searchResult.objectType.name();
}
use of net.osmand.osm.PoiType in project OsmAnd-tools by osmandapp.
the class IndexPoiCreator method iterateEntity.
public void iterateEntity(Entity e, OsmDbAccessorContext ctx, boolean basemap) throws SQLException {
tempAmenityList.clear();
tagsTransform.addPropogatedTags(e);
Map<String, String> tags = e.getTags();
Map<String, String> etags = renderingTypes.transformTags(tags, EntityType.valueOf(e), EntityConvertApplyType.POI);
boolean privateReg = "private".equals(e.getTag("access"));
tempAmenityList = EntityParser.parseAmenities(poiTypes, e, etags, tempAmenityList);
if (!tempAmenityList.isEmpty() && poiPreparedStatement != null) {
if (e instanceof Relation) {
ctx.loadEntityRelation((Relation) e);
}
boolean first = true;
long id = e.getId();
if (basemap) {
id = GENERATE_OBJ_ID--;
} else if (e instanceof Relation) {
// id = GENERATE_OBJ_ID--;
id = assignIdForMultipolygon((Relation) e);
} else if (id > 0) {
// keep backward compatibility for ids (osm editing)
id = e.getId() >> (OsmDbCreator.SHIFT_ID - 1);
if (id % 2 != (e.getId() % 2)) {
id ^= 1;
}
}
for (Amenity a : tempAmenityList) {
if (a.getType().getKeyName().equals("entertainment") && privateReg) {
// don't index private swimming pools
continue;
}
if (basemap) {
PoiType st = a.getType().getPoiTypeByKeyName(a.getSubType());
if (st == null || !a.getType().containsBasemapPoi(st)) {
continue;
}
}
// do not add that check because it is too much printing for batch creation
// by statistic < 1% creates maps manually
// checkEntity(e);
EntityParser.parseMapObject(a, e, etags);
a.setId(id);
if (a.getLocation() != null) {
// convertEnglishName(a);
if (overwriteIds && first) {
if (!ids.add(a.getId())) {
poiPreparedStatement.executeBatch();
poiDeleteStatement.setString(1, a.getId() + "");
poiDeleteStatement.execute();
first = false;
}
}
insertAmenityIntoPoi(a);
}
}
}
}
Aggregations