From c5c60ff04950271979190def4f04d48e6708a6f7 Mon Sep 17 00:00:00 2001 From: Victor Shcherb Date: Sun, 5 Apr 2015 13:51:01 +0200 Subject: [PATCH] Update poi types --- .../src/net/osmand/osm/MapPoiTypes.java | 31 +++++++----- .../src/net/osmand/osm/PoiCategory.java | 2 + OsmAnd-java/src/net/osmand/osm/PoiType.java | 47 +++++++++++++------ .../osmand/plus/activities/MapActivity.java | 4 -- .../net/osmand/plus/poi/PoiFiltersHelper.java | 4 +- .../net/osmand/plus/poi/PoiLegacyFilter.java | 18 +++++++ .../net/osmand/plus/views/POIMapLayer.java | 36 ++++++-------- 7 files changed, 88 insertions(+), 54 deletions(-) diff --git a/OsmAnd-java/src/net/osmand/osm/MapPoiTypes.java b/OsmAnd-java/src/net/osmand/osm/MapPoiTypes.java index 132819d79c..ebaf045f02 100644 --- a/OsmAnd-java/src/net/osmand/osm/MapPoiTypes.java +++ b/OsmAnd-java/src/net/osmand/osm/MapPoiTypes.java @@ -70,21 +70,23 @@ public class MapPoiTypes { return getPoiCategoryByName(name, false); } - - public PoiCategory getPoiCategoryBySubtypeName(String name) { + public PoiType getPoiTypeByKey(String name) { for(PoiCategory pc : categories) { PoiType pt = pc.getPoiTypeByKeyName(name); - if(pt != null) { - return pc; + if(pt != null && !pt.isReference()) { + return pt; } } - return otherCategory; + return null; } public Map getAllTranslatedNames() { Map translation = new TreeMap(); for(PoiCategory pc : categories) { for(PoiType pt : pc.getPoiTypes()) { + if(pt.isReference()) { + continue; + } translation.put(pt.getTranslation(), pt); } } @@ -131,6 +133,7 @@ public class MapPoiTypes { public void init(){ InputStream is; + List referenceTypes = new ArrayList(); try { if(resourceName == null){ is = MapRenderingTypes.class.getResourceAsStream("poi_types.xml"); //$NON-NLS-1$ @@ -157,7 +160,8 @@ public class MapPoiTypes { } else if(name.equals("poi_reference")){ PoiType tp = new PoiType(this, lastCategory, parser.getAttributeValue("","name")); - tp.setReference(true); + referenceTypes.add(tp); + tp.setReferenceType(tp); if(lastFilter != null) { lastFilter.addPoiType(tp); } @@ -197,6 +201,14 @@ public class MapPoiTypes { e.printStackTrace(); throw new RuntimeException(e); } + for (PoiType gt : referenceTypes) { + PoiType pt = getPoiTypeByKey(gt.keyName); + if (pt == null || pt.getOsmTag() == null) { + throw new IllegalStateException("Can't find poi type for poi reference '" + gt.keyName + "'"); + } else { + gt.setReferenceType(pt); + } + } findDefaultOtherCategory(); init = true; } @@ -229,7 +241,8 @@ public class MapPoiTypes { private static void print(String indent, PoiFilter f) { for(PoiType pt : f.getPoiTypes()) { - System.out.println(indent + " Type " + pt.getName()); + System.out.println(indent + " Type " + pt.getName() + + (pt.isReference() ? (" -> " + pt.getReferenceType().getCategory().getKey() ): "")); } } @@ -253,9 +266,5 @@ public class MapPoiTypes { public boolean isRegisteredType(PoiCategory t) { return getPoiCategoryByName(t.getKeyName()) != otherCategory; } - - - - } diff --git a/OsmAnd-java/src/net/osmand/osm/PoiCategory.java b/OsmAnd-java/src/net/osmand/osm/PoiCategory.java index 9c8fd1ad36..1314d48255 100644 --- a/OsmAnd-java/src/net/osmand/osm/PoiCategory.java +++ b/OsmAnd-java/src/net/osmand/osm/PoiCategory.java @@ -47,4 +47,6 @@ public class PoiCategory extends PoiFilter { return regId; } + + } diff --git a/OsmAnd-java/src/net/osmand/osm/PoiType.java b/OsmAnd-java/src/net/osmand/osm/PoiType.java index ec0270d825..26a3b4d934 100644 --- a/OsmAnd-java/src/net/osmand/osm/PoiType.java +++ b/OsmAnd-java/src/net/osmand/osm/PoiType.java @@ -1,15 +1,35 @@ package net.osmand.osm; public class PoiType extends AbstractPoiType { + + private PoiCategory category; + private PoiType referenceType; + private String osmTag; + private String osmTag2; + private String osmValue; + private String osmValue2; - - public PoiType(MapPoiTypes poiTypes, PoiCategory category, String name){ + public PoiType(MapPoiTypes poiTypes, PoiCategory category, String name) { super(name, poiTypes); this.category = category; } - + public PoiType getReferenceType() { + return referenceType; + } + + public void setReferenceType(PoiType referenceType) { + this.referenceType = referenceType; + } + + public boolean isReference() { + return referenceType != null; + } + public String getOsmTag() { + if(isReference()) { + return referenceType.getOsmTag(); + } return osmTag; } @@ -18,6 +38,9 @@ public class PoiType extends AbstractPoiType { } public String getOsmTag2() { + if(isReference()) { + return referenceType.getOsmTag2(); + } return osmTag2; } @@ -26,6 +49,9 @@ public class PoiType extends AbstractPoiType { } public String getOsmValue() { + if(isReference()) { + return referenceType.getOsmValue(); + } return osmValue; } @@ -34,6 +60,9 @@ public class PoiType extends AbstractPoiType { } public String getOsmValue2() { + if(isReference()) { + return referenceType.getOsmValue2(); + } return osmValue2; } @@ -41,21 +70,9 @@ public class PoiType extends AbstractPoiType { this.osmValue2 = osmValue2; } - private PoiCategory category; - private String osmTag; - private String osmTag2; - private String osmValue; - private String osmValue2; - - public PoiCategory getCategory() { return category; } - public void setReference(boolean b) { - - } - - } diff --git a/OsmAnd/src/net/osmand/plus/activities/MapActivity.java b/OsmAnd/src/net/osmand/plus/activities/MapActivity.java index 984ee88438..2ef40d0912 100644 --- a/OsmAnd/src/net/osmand/plus/activities/MapActivity.java +++ b/OsmAnd/src/net/osmand/plus/activities/MapActivity.java @@ -380,10 +380,6 @@ public class MapActivity extends AccessibleActivity { String filterId = settings.getPoiFilterForMap(); PoiLegacyFilter poiFilter = app.getPoiFilters().getFilterById(filterId); - if (poiFilter == null) { - poiFilter = new PoiLegacyFilter(null, app); - } - mapLayers.getPoiMapLayer().setFilter(poiFilter); // if destination point was changed try to recalculate route diff --git a/OsmAnd/src/net/osmand/plus/poi/PoiFiltersHelper.java b/OsmAnd/src/net/osmand/plus/poi/PoiFiltersHelper.java index 42ced4afc4..7539f984ea 100644 --- a/OsmAnd/src/net/osmand/plus/poi/PoiFiltersHelper.java +++ b/OsmAnd/src/net/osmand/plus/poi/PoiFiltersHelper.java @@ -229,10 +229,10 @@ public class PoiFiltersHelper { public List getOsmDefinedPoiFilters(){ - if(cacheOsmDefinedFilters == null){ + if (cacheOsmDefinedFilters == null) { cacheOsmDefinedFilters = new ArrayList(); MapPoiTypes poiTypes = application.getPoiTypes(); - for(PoiCategory t : poiTypes.getCategories()){ + for (PoiCategory t : poiTypes.getCategories()) { cacheOsmDefinedFilters.add(new PoiLegacyFilter(t, application)); } final Collator instance = Collator.getInstance(); diff --git a/OsmAnd/src/net/osmand/plus/poi/PoiLegacyFilter.java b/OsmAnd/src/net/osmand/plus/poi/PoiLegacyFilter.java index 55233816a6..3e49761650 100644 --- a/OsmAnd/src/net/osmand/plus/poi/PoiLegacyFilter.java +++ b/OsmAnd/src/net/osmand/plus/poi/PoiLegacyFilter.java @@ -14,6 +14,8 @@ import net.osmand.ResultMatcher; import net.osmand.data.Amenity; import net.osmand.osm.MapPoiTypes; import net.osmand.osm.PoiCategory; +import net.osmand.osm.PoiFilter; +import net.osmand.osm.PoiType; import net.osmand.plus.OsmAndFormatter; import net.osmand.plus.OsmandApplication; import net.osmand.plus.R; @@ -55,6 +57,22 @@ public class PoiLegacyFilter { initSearchAll(); } else { acceptedTypes.put(type, null); + addReferenceTypes(type); + } + } + + private void addReferenceTypes(PoiFilter type) { + for(PoiType pt : type.getPoiTypes()) { + if (pt.isReference()) { + PoiCategory refCat = pt.getReferenceType().getCategory(); + if (!acceptedTypes.containsKey(refCat)) { + acceptedTypes.put(refCat, new LinkedHashSet()); + } + LinkedHashSet ls = acceptedTypes.get(refCat); + if (ls != null) { + ls.add(pt.getKeyName()); + } + } } } diff --git a/OsmAnd/src/net/osmand/plus/views/POIMapLayer.java b/OsmAnd/src/net/osmand/plus/views/POIMapLayer.java index de2ac0ab86..60e7ad9605 100644 --- a/OsmAnd/src/net/osmand/plus/views/POIMapLayer.java +++ b/OsmAnd/src/net/osmand/plus/views/POIMapLayer.java @@ -81,38 +81,30 @@ public class POIMapLayer extends OsmandMapLayer implements ContextMenuLayer.ICon @Override protected List calculateResult(RotatedTileBox tileBox) { QuadRect latLonBounds = tileBox.getLatLonBounds(); -// if(path) { -// RouteCalculationResult result = routingHelper.getRoute(); -// return resourceManager.searchAmenitiesOnThePath(result.getImmutableAllLocations(), radius, filter, null); -// } else { - return resourceManager.searchAmenities(filter, latLonBounds.top, latLonBounds.left, - latLonBounds.bottom, latLonBounds.right, tileBox.getZoom(), new ResultMatcher() { + if (filter == null) { + return new ArrayList(); + } + return resourceManager.searchAmenities(filter, latLonBounds.top, latLonBounds.left, + latLonBounds.bottom, latLonBounds.right, tileBox.getZoom(), new ResultMatcher() { - @Override - public boolean publish(Amenity object) { - return true; - } + @Override + public boolean publish(Amenity object) { + return true; + } - @Override - public boolean isCancelled() { - return isInterrupted(); - } - }); -// } + @Override + public boolean isCancelled() { + return isInterrupted(); + } + }); } }; } - public PoiLegacyFilter getFilter() { - return filter; - } - public void setFilter(PoiLegacyFilter filter) { this.filter = filter; data.clearCache(); } - - public void getAmenityFromPoint(RotatedTileBox tb, PointF point, List am) { List objects = data.getResults();