2010-08-17 00:36:24 +02:00
|
|
|
package net.osmand.data;
|
2010-05-06 00:29:58 +02:00
|
|
|
|
2010-10-09 14:38:12 +02:00
|
|
|
import java.util.Collection;
|
|
|
|
|
2010-08-17 00:36:24 +02:00
|
|
|
import net.osmand.osm.Entity;
|
2010-10-09 14:38:12 +02:00
|
|
|
import net.osmand.osm.MapRenderingTypes;
|
2010-11-11 23:09:11 +01:00
|
|
|
import net.osmand.osm.Node;
|
2010-08-17 00:36:24 +02:00
|
|
|
import net.osmand.osm.Relation;
|
|
|
|
import net.osmand.osm.OSMSettings.OSMTagKey;
|
2010-05-06 00:29:58 +02:00
|
|
|
|
2010-05-27 13:02:02 +02:00
|
|
|
public class Amenity extends MapObject {
|
2010-05-06 00:29:58 +02:00
|
|
|
|
|
|
|
|
2010-05-16 23:49:11 +02:00
|
|
|
private String subType;
|
|
|
|
private AmenityType type;
|
2010-06-01 23:16:56 +02:00
|
|
|
private String openingHours;
|
2010-11-11 21:12:31 +01:00
|
|
|
private String phone;
|
|
|
|
private String site;
|
2010-05-06 00:29:58 +02:00
|
|
|
|
2010-05-23 09:59:12 +02:00
|
|
|
public Amenity(Entity entity){
|
2010-05-27 13:02:02 +02:00
|
|
|
super(entity);
|
2010-11-11 23:09:11 +01:00
|
|
|
// manipulate with id to distinguish way and nodes
|
|
|
|
this.id = entity.getId() << 1 + ((entity instanceof Node)? 0 : 1);
|
2010-10-09 14:38:12 +02:00
|
|
|
initTypeSubtype(entity, this);
|
2010-06-01 23:16:56 +02:00
|
|
|
this.openingHours = entity.getTag(OSMTagKey.OPENING_HOURS);
|
2010-11-11 23:09:11 +01:00
|
|
|
this.phone = entity.getTag(OSMTagKey.PHONE);
|
|
|
|
if (this.phone == null) {
|
|
|
|
this.phone = entity.getTag(OSMTagKey.CONTACT_PHONE);
|
|
|
|
}
|
|
|
|
this.site = entity.getTag(OSMTagKey.WIKIPEDIA);
|
|
|
|
if (this.site != null) {
|
|
|
|
if (!this.site.startsWith("http://")) { //$NON-NLS-1$
|
|
|
|
int i = this.site.indexOf(':');
|
|
|
|
if (i == -1) {
|
|
|
|
this.site = "http://en.wikipedia.org/wiki/" + this.site; //$NON-NLS-1$
|
|
|
|
} else {
|
|
|
|
this.site = "http://" + this.site.substring(0, i) + ".wikipedia.org/wiki/" + this.site.substring(i + 1); //$NON-NLS-1$ //$NON-NLS-2$
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
this.site = entity.getTag(OSMTagKey.WEBSITE);
|
|
|
|
if (this.site == null) {
|
|
|
|
this.site = entity.getTag(OSMTagKey.URL);
|
|
|
|
if (this.site == null) {
|
|
|
|
this.site = entity.getTag(OSMTagKey.CONTACT_WEBSITE);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2010-05-06 00:29:58 +02:00
|
|
|
}
|
|
|
|
|
2010-05-16 23:49:11 +02:00
|
|
|
public Amenity(){
|
|
|
|
}
|
|
|
|
|
2010-10-09 14:38:12 +02:00
|
|
|
private static AmenityType initTypeSubtype(Entity entity, Amenity init) {
|
|
|
|
Collection<String> keySet = entity.getTagKeySet();
|
|
|
|
if (!keySet.isEmpty()) {
|
|
|
|
for (String t : keySet) {
|
|
|
|
AmenityType type = MapRenderingTypes.getAmenityType(t, entity.getTag(t));
|
|
|
|
if (type != null) {
|
|
|
|
if (init != null) {
|
|
|
|
init.type = type;
|
|
|
|
init.subType = MapRenderingTypes.getAmenitySubtype(t, entity.getTag(t));
|
|
|
|
}
|
|
|
|
return type;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
for (String t : keySet) {
|
|
|
|
AmenityType type = MapRenderingTypes.getAmenityType(t, null);
|
|
|
|
if (type != null) {
|
|
|
|
if (init != null) {
|
|
|
|
init.type = type;
|
|
|
|
init.subType = MapRenderingTypes.getAmenitySubtype(t, entity.getTag(t));
|
|
|
|
}
|
|
|
|
return type;
|
|
|
|
}
|
|
|
|
}
|
2010-06-16 17:05:06 +02:00
|
|
|
}
|
2010-10-09 14:38:12 +02:00
|
|
|
return null;
|
2010-06-16 17:05:06 +02:00
|
|
|
}
|
2010-05-16 23:49:11 +02:00
|
|
|
public AmenityType getType(){
|
|
|
|
return type;
|
|
|
|
}
|
|
|
|
|
|
|
|
public String getSubType(){
|
|
|
|
return subType;
|
|
|
|
}
|
|
|
|
|
|
|
|
public void setType(AmenityType type) {
|
|
|
|
this.type = type;
|
|
|
|
}
|
|
|
|
|
|
|
|
public void setSubType(String subType) {
|
|
|
|
this.subType = subType;
|
|
|
|
}
|
|
|
|
|
2010-05-15 14:54:26 +02:00
|
|
|
public static boolean isAmenity(Entity n){
|
2010-08-13 01:46:45 +02:00
|
|
|
if(n instanceof Relation){
|
|
|
|
// it could be collection of amenities
|
|
|
|
return false;
|
|
|
|
}
|
2010-10-09 14:38:12 +02:00
|
|
|
return initTypeSubtype(n, null) != null;
|
2010-05-06 00:29:58 +02:00
|
|
|
}
|
2010-05-14 23:05:18 +02:00
|
|
|
|
2010-06-01 23:16:56 +02:00
|
|
|
public String getOpeningHours() {
|
|
|
|
return openingHours;
|
|
|
|
}
|
|
|
|
|
|
|
|
public void setOpeningHours(String openingHours) {
|
|
|
|
this.openingHours = openingHours;
|
|
|
|
}
|
|
|
|
|
2010-05-06 00:29:58 +02:00
|
|
|
|
2010-06-01 23:16:56 +02:00
|
|
|
public String getSimpleFormat(boolean en){
|
2010-06-19 19:01:40 +02:00
|
|
|
return AmenityType.toPublicString(type) + " : " + getStringWithoutType(en); //$NON-NLS-1$
|
2010-05-06 00:29:58 +02:00
|
|
|
}
|
|
|
|
|
2010-06-01 23:16:56 +02:00
|
|
|
public String getStringWithoutType(boolean en){
|
2010-06-02 00:15:19 +02:00
|
|
|
String n = getName(en);
|
|
|
|
if(n.length() == 0){
|
|
|
|
return getSubType();
|
|
|
|
}
|
2010-06-19 19:01:40 +02:00
|
|
|
return getSubType() + " " + n; //$NON-NLS-1$
|
2010-05-09 15:06:13 +02:00
|
|
|
}
|
|
|
|
|
2010-05-06 00:29:58 +02:00
|
|
|
@Override
|
|
|
|
public String toString() {
|
2010-06-01 23:16:56 +02:00
|
|
|
return getSimpleFormat(false);
|
2010-05-06 00:29:58 +02:00
|
|
|
}
|
|
|
|
|
2010-11-11 21:12:31 +01:00
|
|
|
public String getSite() {
|
|
|
|
return site;
|
|
|
|
}
|
|
|
|
|
|
|
|
public void setSite(String site) {
|
|
|
|
this.site = site;
|
|
|
|
}
|
|
|
|
|
|
|
|
public String getPhone() {
|
|
|
|
return phone;
|
|
|
|
}
|
|
|
|
|
|
|
|
public void setPhone(String phone) {
|
|
|
|
this.phone = phone;
|
|
|
|
}
|
|
|
|
|
2010-05-06 00:29:58 +02:00
|
|
|
|
2010-05-27 13:02:02 +02:00
|
|
|
public void doDataPreparation() {
|
|
|
|
|
|
|
|
}
|
2010-05-06 00:29:58 +02:00
|
|
|
|
|
|
|
}
|