Search in sources :

Example 11 with MapPoiTypes

use of net.osmand.osm.MapPoiTypes in project Osmand by osmandapp.

the class RenderedObjectMenuController method addPlainMenuItems.

@Override
public void addPlainMenuItems(String typeStr, PointDescription pointDescription, final LatLon latLon) {
    MapPoiTypes poiTypes = getMapActivity().getMyApplication().getPoiTypes();
    for (Map.Entry<String, String> entry : renderedObject.getTags().entrySet()) {
        if (entry.getKey().equalsIgnoreCase("maxheight")) {
            AbstractPoiType pt = poiTypes.getAnyPoiAdditionalTypeByKey(entry.getKey());
            if (pt != null) {
                addPlainMenuItem(R.drawable.ic_action_note_dark, null, pt.getTranslation() + ": " + entry.getValue(), false, false, null);
            }
        }
    }
    boolean osmEditingEnabled = OsmandPlugin.getEnabledPlugin(OsmEditingPlugin.class) != null;
    if (osmEditingEnabled && renderedObject.getId() != null && renderedObject.getId() > 0 && (renderedObject.getId() % 2 == 1 || (renderedObject.getId() >> 7) < Integer.MAX_VALUE)) {
        String link;
        if ((renderedObject.getId() >> 6) % 2 == 1) {
            link = "https://www.openstreetmap.org/node/";
        } else {
            link = "https://www.openstreetmap.org/way/";
        }
        addPlainMenuItem(R.drawable.ic_action_info_dark, null, link + (renderedObject.getId() >> 7), true, true, null);
    }
    addMyLocationToPlainItems(latLon);
}
Also used : AbstractPoiType(net.osmand.osm.AbstractPoiType) Map(java.util.Map) MapPoiTypes(net.osmand.osm.MapPoiTypes) OsmEditingPlugin(net.osmand.plus.osmedit.OsmEditingPlugin)

Example 12 with MapPoiTypes

use of net.osmand.osm.MapPoiTypes in project Osmand by osmandapp.

the class NominatimPoiFilter method searchAmenitiesInternal.

