Search in sources :

Example 26 with Amenity

use of net.osmand.data.Amenity 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 27 with Amenity

use of net.osmand.data.Amenity in project Osmand by osmandapp.

the class QuickSearchListItem method getIcon.

public static Drawable getIcon(SampleApplication app, SearchResult searchResult) {
    if (searchResult == null || searchResult.objectType == null) {
        return null;
    }
    int iconId;
    switch(searchResult.objectType) {
        case CITY:
            return app.getIconsCache().getIcon("ic_action_building_number", R.color.osmand_orange);
        case VILLAGE:
            return app.getIconsCache().getIcon("ic_action_home_dark", R.color.osmand_orange);
        case POSTCODE:
        case STREET:
            return app.getIconsCache().getIcon("ic_action_street_name", R.color.osmand_orange);
        case HOUSE:
            return app.getIconsCache().getIcon("ic_action_building", R.color.osmand_orange);
        case STREET_INTERSECTION:
            return app.getIconsCache().getIcon("ic_action_intersection", R.color.osmand_orange);
        case POI_TYPE:
            iconId = getPoiTypeIconId(app, (AbstractPoiType) searchResult.object);
            if (iconId != 0) {
                return app.getIconsCache().getOsmandIcon(iconId, R.color.osmand_orange);
            } else {
                return null;
            }
        case POI:
            Amenity amenity = (Amenity) searchResult.object;
            iconId = getAmenityIconId(amenity);
            if (iconId != 0) {
                return app.getIconsCache().getOsmandIcon(iconId, R.color.osmand_orange);
            } else {
                return null;
            }
        case LOCATION:
            return app.getIconsCache().getIcon("ic_action_world_globe", R.color.osmand_orange);
        case REGION:
            return app.getIconsCache().getIcon("ic_world_globe_dark", R.color.osmand_orange);
        case UNKNOWN_NAME_FILTER:
            break;
    }
    return null;
}
Also used : Amenity(net.osmand.data.Amenity) AbstractPoiType(net.osmand.osm.AbstractPoiType)

Example 28 with Amenity

use of net.osmand.data.Amenity in project Osmand by osmandapp.

the class QuickSearchListFragment method showOnMap.

private void showOnMap(SearchResult searchResult) {
    if (searchResult.location != null) {
        SampleApplication app = getMyApplication();
        String lang = searchResult.requiredSearchPhrase.getSettings().getLang();
        boolean transliterate = searchResult.requiredSearchPhrase.getSettings().isTransliterate();
        PointDescription pointDescription = null;
        Object object = searchResult.object;
        switch(searchResult.objectType) {
            case POI:
                Amenity a = (Amenity) object;
                String poiSimpleFormat = SampleFormatter.getPoiStringWithoutType(a, lang, transliterate);
                pointDescription = new PointDescription(PointDescription.POINT_TYPE_POI, poiSimpleFormat);
                pointDescription.setIconName(QuickSearchListItem.getAmenityIconName(a));
                break;
            case HOUSE:
                String typeNameHouse = null;
                String name = searchResult.localeName;
                if (searchResult.relatedObject instanceof City) {
                    name = ((City) searchResult.relatedObject).getName(searchResult.requiredSearchPhrase.getSettings().getLang(), true) + " " + name;
                } else if (searchResult.relatedObject instanceof Street) {
                    String s = ((Street) searchResult.relatedObject).getName(searchResult.requiredSearchPhrase.getSettings().getLang(), true);
                    typeNameHouse = ((Street) searchResult.relatedObject).getCity().getName(searchResult.requiredSearchPhrase.getSettings().getLang(), true);
                    name = s + " " + name;
                } else if (searchResult.localeRelatedObjectName != null) {
                    name = searchResult.localeRelatedObjectName + " " + name;
                }
                pointDescription = new PointDescription(PointDescription.POINT_TYPE_ADDRESS, typeNameHouse, name);
                pointDescription.setIconName("ic_action_building");
                break;
            case LOCATION:
                pointDescription = new PointDescription(searchResult.location.getLatitude(), searchResult.location.getLongitude());
                pointDescription.setIconName("ic_action_world_globe");
                break;
            case STREET_INTERSECTION:
                String typeNameIntersection = QuickSearchListItem.getTypeName(app, searchResult);
                if (Algorithms.isEmpty(typeNameIntersection)) {
                    typeNameIntersection = null;
                }
                pointDescription = new PointDescription(PointDescription.POINT_TYPE_ADDRESS, typeNameIntersection, QuickSearchListItem.getName(app, searchResult));
                pointDescription.setIconName("ic_action_intersection");
                break;
        }
        dialogFragment.hideToolbar();
        dialogFragment.hide();
        getMainActivity().showOnMap(searchResult.location, searchResult.preferredZoom);
        getMainActivity().getContextMenu().show(searchResult.location, pointDescription, object);
    }
}
Also used : SampleApplication(net.osmand.core.samples.android.sample1.SampleApplication) Amenity(net.osmand.data.Amenity) PointDescription(net.osmand.core.samples.android.sample1.data.PointDescription) Street(net.osmand.data.Street) City(net.osmand.data.City)

