use of io.jawg.osmcontributor.model.entities.Poi in project osm-contributor by jawg.
the class PoiAssetLoader method loadPoisFromAssets.
/**
* Load the POIs from the pois.osm file located in the assets directory.
*
* @return the loaded POIs.
*/
public List<Poi> loadPoisFromAssets() {
try {
OsmDto read = simple.read(OsmDto.class, application.getAssets().open("pois.osm"));
List<Poi> pois = poiMapper.convertDtosToPois(read.getNodeDtoList());
pois.addAll(poiMapper.convertDtosToPois(read.getWayDtoList()));
return pois;
} catch (Exception e) {
Timber.e(e, "Error while loading POIS from assets");
throw new RuntimeException(e);
}
}
use of io.jawg.osmcontributor.model.entities.Poi in project osm-contributor by jawg.
the class WayMapper method poisToWays.
public static Set<Way> poisToWays(List<Poi> pois) {
Set<Way> ways = new HashSet<>();
if (pois != null && !pois.isEmpty()) {
for (Poi poi : pois) {
Way way = new Way(poi);
for (PoiNodeRef nodeRef : poi.getNodeRefs()) {
// Properties of a node in way edition
way.add(nodeRef);
}
ways.add(way);
}
}
return ways;
}
use of io.jawg.osmcontributor.model.entities.Poi in project osm-contributor by jawg.
the class MapFragment method switchMode.
public void switchMode(MapMode mode) {
mapMode = mode;
Bitmap bitmap;
switchToolbarMode(mapMode);
editNodeRefPosition.setVisibility(View.GONE);
// progressBar.setVisibility(View.GONE);
final MapMode.MapModeProperties properties = mode.getProperties();
if (properties.isUnSelectIcon()) {
unselectMarker();
}
showFloatingButtonAddPoi(properties.isShowAddPoiFab());
displayPoiTypePicker();
displayPoiDetailBanner(properties.isShowPoiBanner());
displayNoteDetailBanner(properties.isShowNodeBanner());
switch(mode) {
case DETAIL_POI:
break;
case DETAIL_NOTE:
break;
case TYPE_PICKER:
eventBus.post(new PleaseLoadLastUsedPoiType());
break;
case POI_CREATION:
animationPoiCreation();
break;
case NOTE_CREATION:
noteSelected();
animationPoiCreation();
break;
case POI_POSITION_EDITION:
// This marker is being moved
bitmap = bitmapHandler.getMarkerBitmap(((Poi) markerSelected.getRelatedObject()).getType(), Poi.computeState(false, true, false));
creationPin.setImageBitmap(bitmap);
break;
case NODE_REF_POSITION_EDITION:
wayCreationPin.setImageBitmap(bitmapHandler.getNodeRefBitmap(PoiNodeRef.State.MOVING));
break;
case WAY_EDITION:
if (getZoomLevel() < zoomVectorial) {
changeMapZoomSmooth(configManager.getZoomVectorial());
}
loadAreaForEdition();
break;
default:
poiTypeSelected = null;
poiTypeEditText.setText("");
clearAllNodeRef();
switchToolbarMode(mapMode);
displayHomeButton(true);
unselectMarker();
break;
}
// the marker is displayed at the end of the animation
displayCreationPin(properties.isShowCreationPin());
wayCreationPin.setVisibility(properties.isShowCreationPin() ? View.VISIBLE : View.GONE);
if (addPoiFloatingMenu.isOpened()) {
addPoiFloatingMenu.toggle(true);
}
}
use of io.jawg.osmcontributor.model.entities.Poi in project osm-contributor by jawg.
the class MapFragment method onPleaseDuplicatePoiFromMapEvent.
/*-----------------------------------------------------------
* POI DUPLICATION
*---------------------------------------------------------*/
@Subscribe(threadMode = ThreadMode.MAIN)
public void onPleaseDuplicatePoiFromMapEvent(PleaseDuplicatePoiEvent event) {
Poi poi = (Poi) markerSelected.getRelatedObject();
poiTypeSelected(poi.getType());
mapboxMap.setCameraPosition(new CameraPosition.Builder().target(new LatLng(poi.getLatitude(), poi.getLongitude())).build());
switchMode(MapMode.POI_CREATION);
}
use of io.jawg.osmcontributor.model.entities.Poi in project osm-contributor by jawg.
the class PoiManager method mergeFromOsmPois.
/**
* Merge POIs in parameters to those already in the database.
*
* @param remotePois The POIs to merge.
*/
public void mergeFromOsmPois(List<Poi> remotePois, Box box) {
List<Poi> toMergePois = new ArrayList<>();
Map<String, Poi> remotePoisMap = new HashMap<>();
// Map remote Poi backend Ids
for (Poi poi : remotePois) {
remotePoisMap.put(poi.getBackendId(), poi);
}
// List matching Pois
List<Poi> localPois = poiDao.queryForAllInRect(box);
Map<String, Poi> localPoisMap = new ConcurrentHashMap<>();
// Map matching local Pois
for (Poi localPoi : localPois) {
localPoisMap.put(localPoi.getBackendId(), localPoi);
}
// Browse remote pois
for (Poi remotePoi : remotePois) {
Poi localPoi = localPoisMap.remove(remotePoi.getBackendId());
Long localVersion = -1L;
// If localPoi is versioned
if (localPoi != null && localPoi.getVersion() != null) {
localVersion = Long.valueOf(localPoi.getVersion());
}
// Compute version delta
if (Long.valueOf(remotePoi.getVersion()) > localVersion) {
// Remote version is newer, override existing one
if (localPoi != null) {
remotePoi.setId(localPoi.getId());
}
// This Poi should be updated
toMergePois.add(remotePoi);
}
}
poiDao.delete(localPoisMap.values());
// savePois of either new or existing Pois
savePois(toMergePois);
}
Aggregations