@Override
protected List<Amenity> searchAmenitiesInternal(double lat, double lon, double topLatitude, double bottomLatitude, double leftLongitude, double rightLongitude, int zoom, ResultMatcher<Amenity> matcher) {
    final int deviceApiVersion = android.os.Build.VERSION.SDK_INT;
    String NOMINATIM_API;
    if (deviceApiVersion >= android.os.Build.VERSION_CODES.GINGERBREAD) {
        NOMINATIM_API = "https://nominatim.openstreetmap.org/search/";
    } else {
        NOMINATIM_API = "http://nominatim.openstreetmap.org/search/";
    }
    currentSearchResult = new ArrayList<Amenity>();
    if (Algorithms.isEmpty(getFilterByName())) {
        return currentSearchResult;
    }
    String viewbox = "viewboxlbrt=" + ((float) leftLongitude) + "," + ((float) bottomLatitude) + "," + ((float) rightLongitude) + "," + ((float) topLatitude);
    try {
        lastError = "";
        String urlq;
        if (addressQuery) {
            urlq = NOMINATIM_API + "?format=xml&addressdetails=0&accept-language=" + Locale.getDefault().getLanguage() + "&q=" + URLEncoder.encode(getFilterByName());
        } else {
            urlq = NOMINATIM_API + "?format=xml&addressdetails=1&limit=" + LIMIT + "&bounded=1&" + viewbox + "&q=" + URLEncoder.encode(getFilterByName());
        }
        log.info(urlq);
        // $NON-NLS-1$
        URLConnection connection = NetworkUtils.getHttpURLConnection(urlq);
        InputStream stream = connection.getInputStream();
        XmlPullParser parser = PlatformUtil.newXMLPullParser();
        // $NON-NLS-1$
        parser.setInput(stream, "UTF-8");
        int eventType;
        int namedDepth = 0;
        Amenity a = null;
        MapPoiTypes poiTypes = ((OsmandApplication) getApplication()).getPoiTypes();
        while ((eventType = parser.next()) != XmlPullParser.END_DOCUMENT) {
            if (eventType == XmlPullParser.START_TAG) {
                if (parser.getName().equals("searchresults")) {
                    // $NON-NLS-1$
                    // $NON-NLS-1$ //$NON-NLS-2$
                    String err = parser.getAttributeValue("", "error");
                    if (err != null && err.length() > 0) {
                        lastError = err;
                        stream.close();
                        return currentSearchResult;
                    }
                }
                if (parser.getName().equals("place")) {
                    // $NON-NLS-1$
                    namedDepth++;
                    if (namedDepth == 1) {
                        try {
                            a = new Amenity();
                            // $NON-NLS-1$//$NON-NLS-2$
                            a.setLocation(// $NON-NLS-1$//$NON-NLS-2$
                            Double.parseDouble(parser.getAttributeValue("", "lat")), // $NON-NLS-1$//$NON-NLS-2$
                            Double.parseDouble(parser.getAttributeValue("", "lon")));
                            // $NON-NLS-1$ //$NON-NLS-2$
                            a.setId(Long.parseLong(parser.getAttributeValue("", "place_id")));
                            // $NON-NLS-1$//$NON-NLS-2$
                            String name = parser.getAttributeValue("", "display_name");
                            a.setName(name);
                            a.setEnName(Junidecode.unidecode(name));
                            // $NON-NLS-1$//$NON-NLS-2$
                            a.setSubType(parser.getAttributeValue("", "type"));
                            PoiType pt = poiTypes.getPoiTypeByKey(a.getSubType());
                            a.setType(pt != null ? pt.getCategory() : poiTypes.getOtherPoiCategory());
                            if (matcher == null || matcher.publish(a)) {
                                currentSearchResult.add(a);
                            }
                        } catch (NumberFormatException e) {
                            // $NON-NLS-1$
                            log.info("Invalid attributes", e);
                        }
                    }
                } else if (a != null && parser.getName().equals(a.getSubType())) {
                    if (parser.next() == XmlPullParser.TEXT) {
                        String name = parser.getText();
                        if (name != null) {
                            a.setName(name);
                            a.setEnName(Junidecode.unidecode(name));
                        }
                    }
                }
            } else if (eventType == XmlPullParser.END_TAG) {
                if (parser.getName().equals("place")) {
                    // $NON-NLS-1$
                    namedDepth--;
                    if (namedDepth == 0) {
                        a = null;
                    }
                }
            }
        }
        stream.close();
    } catch (IOException e) {
        // $NON-NLS-1$
        log.error("Error loading name finder poi", e);
        // $NON-NLS-1$
        lastError = getApplication().getString(R.string.shared_string_io_error);
    } catch (XmlPullParserException e) {
        // $NON-NLS-1$
        log.error("Error parsing name finder poi", e);
        // $NON-NLS-1$
        lastError = getApplication().getString(R.string.shared_string_io_error);
    }
    MapUtils.sortListOfMapObject(currentSearchResult, lat, lon);
    return currentSearchResult;
}
Also used : Amenity(net.osmand.data.Amenity) OsmandApplication(net.osmand.plus.OsmandApplication) InputStream(java.io.InputStream) XmlPullParser(org.xmlpull.v1.XmlPullParser) PoiType(net.osmand.osm.PoiType) IOException(java.io.IOException) URLConnection(java.net.URLConnection) MapPoiTypes(net.osmand.osm.MapPoiTypes) XmlPullParserException(org.xmlpull.v1.XmlPullParserException)

Example 13 with MapPoiTypes

use of net.osmand.osm.MapPoiTypes in project Osmand by osmandapp.

the class AmenityMenuBuilder method buildInternal.

