Search in sources :

Example 26 with PoiType

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;
}
Also used : OsmPoint(net.osmand.plus.osmedit.OsmPoint) HashMap(java.util.HashMap) PoiType(net.osmand.osm.PoiType) HashMap(java.util.HashMap) Map(java.util.Map) OpenstreetmapPoint(net.osmand.plus.osmedit.OpenstreetmapPoint) OsmPoint(net.osmand.plus.osmedit.OsmPoint)

Example 27 with PoiType

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;
}
Also used : PoiType(net.osmand.osm.PoiType) SpannableString(android.text.SpannableString)

Example 28 with PoiType

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;
}
Also used : PoiCategory(net.osmand.osm.PoiCategory) PoiType(net.osmand.osm.PoiType)

Example 29 with PoiType

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();
}
Also used : Amenity(net.osmand.data.Amenity) PoiFilter(net.osmand.osm.PoiFilter) CustomSearchPoiFilter(net.osmand.search.core.CustomSearchPoiFilter) AbstractPoiType(net.osmand.osm.AbstractPoiType) PoiType(net.osmand.osm.PoiType) BinaryMapIndexReader(net.osmand.binary.BinaryMapIndexReader) City(net.osmand.data.City) AbstractPoiType(net.osmand.osm.AbstractPoiType) LatLon(net.osmand.data.LatLon) PoiCategory(net.osmand.osm.PoiCategory) Street(net.osmand.data.Street) CustomSearchPoiFilter(net.osmand.search.core.CustomSearchPoiFilter)

Example 30 with PoiType

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);
            }
        }
    }
}
Also used : Amenity(net.osmand.data.Amenity) Relation(net.osmand.osm.edit.Relation) PoiType(net.osmand.osm.PoiType)

Aggregations

PoiType (net.osmand.osm.PoiType)49 AbstractPoiType (net.osmand.osm.AbstractPoiType)30 PoiCategory (net.osmand.osm.PoiCategory)11 MapPoiTypes (net.osmand.osm.MapPoiTypes)10 View (android.view.View)8 TextView (android.widget.TextView)8 Map (java.util.Map)8 Amenity (net.osmand.data.Amenity)8 ArrayList (java.util.ArrayList)7 LinkedHashMap (java.util.LinkedHashMap)7 AdapterView (android.widget.AdapterView)5 HashMap (java.util.HashMap)5 List (java.util.List)5 OsmandApplication (net.osmand.plus.OsmandApplication)5 PoiUIFilter (net.osmand.plus.poi.PoiUIFilter)5 AutoCompleteTextView (android.widget.AutoCompleteTextView)4 LinkedHashSet (java.util.LinkedHashSet)4 LatLon (net.osmand.data.LatLon)4 PoiFilter (net.osmand.osm.PoiFilter)4 Node (net.osmand.osm.edit.Node)4