use of net.osmand.osm.PoiType in project Osmand by osmandapp.
the class PoiFiltersHelper method getLocalWikiPOIFilter.
public PoiUIFilter getLocalWikiPOIFilter() {
if (localWikiPoiFilter == null) {
PoiType place = application.getPoiTypes().getPoiTypeByKey("wiki_place");
if (place != null && !Algorithms.isEmpty(application.getLanguage())) {
PoiUIFilter filter = new PoiUIFilter(place, application, " " + // $NON-NLS-1$
application.getLangTranslation(application.getLanguage()));
filter.setSavedFilterByName("wiki:lang:" + application.getLanguage());
filter.setStandardFilter(true);
localWikiPoiFilter = filter;
}
}
return localWikiPoiFilter;
}
use of net.osmand.osm.PoiType in project Osmand by osmandapp.
the class PoiUIFilter method fillPoiAdditionals.
private void fillPoiAdditionals(AbstractPoiType pt, boolean allFromCategory) {
for (PoiType add : pt.getPoiAdditionals()) {
poiAdditionals.put(add.getKeyName().replace('_', ':').replace(' ', ':'), add);
poiAdditionals.put(add.getTranslation().replace(' ', ':').toLowerCase(), add);
}
if (pt instanceof PoiCategory && allFromCategory) {
for (PoiFilter pf : ((PoiCategory) pt).getPoiFilters()) {
fillPoiAdditionals(pf, true);
}
for (PoiType ps : ((PoiCategory) pt).getPoiTypes()) {
fillPoiAdditionals(ps, false);
}
} else if (pt instanceof PoiFilter && !(pt instanceof PoiCategory)) {
for (PoiType ps : ((PoiFilter) pt).getPoiTypes()) {
fillPoiAdditionals(ps, false);
}
}
}
use of net.osmand.osm.PoiType in project Osmand by osmandapp.
the class PoiUIFilter method addOtherPoiAdditionals.
private void addOtherPoiAdditionals() {
for (PoiType add : poiTypes.getOtherMapCategory().getPoiAdditionalsCategorized()) {
poiAdditionals.put(add.getKeyName().replace('_', ':').replace(' ', ':'), add);
poiAdditionals.put(add.getTranslation().replace(' ', ':').toLowerCase(), add);
}
}
use of net.osmand.osm.PoiType in project Osmand by osmandapp.
the class PoiUIFilter method getNameFilterInternal.
private AmenityNameFilter getNameFilterInternal(StringBuilder nmFilter, final boolean allTime, final boolean open, final List<PoiType> poiAdditionals) {
final CollatorStringMatcher sm = nmFilter.length() > 0 ? new CollatorStringMatcher(nmFilter.toString().trim(), StringMatcherMode.CHECK_CONTAINS) : null;
return new AmenityNameFilter() {
@Override
public boolean accept(Amenity a) {
if (sm != null) {
String lower = OsmAndFormatter.getPoiStringWithoutType(a, app.getSettings().MAP_PREFERRED_LOCALE.get(), app.getSettings().MAP_TRANSLITERATE_NAMES.get());
if (!sm.matches(lower)) {
return false;
}
}
if (poiAdditionals != null) {
Map<PoiType, PoiType> textPoiAdditionalsMap = new HashMap<>();
Map<String, List<PoiType>> poiAdditionalCategoriesMap = new HashMap<>();
for (PoiType pt : poiAdditionals) {
String category = pt.getPoiAdditionalCategory();
List<PoiType> types = poiAdditionalCategoriesMap.get(category);
if (types == null) {
types = new ArrayList<>();
poiAdditionalCategoriesMap.put(category, types);
}
types.add(pt);
String osmTag = pt.getOsmTag();
if (osmTag.length() < pt.getKeyName().length()) {
PoiType textPoiType = poiTypes.getTextPoiAdditionalByKey(osmTag);
if (textPoiType != null) {
textPoiAdditionalsMap.put(pt, textPoiType);
}
}
}
for (List<PoiType> types : poiAdditionalCategoriesMap.values()) {
boolean acceptedAnyInCategory = false;
for (PoiType p : types) {
String inf = a.getAdditionalInfo(p.getKeyName());
if (inf != null) {
acceptedAnyInCategory = true;
break;
} else {
PoiType textPoiType = textPoiAdditionalsMap.get(p);
if (textPoiType != null) {
inf = a.getAdditionalInfo(textPoiType.getKeyName());
if (!Algorithms.isEmpty(inf)) {
String[] items = inf.split(";");
String val = p.getOsmValue().trim().toLowerCase();
for (String item : items) {
if (item.trim().toLowerCase().equals(val)) {
acceptedAnyInCategory = true;
break;
}
}
if (acceptedAnyInCategory) {
break;
}
}
}
}
}
if (!acceptedAnyInCategory) {
return false;
}
}
}
if (allTime) {
if (!"24/7".equalsIgnoreCase(a.getOpeningHours()) && !"Mo-Su 00:00-24:00".equalsIgnoreCase(a.getOpeningHours())) {
return false;
}
}
if (open) {
OpeningHours rs = OpeningHoursParser.parseOpenedHours(a.getOpeningHours());
if (rs != null) {
Calendar inst = Calendar.getInstance();
inst.setTimeInMillis(System.currentTimeMillis());
boolean work = rs.isOpenedForTime(inst);
if (!work) {
return false;
}
} else {
return false;
}
}
return true;
}
};
}
use of net.osmand.osm.PoiType in project Osmand by osmandapp.
the class PoiUIFilter method getNameFilter.
public AmenityNameFilter getNameFilter(String filter) {
if (Algorithms.isEmpty(filter)) {
return new AmenityNameFilter() {
@Override
public boolean accept(Amenity a) {
return true;
}
};
}
StringBuilder nmFilter = new StringBuilder();
String[] items = filter.split(" ");
boolean allTime = false;
boolean open = false;
List<PoiType> poiAdditionalsFilter = null;
for (String s : items) {
s = s.trim();
if (!Algorithms.isEmpty(s)) {
if (getNameToken24H().equalsIgnoreCase(s)) {
allTime = true;
} else if (getNameTokenOpen().equalsIgnoreCase(s)) {
open = true;
} else if (poiAdditionals.containsKey(s.toLowerCase())) {
if (poiAdditionalsFilter == null) {
poiAdditionalsFilter = new ArrayList<>();
}
PoiType pt = poiAdditionals.get(s.toLowerCase());
if (pt != null) {
poiAdditionalsFilter.add(pt);
}
} else {
nmFilter.append(s).append(" ");
}
}
}
return getNameFilterInternal(nmFilter, allTime, open, poiAdditionalsFilter);
}
Aggregations