@Override
public void buildInternal(View view) {
    boolean hasWiki = false;
    MapPoiTypes poiTypes = app.getPoiTypes();
    String preferredLang = SampleApplication.LANGUAGE;
    List<AmenityInfoRow> infoRows = new LinkedList<>();
    List<AmenityInfoRow> descriptions = new LinkedList<>();
    for (Map.Entry<String, String> e : amenity.getAdditionalInfo().entrySet()) {
        int iconId;
        Drawable icon = null;
        int textColor = 0;
        String key = e.getKey();
        String vl = e.getValue();
        String textPrefix = "";
        View collapsableView = null;
        boolean collapsable = false;
        boolean isWiki = false;
        boolean isText = false;
        boolean isDescription = false;
        boolean needLinks = !"population".equals(key);
        boolean isPhoneNumber = false;
        boolean isUrl = false;
        int poiTypeOrder = 0;
        String poiTypeKeyName = "";
        AbstractPoiType pt = poiTypes.getAnyPoiAdditionalTypeByKey(key);
        if (pt == null && !Algorithms.isEmpty(vl) && vl.length() < 50) {
            pt = poiTypes.getAnyPoiAdditionalTypeByKey(key + "_" + vl);
        }
        PoiType pType = null;
        if (pt != null) {
            pType = (PoiType) pt;
            if (pType.isFilterOnly()) {
                continue;
            }
            poiTypeOrder = pType.getOrder();
            poiTypeKeyName = pType.getKeyName();
        }
        if (amenity.getType().isWiki()) {
            if (!hasWiki) {
                iconId = OsmandResources.getDrawableId("ic_action_note_dark");
                String lng = amenity.getContentLanguage("content", preferredLang, "en");
                if (Algorithms.isEmpty(lng)) {
                    lng = "en";
                }
                final String langSelected = lng;
                String content = amenity.getDescription(langSelected);
                vl = (content != null) ? Html.fromHtml(content).toString() : "";
                if (vl.length() > 300) {
                    vl = vl.substring(0, 300);
                }
                hasWiki = true;
                isWiki = true;
                needLinks = false;
            } else {
                continue;
            }
        } else if (key.startsWith("name:")) {
            continue;
        } else if (Amenity.OPENING_HOURS.equals(key)) {
            iconId = OsmandResources.getDrawableId("ic_action_time");
            collapsableView = getCollapsableTextView(view.getContext(), true, amenity.getOpeningHours());
            collapsable = true;
            OpeningHoursParser.OpeningHours rs = OpeningHoursParser.parseOpenedHours(amenity.getOpeningHours());
            if (rs != null) {
                vl = rs.toLocalString();
                Calendar inst = Calendar.getInstance();
                inst.setTimeInMillis(System.currentTimeMillis());
                boolean opened = rs.isOpenedForTime(inst);
                if (opened) {
                    textColor = R.color.color_ok;
                } else {
                    textColor = R.color.color_invalid;
                }
            }
            needLinks = false;
        } else if (Amenity.PHONE.equals(key)) {
            iconId = OsmandResources.getDrawableId("ic_action_call_dark");
            isPhoneNumber = true;
        } else if (Amenity.WEBSITE.equals(key)) {
            iconId = OsmandResources.getDrawableId("ic_world_globe_dark");
            isUrl = true;
        } else if (Amenity.CUISINE.equals(key)) {
            iconId = OsmandResources.getDrawableId("ic_action_cuisine");
            StringBuilder sb = new StringBuilder();
            for (String c : e.getValue().split(";")) {
                if (sb.length() > 0) {
                    sb.append(", ");
                } else {
                    sb.append(app.getString("poi_cuisine")).append(": ");
                }
                sb.append(poiTypes.getPoiTranslation("cuisine_" + c).toLowerCase());
            }
            vl = sb.toString();
        } else {
            if (key.contains(Amenity.DESCRIPTION)) {
                iconId = OsmandResources.getDrawableId("ic_action_note_dark");
            } else {
                iconId = OsmandResources.getDrawableId("ic_action_info_dark");
            }
            if (pType != null) {
                poiTypeOrder = pType.getOrder();
                poiTypeKeyName = pType.getKeyName();
                if (pType.getParentType() != null && pType.getParentType() instanceof PoiType) {
                    icon = getRowIcon(view.getContext(), ((PoiType) pType.getParentType()).getOsmTag() + "_" + pType.getOsmTag().replace(':', '_') + "_" + pType.getOsmValue());
                }
                if (!pType.isText()) {
                    if (!Algorithms.isEmpty(pType.getPoiAdditionalCategory())) {
                        vl = pType.getPoiAdditionalCategoryTranslation() + ": " + pType.getTranslation().toLowerCase();
                    } else {
                        vl = pType.getTranslation();
                    }
                } else {
                    isText = true;
                    isDescription = iconId == OsmandResources.getDrawableId("ic_action_note_dark");
                    textPrefix = pType.getTranslation();
                    vl = amenity.unzipContent(e.getValue());
                }
                if (!isDescription && icon == null) {
                    icon = getRowIcon(view.getContext(), pType.getIconKeyName());
                    if (isText && icon != null) {
                        textPrefix = "";
                    }
                }
                if (icon == null && isText) {
                    iconId = OsmandResources.getDrawableId("ic_action_note_dark");
                }
            } else {
                textPrefix = Algorithms.capitalizeFirstLetterAndLowercase(e.getKey());
                vl = amenity.unzipContent(e.getValue());
            }
        }
        if (vl.startsWith("http://") || vl.startsWith("https://") || vl.startsWith("HTTP://") || vl.startsWith("HTTPS://")) {
            isUrl = true;
        }
        if (isDescription) {
            descriptions.add(new AmenityInfoRow(key, OsmandResources.getDrawableId("ic_action_note_dark"), textPrefix, vl, collapsable, collapsableView, 0, false, true, true, 0, "", false, false));
        } else if (icon != null) {
            infoRows.add(new AmenityInfoRow(key, icon, textPrefix, vl, collapsable, collapsableView, textColor, isWiki, isText, needLinks, poiTypeOrder, poiTypeKeyName, isPhoneNumber, isUrl));
        } else {
            infoRows.add(new AmenityInfoRow(key, iconId, textPrefix, vl, collapsable, collapsableView, textColor, isWiki, isText, needLinks, poiTypeOrder, poiTypeKeyName, isPhoneNumber, isUrl));
        }
    }
    Collections.sort(infoRows, new Comparator<AmenityInfoRow>() {

        @Override
        public int compare(AmenityInfoRow row1, AmenityInfoRow row2) {
            if (row1.order < row2.order) {
                return -1;
            } else if (row1.order == row2.order) {
                return row1.name.compareTo(row2.name);
            } else {
                return 1;
            }
        }
    });
    for (AmenityInfoRow info : infoRows) {
        buildAmenityRow(view, info);
    }
    String langSuffix = ":" + preferredLang;
    AmenityInfoRow descInPrefLang = null;
    for (AmenityInfoRow desc : descriptions) {
        if (desc.key.length() > langSuffix.length() && desc.key.substring(desc.key.length() - langSuffix.length(), desc.key.length()).equals(langSuffix)) {
            descInPrefLang = desc;
            break;
        }
    }
    if (descInPrefLang != null) {
        descriptions.remove(descInPrefLang);
        descriptions.add(0, descInPrefLang);
    }
    for (AmenityInfoRow info : descriptions) {
        buildAmenityRow(view, info);
    }
    if (processNearstWiki() && nearestWiki.size() > 0) {
        AmenityInfoRow wikiInfo = new AmenityInfoRow("nearest_wiki", OsmandResources.getDrawableId("ic_action_wikipedia"), null, app.getString("wiki_around") + " (" + nearestWiki.size() + ")", true, getCollapsableWikiView(view.getContext(), true), 0, false, false, false, 1000, null, false, false);
        buildAmenityRow(view, wikiInfo);
    }
    buildRow(view, OsmandResources.getDrawableId("ic_action_get_my_location"), PointDescription.getLocationName(app, amenity.getLocation().getLatitude(), amenity.getLocation().getLongitude(), true).replaceAll("\n", " "), 0, false, null, false, 0, false, null);
}
Also used : Calendar(java.util.Calendar) Drawable(android.graphics.drawable.Drawable) AbstractPoiType(net.osmand.osm.AbstractPoiType) PoiType(net.osmand.osm.PoiType) SpannableString(android.text.SpannableString) AbstractPoiType(net.osmand.osm.AbstractPoiType) ImageView(android.widget.ImageView) View(android.view.View) TextView(android.widget.TextView) OpeningHoursParser(net.osmand.util.OpeningHoursParser) MapPoiTypes(net.osmand.osm.MapPoiTypes) LinkedList(java.util.LinkedList) Map(java.util.Map)

