Added poi additional filter (cuisine)

This commit is contained in:
Alexey Kulish 2016-10-17 16:12:35 +03:00
parent 8f7a5c256a
commit eabd00680b
3 changed files with 51 additions and 8 deletions

View file

@ -42,6 +42,7 @@ public class MapPoiTypes {
Map<String, PoiType> poiTypesByTag = new LinkedHashMap<String, PoiType>();
Map<String, String> deprecatedTags = new LinkedHashMap<String, String>();
Map<String, String> poiAdditionalCategoryIcons = new LinkedHashMap<String, String>();
List<PoiType> textPoiAdditionals = new ArrayList<PoiType>();
public MapPoiTypes(String fileName) {
@ -95,6 +96,10 @@ public class MapPoiTypes {
return poiAdditionalCategoryIcons.get(category);
}
public List<PoiType> getTextPoiAdditionals() {
return textPoiAdditionals;
}
public List<PoiFilter> getTopVisibleFilters() {
List<PoiFilter> lf = new ArrayList<PoiFilter>();
for (PoiCategory pc : categories) {
@ -285,11 +290,11 @@ public class MapPoiTypes {
int tok;
parser.setInput(is, "UTF-8");
PoiCategory lastCategory = null;
Set<String> lastCategoryPoiAdditionalsCategories = new TreeSet<>();
Set<String> lastCategoryPoiAdditionalsCategories = new TreeSet<String>();
PoiFilter lastFilter = null;
Set<String> lastFilterPoiAdditionalsCategories = new TreeSet<>();
Set<String> lastFilterPoiAdditionalsCategories = new TreeSet<String>();
PoiType lastType = null;
Set<String> lastTypePoiAdditionalsCategories = new TreeSet<>();
Set<String> lastTypePoiAdditionalsCategories = new TreeSet<String>();
String lastPoiAdditionalCategory = null;
while ((tok = parser.next()) != XmlPullParser.END_DOCUMENT) {
if (tok == XmlPullParser.START_TAG) {
@ -395,19 +400,19 @@ public class MapPoiTypes {
if (name.equals("poi_filter")) {
if (lastFilterPoiAdditionalsCategories.size() > 0) {
abstractTypeAdditionalCategories.put(lastFilter, lastFilterPoiAdditionalsCategories);
lastFilterPoiAdditionalsCategories = new TreeSet<>();
lastFilterPoiAdditionalsCategories = new TreeSet<String>();
}
lastFilter = null;
} else if (name.equals("poi_type")) {
if (lastTypePoiAdditionalsCategories.size() > 0) {
abstractTypeAdditionalCategories.put(lastType, lastTypePoiAdditionalsCategories);
lastTypePoiAdditionalsCategories = new TreeSet<>();
lastTypePoiAdditionalsCategories = new TreeSet<String>();
}
lastType = null;
} else if (name.equals("poi_category")) {
if (lastCategoryPoiAdditionalsCategories.size() > 0) {
abstractTypeAdditionalCategories.put(lastCategory, lastCategoryPoiAdditionalsCategories);
lastCategoryPoiAdditionalsCategories = new TreeSet<>();
lastCategoryPoiAdditionalsCategories = new TreeSet<String>();
}
lastCategory = null;
} else if (name.equals("poi_additional_category")) {
@ -490,6 +495,9 @@ public class MapPoiTypes {
} else if (lastCategory != null) {
lastCategory.addPoiAdditional(tp);
}
if (tp.isText()) {
textPoiAdditionals.add(tp);
}
return tp;
}
@ -558,7 +566,6 @@ public class MapPoiTypes {
}
print(" ", p);
}
}
private PoiType getPoiAdditionalByKey(AbstractPoiType p, String name) {
@ -571,7 +578,15 @@ public class MapPoiTypes {
}
}
return null;
}
public PoiType getTextPoiAdditionalByKey(String name) {
for (PoiType pt : textPoiAdditionals) {
if (pt.getKeyName().equals(name)) {
return pt;
}
}
return null;
}
public AbstractPoiType getAnyPoiAdditionalTypeByKey(String name) {

View file

@ -26,6 +26,7 @@ import net.osmand.util.OpeningHoursParser;
import net.osmand.util.OpeningHoursParser.OpeningHours;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Calendar;
import java.util.Collections;
import java.util.HashMap;
@ -331,6 +332,7 @@ public class PoiUIFilter implements SearchPoiTypeFilter, Comparable<PoiUIFilter>
}
}
if (poiAdditionals != null) {
Map<PoiType, PoiType> textPoiAdditionalsMap = new HashMap<>();
Map<String, List<PoiType>> poiAdditionalCategoriesMap = new HashMap<>();
for (PoiType pt : poiAdditionals) {
String category = pt.getPoiAdditionalCategory();
@ -340,6 +342,14 @@ public class PoiUIFilter implements SearchPoiTypeFilter, Comparable<PoiUIFilter>
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;
@ -348,6 +358,24 @@ public class PoiUIFilter implements SearchPoiTypeFilter, Comparable<PoiUIFilter>
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) {

View file

@ -137,7 +137,7 @@ public class MapInfoLayer extends OsmandMapLayer {
rulerControl.setVisibility(false);
// register left stack
registerSideWidget(null, R.drawable.ic_action_aircraft, R.string.map_widget_compass, "compass", true, 4);
registerSideWidget(null, R.drawable.ic_action_compass, R.string.map_widget_compass, "compass", true, 4);
NextTurnInfoWidget bigInfoControl = ric.createNextInfoControl(map, app, false);
registerSideWidget(bigInfoControl, R.drawable.ic_action_next_turn, R.string.map_widget_next_turn, "next_turn", true, 5);