2013-04-18 23:35:02 +02:00
|
|
|
package net.osmand.data;
|
|
|
|
|
2013-11-10 16:54:28 +01:00
|
|
|
import java.util.Collections;
|
|
|
|
import java.util.LinkedHashMap;
|
|
|
|
import java.util.Map;
|
|
|
|
|
2014-08-17 15:42:09 +02:00
|
|
|
import net.osmand.Location;
|
2015-02-18 23:21:57 +01:00
|
|
|
import net.osmand.osm.PoiCategory;
|
2015-05-27 00:09:48 +02:00
|
|
|
import net.osmand.util.Algorithms;
|
2013-04-18 23:35:02 +02:00
|
|
|
|
2014-08-17 15:42:09 +02:00
|
|
|
|
|
|
|
public class Amenity extends MapObject {
|
2013-04-18 23:35:02 +02:00
|
|
|
|
2013-11-24 19:45:00 +01:00
|
|
|
public static final String WEBSITE = "website";
|
|
|
|
public static final String PHONE = "phone";
|
|
|
|
public static final String DESCRIPTION = "description";
|
|
|
|
public static final String OPENING_HOURS = "opening_hours";
|
2015-05-27 00:09:48 +02:00
|
|
|
public static final String CONTENT = "content";
|
2013-11-24 19:45:00 +01:00
|
|
|
|
2013-04-18 23:35:02 +02:00
|
|
|
private static final long serialVersionUID = 132083949926339552L;
|
|
|
|
private String subType;
|
2015-02-18 23:21:57 +01:00
|
|
|
private PoiCategory type;
|
2013-11-10 16:54:28 +01:00
|
|
|
// duplicate for fast access
|
2013-04-18 23:35:02 +02:00
|
|
|
private String openingHours;
|
2013-11-10 16:54:28 +01:00
|
|
|
private Map<String, String> additionalInfo;
|
2014-08-17 15:42:09 +02:00
|
|
|
private AmenityRoutePoint routePoint; // for search on path
|
2013-04-18 23:35:02 +02:00
|
|
|
|
|
|
|
public Amenity(){
|
|
|
|
}
|
|
|
|
|
2014-08-17 15:42:09 +02:00
|
|
|
public static class AmenityRoutePoint {
|
|
|
|
public double deviateDistance;
|
|
|
|
public Location pointA;
|
|
|
|
public Location pointB;
|
|
|
|
}
|
|
|
|
|
2015-02-18 23:21:57 +01:00
|
|
|
public PoiCategory getType(){
|
2013-04-18 23:35:02 +02:00
|
|
|
return type;
|
|
|
|
}
|
|
|
|
|
|
|
|
public String getSubType(){
|
|
|
|
return subType;
|
|
|
|
}
|
|
|
|
|
2015-02-18 23:21:57 +01:00
|
|
|
public void setType(PoiCategory type) {
|
2013-04-18 23:35:02 +02:00
|
|
|
this.type = type;
|
|
|
|
}
|
|
|
|
|
|
|
|
public void setSubType(String subType) {
|
|
|
|
this.subType = subType;
|
|
|
|
}
|
|
|
|
|
|
|
|
public String getOpeningHours() {
|
2013-11-10 16:54:28 +01:00
|
|
|
// getAdditionalInfo("opening_hours");
|
2013-04-18 23:35:02 +02:00
|
|
|
return openingHours;
|
|
|
|
}
|
|
|
|
|
2013-11-10 16:54:28 +01:00
|
|
|
public String getAdditionalInfo(String key){
|
|
|
|
if(additionalInfo == null) {
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
return additionalInfo.get(key);
|
|
|
|
}
|
|
|
|
|
|
|
|
public Map<String, String> getAdditionalInfo() {
|
|
|
|
if(additionalInfo == null) {
|
|
|
|
return Collections.emptyMap();
|
|
|
|
}
|
|
|
|
return additionalInfo;
|
|
|
|
}
|
|
|
|
|
|
|
|
public void setAdditionalInfo(Map<String, String> additionalInfo) {
|
|
|
|
this.additionalInfo = additionalInfo;
|
2013-11-24 19:45:00 +01:00
|
|
|
openingHours = additionalInfo.get(OPENING_HOURS);
|
2013-11-10 16:54:28 +01:00
|
|
|
}
|
2014-08-17 15:42:09 +02:00
|
|
|
|
|
|
|
public void setRoutePoint(AmenityRoutePoint routePoint) {
|
|
|
|
this.routePoint = routePoint;
|
2014-08-05 11:09:15 +02:00
|
|
|
}
|
|
|
|
|
2014-08-17 15:42:09 +02:00
|
|
|
public AmenityRoutePoint getRoutePoint() {
|
|
|
|
return routePoint;
|
2014-08-05 11:09:15 +02:00
|
|
|
}
|
2013-11-13 14:13:48 +01:00
|
|
|
|
2013-11-10 16:54:28 +01:00
|
|
|
public void setAdditionalInfo(String tag, String value) {
|
|
|
|
if(this.additionalInfo == null){
|
|
|
|
this.additionalInfo = new LinkedHashMap<String, String>();
|
|
|
|
}
|
2013-11-24 20:24:14 +01:00
|
|
|
if("name".equals(tag)) {
|
|
|
|
setName(value);
|
|
|
|
} else if("name:en".equals(tag)) {
|
|
|
|
setEnName(value);
|
|
|
|
} else {
|
|
|
|
this.additionalInfo.put(tag, value);
|
|
|
|
if (OPENING_HOURS.equals(tag)) {
|
|
|
|
this.openingHours = value;
|
|
|
|
}
|
2013-11-13 14:13:48 +01:00
|
|
|
}
|
2013-11-10 16:54:28 +01:00
|
|
|
}
|
|
|
|
|
2013-04-18 23:35:02 +02:00
|
|
|
|
|
|
|
@Override
|
|
|
|
public String toString() {
|
|
|
|
return type.toString() + " : " + subType + " "+ getName();
|
|
|
|
}
|
|
|
|
|
|
|
|
public String getSite() {
|
2013-11-24 19:45:00 +01:00
|
|
|
return getAdditionalInfo(WEBSITE);
|
2013-04-18 23:35:02 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
public void setSite(String site) {
|
2013-11-24 19:45:00 +01:00
|
|
|
setAdditionalInfo(WEBSITE, site);
|
2013-04-18 23:35:02 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
public String getPhone() {
|
2013-11-24 19:45:00 +01:00
|
|
|
return getAdditionalInfo(PHONE);
|
2013-04-18 23:35:02 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
public void setPhone(String phone) {
|
2013-11-24 19:45:00 +01:00
|
|
|
setAdditionalInfo(PHONE, phone);
|
2013-04-18 23:35:02 +02:00
|
|
|
}
|
|
|
|
|
2015-05-27 00:09:48 +02:00
|
|
|
public String getName(String lang) {
|
|
|
|
if (lang != null) {
|
|
|
|
String translateName;
|
|
|
|
if (lang.equals("en")) {
|
|
|
|
translateName = getEnName();
|
|
|
|
} else {
|
|
|
|
translateName = getAdditionalInfo("name:" + lang);
|
|
|
|
}
|
|
|
|
if (!Algorithms.isEmpty(translateName)) {
|
|
|
|
return translateName;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (!Algorithms.isEmpty(getName())) {
|
|
|
|
return getName();
|
|
|
|
}
|
|
|
|
for (String nm : additionalInfo.keySet()) {
|
|
|
|
if (nm.startsWith("name:")) {
|
|
|
|
return getAdditionalInfo(nm);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return "";
|
|
|
|
}
|
|
|
|
public String getContentLang(String tag, String lang) {
|
|
|
|
if (lang != null) {
|
|
|
|
String translateName = getAdditionalInfo(tag + ":" + lang);
|
|
|
|
if (!Algorithms.isEmpty(translateName)) {
|
|
|
|
return translateName;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
String plainName = getAdditionalInfo(tag);
|
|
|
|
if (!Algorithms.isEmpty(plainName)) {
|
|
|
|
return plainName;
|
|
|
|
}
|
|
|
|
String enName = getAdditionalInfo(tag + ":en");
|
|
|
|
if (!Algorithms.isEmpty(enName)) {
|
|
|
|
return enName;
|
|
|
|
}
|
|
|
|
for (String nm : additionalInfo.keySet()) {
|
|
|
|
if (nm.startsWith(tag + ":")) {
|
|
|
|
return getAdditionalInfo(nm);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
|
|
|
public String getDescription(String lang) {
|
|
|
|
String info = getContentLang(DESCRIPTION, lang);
|
|
|
|
if(!Algorithms.isEmpty(info)) {
|
|
|
|
return info;
|
|
|
|
}
|
|
|
|
return getContentLang(CONTENT, lang);
|
2013-04-18 23:35:02 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
public void setDescription(String description) {
|
2013-11-24 19:45:00 +01:00
|
|
|
setAdditionalInfo(DESCRIPTION, description);
|
2013-04-18 23:35:02 +02:00
|
|
|
}
|
|
|
|
|
2013-11-13 14:13:48 +01:00
|
|
|
public void setOpeningHours(String openingHours) {
|
2013-11-24 19:45:00 +01:00
|
|
|
setAdditionalInfo(OPENING_HOURS, openingHours);
|
2013-11-13 14:13:48 +01:00
|
|
|
}
|
|
|
|
|
2013-04-18 23:35:02 +02:00
|
|
|
|
|
|
|
}
|