Example 14 with MapPoiTypes

use of net.osmand.osm.MapPoiTypes in project Osmand by osmandapp.

the class SampleFormatter method getAmenityDescriptionContent.

public static String getAmenityDescriptionContent(SampleApplication ctx, Amenity amenity, boolean shortDescription) {
    StringBuilder d = new StringBuilder();
    if (amenity.getType().isWiki()) {
        return "";
    }
    MapPoiTypes poiTypes = ctx.getPoiTypes();
    for (Entry<String, String> e : amenity.getAdditionalInfo().entrySet()) {
        String key = e.getKey();
        String vl = e.getValue();
        if (key.startsWith("name:")) {
            continue;
        } else if (vl.length() >= 150) {
            if (shortDescription) {
                continue;
            }
        } else if (Amenity.OPENING_HOURS.equals(key)) {
            d.append(ctx.getString("opening_hours") + ": ");
        } else if (Amenity.PHONE.equals(key)) {
            d.append(ctx.getString("phone") + ": ");
        } else if (Amenity.WEBSITE.equals(key)) {
            d.append(ctx.getString("website") + ": ");
        } else {
            AbstractPoiType pt = poiTypes.getAnyPoiAdditionalTypeByKey(e.getKey());
            if (pt != null) {
                if (pt instanceof PoiType && !((PoiType) pt).isText()) {
                    vl = pt.getTranslation();
                } else {
                    vl = pt.getTranslation() + ": " + amenity.unzipContent(e.getValue());
                }
            } else {
                vl = Algorithms.capitalizeFirstLetterAndLowercase(e.getKey()) + ": " + amenity.unzipContent(e.getValue());
            }
        }
        d.append(vl).append('\n');
    }
    return d.toString().trim();
}
Also used : AbstractPoiType(net.osmand.osm.AbstractPoiType) PoiType(net.osmand.osm.PoiType) AbstractPoiType(net.osmand.osm.AbstractPoiType) MapPoiTypes(net.osmand.osm.MapPoiTypes)

