Search in sources :

Example 1 with PoiNodeRef

use of io.jawg.osmcontributor.model.entities.PoiNodeRef 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;
}
Also used : Poi(io.jawg.osmcontributor.model.entities.Poi) PoiNodeRef(io.jawg.osmcontributor.model.entities.PoiNodeRef) Way(io.jawg.osmcontributor.model.entities.Way) HashSet(java.util.HashSet)

Example 2 with PoiNodeRef

use of io.jawg.osmcontributor.model.entities.PoiNodeRef in project osm-contributor by jawg.

the class MapFragment method updateVectorials.

public void updateVectorials(Set<Way> ways, TreeSet<Double> levels) {
    for (Way way : ways) {
        mapboxMap.addPolyline(way.getPolylineOptions());
        for (PoiNodeRef poiNodeRef : way.getPoiNodeRefs()) {
            WayMarkerOptions wayMarkerOptions = new WayMarkerOptions().position(poiNodeRef.getPosition()).poiNodeRef(poiNodeRef).icon(IconFactory.getInstance(getActivity()).fromBitmap(bitmapHandler.getNodeRefBitmap(PoiNodeRef.State.NONE)));
            addWayMarker(wayMarkerOptions);
            markersNodeRef.put(poiNodeRef.getId(), wayMarkerOptions);
            polylinesWays.put(poiNodeRef.getId(), way.getPolylineOptions());
        }
    }
}
Also used : WayMarkerOptions(io.jawg.osmcontributor.ui.utils.views.map.marker.WayMarkerOptions) PoiNodeRef(io.jawg.osmcontributor.model.entities.PoiNodeRef) Way(io.jawg.osmcontributor.model.entities.Way)

Example 3 with PoiNodeRef

use of io.jawg.osmcontributor.model.entities.PoiNodeRef in project osm-contributor by jawg.

the class PoiManager method savePoiNoTransaction.

/**
 * Method saving a poi and all the associated foreign collections without transaction management.
 * <p/>
 * Do not call the DAO directly to save a poi, use this method.
 *
 * @param poi The poi to save
 * @return The saved poi
 * @see #savePoi(Poi)
 */
private Poi savePoiNoTransaction(Poi poi) {
    List<PoiTag> poiTagsToRemove = poiTagDao.queryByPoiId(poi.getId());
    poiTagsToRemove.removeAll(poi.getTags());
    for (PoiTag poiTag : poiTagsToRemove) {
        poiTagDao.delete(poiTag);
    }
    List<PoiNodeRef> poiNodeRefsToRemove = poiNodeRefDao.queryByPoiId(poi.getId());
    poiNodeRefsToRemove.removeAll(poi.getNodeRefs());
    for (PoiNodeRef poiNodeRef : poiNodeRefsToRemove) {
        poiNodeRefDao.delete(poiNodeRef);
    }
    poiDao.createOrUpdate(poi);
    if (poi.getTags() != null) {
        for (PoiTag poiTag : poi.getTags()) {
            poiTag.setPoi(poi);
            poiTagDao.createOrUpdate(poiTag);
        }
    }
    if (poi.getNodeRefs() != null) {
        for (PoiNodeRef poiNodeRef : poi.getNodeRefs()) {
            poiNodeRef.setPoi(poi);
            poiNodeRefDao.createOrUpdate(poiNodeRef);
        }
    }
    return poi;
}
Also used : PoiTag(io.jawg.osmcontributor.model.entities.PoiTag) PoiNodeRef(io.jawg.osmcontributor.model.entities.PoiNodeRef)

Example 4 with PoiNodeRef

use of io.jawg.osmcontributor.model.entities.PoiNodeRef in project osm-contributor by jawg.

the class PoiManager method onPleaseLoadPoisToUpdateEvent.

