Update poi types

This commit is contained in:
Victor Shcherb 2015-04-05 13:51:01 +02:00
parent cb48b312c1
commit c5c60ff049
7 changed files with 88 additions and 54 deletions

View file

@ -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<String, PoiType> getAllTranslatedNames() {
Map<String, PoiType> translation = new TreeMap<String, PoiType>();
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<PoiType> referenceTypes = new ArrayList<PoiType>();
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;
}
}

View file

@ -47,4 +47,6 @@ public class PoiCategory extends PoiFilter {
return regId;
}
}

View file

@ -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) {
}
}

View file

@ -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

View file

@ -229,10 +229,10 @@ public class PoiFiltersHelper {
public List<PoiLegacyFilter> getOsmDefinedPoiFilters(){
if(cacheOsmDefinedFilters == null){
if (cacheOsmDefinedFilters == null) {
cacheOsmDefinedFilters = new ArrayList<PoiLegacyFilter>();
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();

View file

@ -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<String>());
}
LinkedHashSet<String> ls = acceptedTypes.get(refCat);
if (ls != null) {
ls.add(pt.getKeyName());
}
}
}
}

View file

@ -81,38 +81,30 @@ public class POIMapLayer extends OsmandMapLayer implements ContextMenuLayer.ICon
@Override
protected List<Amenity> 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<Amenity>() {
if (filter == null) {
return new ArrayList<Amenity>();
}
return resourceManager.searchAmenities(filter, latLonBounds.top, latLonBounds.left,
latLonBounds.bottom, latLonBounds.right, tileBox.getZoom(), new ResultMatcher<Amenity>() {
@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<? super Amenity> am) {
List<Amenity> objects = data.getResults();