use of io.jawg.osmcontributor.model.entities.PoiType in project osm-contributor by jawg.
the class PoiMapper method convertDtoToPoi.
public Poi convertDtoToPoi(boolean typeFiltering, List<PoiType> availableTypes, PoiDto dto) {
List<PoiNodeRef> nodeRefs = new ArrayList<>();
List<PoiTag> tags = new ArrayList<>();
PoiType type;
if (FlavorUtils.isBus()) {
type = availableTypes.get(0);
} else {
type = findType(dto, availableTypes);
}
if (type == null && typeFiltering) {
return null;
}
Poi poi = new Poi();
poi.setType(type);
poi.setLatitude(dto.getLat());
poi.setLongitude(dto.getLon());
poi.setBackendId(dto.getId());
poi.setVersion(String.valueOf(dto.getVersion()));
poi.setUpdated(false);
poi.setUpdateDate(dto.getTimestamp());
poi.setWay(dto.isWay());
for (TagDto tagDto : dto.getTagsDtoList()) {
PoiTag tag = new PoiTag();
tag.setPoi(poi);
tag.setKey(tagDto.getKey());
tag.setValue(tagDto.getValue());
tags.add(tag);
if (tag.getKey().equals("name")) {
poi.setName(tag.getValue());
}
if (tag.getKey().equals("level")) {
poi.setLevel(tag.getValue());
}
}
poi.setTags(tags);
int counter = 0;
for (NdDto ndDto : dto.getNdDtoList()) {
PoiNodeRef nodeRef = new PoiNodeRef();
nodeRef.setPoi(poi);
nodeRef.setNodeBackendId(ndDto.getRef());
nodeRef.setOrdinal(counter++);
nodeRef.setLatitude(ndDto.getLat());
nodeRef.setLongitude(ndDto.getLon());
nodeRef.setUpdated(false);
nodeRefs.add(nodeRef);
}
poi.setNodeRefs(nodeRefs);
return poi;
}
use of io.jawg.osmcontributor.model.entities.PoiType in project osm-contributor by jawg.
the class MapActivity method onPleaseInitializeDrawer.
@Subscribe(threadMode = ThreadMode.MAIN)
public void onPleaseInitializeDrawer(PleaseInitializeDrawer event) {
Timber.d("initializing drawer with poiType");
if (filtersItemList == null) {
filtersItemList = new ArrayList<>();
}
List<PoiType> poiTypes = event.getPoiTypes();
poiTypesHidden = event.getPoiTypeHidden();
filters.clear();
for (PoiType poiType : poiTypes) {
Long id = poiType.getId();
filters.add(new PoiTypeFilter(poiType.getName(), id, poiType.getIcon(), !poiTypesHidden.contains(id)));
}
Collections.sort(filters);
Menu menu = filterView.getMenu();
int order = 1;
for (PoiTypeFilter poiTypeFilter : filters) {
PoiTypeFilter nextPoiTypeFilter = null;
if (order < filters.size()) {
nextPoiTypeFilter = filters.get(order);
}
// Add only menu if not present
if (menu.findItem(poiTypeFilter.getPoiTypeId().intValue()) == null) {
filtersItemList.add(menu.add(Menu.NONE, poiTypeFilter.getPoiTypeId().intValue(), (nextPoiTypeFilter != null ? (poiTypeFilter.compareTo(nextPoiTypeFilter) > 0 ? order - 1 : order) : order), poiTypeFilter.getPoiTypeName()).setChecked(poiTypeFilter.isActive()).setIcon(bitmapHandler.getDrawable(poiTypeFilter.getPoiTypeIconName())));
}
order++;
}
// Remove only filter removed by user
if (filters.size() < filtersItemList.size()) {
List<MenuItem> temp = new ArrayList<>(filters.size());
for (MenuItem menuItem : filtersItemList) {
PoiTypeFilter poiTypeFilter = new PoiTypeFilter("", (long) menuItem.getItemId(), "", true);
if (!filters.contains(poiTypeFilter)) {
menu.removeItem(poiTypeFilter.getPoiTypeId().intValue());
} else {
temp.add(menuItem);
}
}
filtersItemList.clear();
filtersItemList.addAll(temp);
temp.clear();
}
selectAllMenuItem.setChecked(poiTypesHidden.isEmpty());
}
use of io.jawg.osmcontributor.model.entities.PoiType in project osm-contributor by jawg.
the class TypeManager method onInternalUpdatePoiTagsEvent.
@Subscribe(threadMode = ThreadMode.ASYNC)
public void onInternalUpdatePoiTagsEvent(InternalUpdatePoiTagsEvent event) {
PoiType poiType = event.getPoiType();
poiManager.savePoiType(poiType);
bus.post(new PoiTagsUpdatedEvent(poiType));
}
use of io.jawg.osmcontributor.model.entities.PoiType in project osm-contributor by jawg.
the class TypeManager method getPoiTypeSuggested.
// *********************************
// ************ private ************
// *********************************
/**
* Return the PoiType suggested for a given key.
*
* @param key The name of the wished PoiType.
* @return The suggested PoiType.
*/
private PoiType getPoiTypeSuggested(String key) {
if (StringUtils.isEmpty(key)) {
return null;
}
Wiki wiki = tagInfoRestClient.getWikiPages(key);
PoiType poiType = new PoiType();
poiType.setName(key);
poiType.setIcon(key);
poiType.setLastUse(DateTime.now());
int ordinal = 0;
List<PoiTypeTag> poiTypeTags = new ArrayList<>();
// Request for the English wiki and keep the tags of the tags_combination field.
for (WikiDataDto data : wiki.getDatas()) {
if ("en".equals(data.getLang())) {
for (String tagCombination : data.getTagsCombination()) {
String[] splitResult = tagCombination.split("=");
if (splitResult.length > 1) {
poiTypeTags.add(PoiTypeTag.builder().key(splitResult[0]).value(splitResult[1]).mandatory(true).poiType(poiType).ordinal(ordinal++).build());
} else {
poiTypeTags.add(PoiTypeTag.builder().key(tagCombination).mandatory(false).poiType(poiType).ordinal(ordinal++).build());
}
}
break;
}
}
// If there was no relevant information in the English wiki, query for tags combinations.
if (poiTypeTags.size() == 0) {
CombinationsDto combinationsDto = tagInfoRestClient.getCombinations(key, 1, 5);
for (CombinationsDataDto data : combinationsDto.getData()) {
if (tagsGroup.contains(data.getOtherKey())) {
poiTypeTags.add(PoiTypeTag.builder().key(data.getOtherKey()).value(key).mandatory(true).poiType(poiType).ordinal(ordinal++).build());
} else {
poiTypeTags.add(PoiTypeTag.builder().key(data.getOtherKey()).mandatory(false).poiType(poiType).ordinal(ordinal++).build());
}
}
}
poiType.setTags(poiTypeTags);
return poiType;
}
use of io.jawg.osmcontributor.model.entities.PoiType in project osm-contributor by jawg.
the class TypeManager method onInternalSavePoiTagEvent.
@Subscribe(threadMode = ThreadMode.ASYNC)
public void onInternalSavePoiTagEvent(InternalSavePoiTagEvent event) {
PoiTypeTag poiTypeTag = event.getPoiTypeTag();
PoiType poiType = poiTypeTag.getPoiType();
poiManager.savePoiType(poiType);
bus.post(new PoiTagCreatedEvent(poiTypeTag));
}
Aggregations