Example 15 with MapPoiTypes

use of net.osmand.osm.MapPoiTypes in project Osmand by osmandapp.

the class QuickSearchPoiFilterFragment method getExcludedPoiAdditionalCategories.

@NonNull
private Set<String> getExcludedPoiAdditionalCategories() {
    Set<String> excludedPoiAdditionalCategories = new LinkedHashSet<>();
    if (filter.getAcceptedTypes().size() == 0) {
        return excludedPoiAdditionalCategories;
    }
    MapPoiTypes poiTypes = getMyApplication().getPoiTypes();
    PoiCategory topCategory = null;
    for (Entry<PoiCategory, LinkedHashSet<String>> entry : filter.getAcceptedTypes().entrySet()) {
        if (topCategory == null) {
            topCategory = entry.getKey();
        }
        if (entry.getValue() != null) {
            Set<String> excluded = new LinkedHashSet<>();
            for (String keyName : entry.getValue()) {
                PoiType poiType = poiTypes.getPoiTypeByKeyInCategory(topCategory, keyName);
                if (poiType != null) {
                    collectExcludedPoiAdditionalCategories(poiType, excluded);
                    if (!poiType.isReference()) {
                        PoiFilter poiFilter = poiType.getFilter();
                        if (poiFilter != null) {
                            collectExcludedPoiAdditionalCategories(poiFilter, excluded);
                        }
                        PoiCategory poiCategory = poiType.getCategory();
                        if (poiCategory != null) {
                            collectExcludedPoiAdditionalCategories(poiCategory, excluded);
                        }
                    }
                }
                if (excludedPoiAdditionalCategories.size() == 0) {
                    excludedPoiAdditionalCategories.addAll(excluded);
                } else {
                    excludedPoiAdditionalCategories.retainAll(excluded);
                }
                excluded.clear();
            }
        }
    }
    if (topCategory != null && topCategory.getExcludedPoiAdditionalCategories() != null) {
        excludedPoiAdditionalCategories.addAll(topCategory.getExcludedPoiAdditionalCategories());
    }
    return excludedPoiAdditionalCategories;
}
Also used : LinkedHashSet(java.util.LinkedHashSet) PoiFilter(net.osmand.osm.PoiFilter) PoiCategory(net.osmand.osm.PoiCategory) AbstractPoiType(net.osmand.osm.AbstractPoiType) PoiType(net.osmand.osm.PoiType) MapPoiTypes(net.osmand.osm.MapPoiTypes) NonNull(android.support.annotation.NonNull)

Aggregations

MapPoiTypes (net.osmand.osm.MapPoiTypes)17 AbstractPoiType (net.osmand.osm.AbstractPoiType)11 PoiType (net.osmand.osm.PoiType)10 OsmandApplication (net.osmand.plus.OsmandApplication)7 PoiCategory (net.osmand.osm.PoiCategory)6 ArrayList (java.util.ArrayList)5 Drawable (android.graphics.drawable.Drawable)3 NonNull (android.support.annotation.NonNull)3 View (android.view.View)3 TextView (android.widget.TextView)3 List (java.util.List)3 Map (java.util.Map)3 Amenity (net.osmand.data.Amenity)3 DialogInterface (android.content.DialogInterface)2 AlertDialog (android.support.v7.app.AlertDialog)2 AutoCompleteTextView (android.widget.AutoCompleteTextView)2 Button (android.widget.Button)2 ImageButton (android.widget.ImageButton)2 LinearLayout (android.widget.LinearLayout)2 File (java.io.File)2