Example 29 with Amenity

use of net.osmand.data.Amenity 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)

Example 30 with Amenity

use of net.osmand.data.Amenity in project OsmAnd-tools by osmandapp.

the class BinaryComparator method comparePoi.

private void comparePoi(BinaryMapIndexReader i0, BinaryMapIndexReader i1) throws IOException {
    List<Amenity> amenities0 = loadAmenities(i0);
    List<Amenity> amenities1 = loadAmenities(i1);
    int i = 0;
    int j = 0;
    int[] uniqueCount = { 0, 0 };
    Comparator<Amenity> c = getNaturalOrder();
    Amenity a0 = get(amenities0, 0);
    Amenity a1 = get(amenities1, 0);
    while (i < amenities0.size() || j < amenities1.size()) {
        int cmp = c.compare(a0, a1);
        if (cmp < 0) {
            if (COMPARE_SET.contains(COMPARE_UNIQUE_1) && COMPARE_SET.contains(POI_COMPARE)) {
                uniqueCount[0]++;
                printAmenity(a0, 0);
            }
            i++;
            a0 = get(amenities0, i);
        } else if (cmp > 0) {
            if (COMPARE_SET.contains(COMPARE_UNIQUE_2) && COMPARE_SET.contains(POI_COMPARE)) {
                uniqueCount[1]++;
                printAmenity(a1, 1);
            }
            j++;
            a1 = get(amenities1, j);
        } else {
            if (COMPARE_SET.contains(POI_DETAILS) && a0 != null && a1 != null) {
                comparePoiDetails(a0, a1);
            }
            i++;
            j++;
            a0 = get(amenities0, i);
            a1 = get(amenities1, j);
        }
    }
    for (int compareUnique : Arrays.asList(COMPARE_UNIQUE_1, COMPARE_UNIQUE_2)) {
        if (COMPARE_SET.contains(compareUnique)) {
            int uniqueToFile = compareUnique - COMPARE_UNIQUE_1;
            log.info("Amenities present only in " + fileNameByNumber[uniqueToFile] + ": " + uniqueCount[uniqueToFile]);
        }
    }
}
Also used : Amenity(net.osmand.data.Amenity)

Aggregations

Amenity (net.osmand.data.Amenity)53 LatLon (net.osmand.data.LatLon)17 ArrayList (java.util.ArrayList)11 PoiCategory (net.osmand.osm.PoiCategory)9 AbstractPoiType (net.osmand.osm.AbstractPoiType)8 PoiType (net.osmand.osm.PoiType)8 PointDescription (net.osmand.data.PointDescription)7 Paint (android.graphics.Paint)6 View (android.view.View)6 ImageView (android.widget.ImageView)6 HashMap (java.util.HashMap)6 FavouritePoint (net.osmand.data.FavouritePoint)6 TLongObjectHashMap (gnu.trove.map.hash.TLongObjectHashMap)5 File (java.io.File)5 Map (java.util.Map)5 BinaryMapIndexReader (net.osmand.binary.BinaryMapIndexReader)5 QuadRect (net.osmand.data.QuadRect)5 MapMarker (net.osmand.plus.MapMarkersHelper.MapMarker)5 OsmandApplication (net.osmand.plus.OsmandApplication)5 LinearLayout (android.widget.LinearLayout)4