Search in sources :

Example 1 with Poi

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);
    }
}
Also used : OsmDto(io.jawg.osmcontributor.rest.dtos.osm.OsmDto) Poi(io.jawg.osmcontributor.model.entities.Poi)

Example 2 with Poi

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;
}
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 3 with Poi

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);
    }
}
Also used : PleaseLoadLastUsedPoiType(io.jawg.osmcontributor.ui.events.map.PleaseLoadLastUsedPoiType) Bitmap(android.graphics.Bitmap) MapMode(io.jawg.osmcontributor.ui.utils.MapMode) Poi(io.jawg.osmcontributor.model.entities.Poi)

Example 4 with Poi

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);
}
Also used : CameraPosition(com.mapbox.mapboxsdk.camera.CameraPosition) Poi(io.jawg.osmcontributor.model.entities.Poi) LatLng(com.mapbox.mapboxsdk.geometry.LatLng) Subscribe(org.greenrobot.eventbus.Subscribe)

Example 5 with Poi

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);
}
Also used : ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) Poi(io.jawg.osmcontributor.model.entities.Poi) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap)

Aggregations

Poi (io.jawg.osmcontributor.model.entities.Poi)36 ArrayList (java.util.ArrayList)9 Subscribe (org.greenrobot.eventbus.Subscribe)9 HashMap (java.util.HashMap)7 PoiNodeRef (io.jawg.osmcontributor.model.entities.PoiNodeRef)5 Bitmap (android.graphics.Bitmap)3 LatLng (com.mapbox.mapboxsdk.geometry.LatLng)3 PoiTag (io.jawg.osmcontributor.model.entities.PoiTag)3 Note (io.jawg.osmcontributor.model.entities.Note)2 PoiType (io.jawg.osmcontributor.model.entities.PoiType)2 PoiTypeTag (io.jawg.osmcontributor.model.entities.PoiTypeTag)2 PoiForEditionLoadedEvent (io.jawg.osmcontributor.model.events.PoiForEditionLoadedEvent)2 OsmDto (io.jawg.osmcontributor.rest.dtos.osm.OsmDto)2 PoiChangesApplyEvent (io.jawg.osmcontributor.ui.events.edition.PoiChangesApplyEvent)2 PleaseChangeValuesDetailPoiFragmentEvent (io.jawg.osmcontributor.ui.events.map.PleaseChangeValuesDetailPoiFragmentEvent)2 PoiManager (io.jawg.osmcontributor.ui.managers.PoiManager)2 MapElement (io.jawg.osmcontributor.utils.core.MapElement)2 IOException (java.io.IOException)2 HashSet (java.util.HashSet)2 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)2