@Subscribe(threadMode = ThreadMode.ASYNC)
public void onPleaseLoadPoisToUpdateEvent(PleaseLoadPoisToUpdateEvent event) {
    List<Poi> updatedPois = poiDao.queryForAllUpdated();
    List<Poi> newPois = poiDao.queryForAllNew();
    List<Poi> toDeletePois = poiDao.queryToDelete();
    List<PoiNodeRef> wayPoiNodeRef = poiNodeRefDao.queryAllToUpdate();
    List<PoiUpdateWrapper> allPois = new ArrayList<>();
    for (Poi p : updatedPois) {
        Long oldPoiId = p.getOldPoiId();
        if (oldPoiId != null) {
            allPois.add(new PoiUpdateWrapper(true, p, poiDao.queryForId(oldPoiId), null, PoiUpdateWrapper.PoiAction.UPDATE));
        }
    }
    for (Poi p : newPois) {
        allPois.add(new PoiUpdateWrapper(true, p, null, null, PoiUpdateWrapper.PoiAction.CREATE));
    }
    for (Poi p : toDeletePois) {
        allPois.add(new PoiUpdateWrapper(true, p, poiDao.queryForId(p.getOldPoiId()), null, PoiUpdateWrapper.PoiAction.DELETED));
    }
    for (PoiNodeRef p : wayPoiNodeRef) {
        allPois.add(new PoiUpdateWrapper(false, null, null, p, PoiUpdateWrapper.PoiAction.UPDATE));
    }
    bus.post(new PoisToUpdateLoadedEvent(allPois));
}
Also used : PoisToUpdateLoadedEvent(io.jawg.osmcontributor.model.events.PoisToUpdateLoadedEvent) ArrayList(java.util.ArrayList) Poi(io.jawg.osmcontributor.model.entities.Poi) PoiNodeRef(io.jawg.osmcontributor.model.entities.PoiNodeRef) PoiUpdateWrapper(io.jawg.osmcontributor.utils.upload.PoiUpdateWrapper) Subscribe(org.greenrobot.eventbus.Subscribe)

Example 5 with PoiNodeRef

use of io.jawg.osmcontributor.model.entities.PoiNodeRef in project osm-contributor by jawg.

the class PoiManager method revertPoiNodeRef.

/**
 * Get the backup data and put it back in the active NodeRefPoi
 *
 * @param poiNodeRefId The Id of the PoiNodeRef to revert.
 */
private PoiNodeRef revertPoiNodeRef(Long poiNodeRefId) {
    PoiNodeRef poiNodeRef = poiNodeRefDao.queryForId(poiNodeRefId);
    PoiNodeRef backup;
    Long oldId = poiNodeRef.getOldPoiId();
    if (oldId != null) {
        backup = poiNodeRefDao.queryForId(oldId);
        poiNodeRef.setLatitude(backup.getLatitude());
        poiNodeRef.setLongitude(backup.getLongitude());
        poiNodeRefDao.deleteById(oldId);
    }
    poiNodeRef.setUpdated(false);
    poiNodeRef.setOld(false);
    poiNodeRef.setOldPoiId(null);
    poiNodeRefDao.createOrUpdate(poiNodeRef);
    return poiNodeRef;
}
Also used : PoiNodeRef(io.jawg.osmcontributor.model.entities.PoiNodeRef)

Aggregations

PoiNodeRef (io.jawg.osmcontributor.model.entities.PoiNodeRef)13 Poi (io.jawg.osmcontributor.model.entities.Poi)5 ArrayList (java.util.ArrayList)4 LatLng (com.mapbox.mapboxsdk.geometry.LatLng)3 Subscribe (org.greenrobot.eventbus.Subscribe)3 PoiTag (io.jawg.osmcontributor.model.entities.PoiTag)2 Way (io.jawg.osmcontributor.model.entities.Way)2 NdDto (io.jawg.osmcontributor.rest.dtos.osm.NdDto)2 PolylineOptions (com.mapbox.mapboxsdk.annotations.PolylineOptions)1 PoiType (io.jawg.osmcontributor.model.entities.PoiType)1 PoisToUpdateLoadedEvent (io.jawg.osmcontributor.model.events.PoisToUpdateLoadedEvent)1 RevertFinishedEvent (io.jawg.osmcontributor.model.events.RevertFinishedEvent)1 TagDto (io.jawg.osmcontributor.rest.dtos.osm.TagDto)1 WayDto (io.jawg.osmcontributor.rest.dtos.osm.WayDto)1 NoteCommentDialogFragment (io.jawg.osmcontributor.ui.dialogs.NoteCommentDialogFragment)1 PleaseApplyNodeRefPositionChange (io.jawg.osmcontributor.ui.events.edition.PleaseApplyNodeRefPositionChange)1 PleaseApplyPoiPositionChange (io.jawg.osmcontributor.ui.events.edition.PleaseApplyPoiPositionChange)1 WayMarkerOptions (io.jawg.osmcontributor.ui.utils.views.map.marker.WayMarkerOptions)1 PoiUpdateWrapper (io.jawg.osmcontributor.utils.upload.PoiUpdateWrapper)1 HashMap (java.util.HashMap)1