Search in sources :

Example 6 with PoiNodeRef

use of io.jawg.osmcontributor.model.entities.PoiNodeRef 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;
}
Also used : PoiTag(io.jawg.osmcontributor.model.entities.PoiTag) NdDto(io.jawg.osmcontributor.rest.dtos.osm.NdDto) ArrayList(java.util.ArrayList) PoiType(io.jawg.osmcontributor.model.entities.PoiType) TagDto(io.jawg.osmcontributor.rest.dtos.osm.TagDto) Poi(io.jawg.osmcontributor.model.entities.Poi) PoiNodeRef(io.jawg.osmcontributor.model.entities.PoiNodeRef)

Example 7 with PoiNodeRef

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

the class PoiMapper method convertPoiToWayDto.

public WayDto convertPoiToWayDto(Poi poi, String changeSetId) {
    WayDto wayDto = new WayDto();
    wayDto.setId(poi.getBackendId());
    wayDto.setChangeset(changeSetId);
    if (poi.getVersion() != null) {
        wayDto.setVersion(Integer.parseInt(poi.getVersion()));
    }
    wayDto.setTagsDtoList(poiTagMapper.convertFromPoiTag(poi.getTags()));
    List<NdDto> ndDtos = new ArrayList<>();
    for (PoiNodeRef poiNodeRef : poi.getNodeRefs()) {
        NdDto ndDto = new NdDto();
        ndDto.setRef(poiNodeRef.getNodeBackendId());
    }
    wayDto.setNdDtoList(ndDtos);
    return wayDto;
}
Also used : NdDto(io.jawg.osmcontributor.rest.dtos.osm.NdDto) WayDto(io.jawg.osmcontributor.rest.dtos.osm.WayDto) ArrayList(java.util.ArrayList) PoiNodeRef(io.jawg.osmcontributor.model.entities.PoiNodeRef)

Example 8 with PoiNodeRef

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

the class EditPoiManager method onPleaseApplyNodeRefPositionChange.

@Subscribe(threadMode = ThreadMode.ASYNC)
public void onPleaseApplyNodeRefPositionChange(PleaseApplyNodeRefPositionChange event) {
    Timber.d("Please apply noderef position change");
    LatLng newLatLng = event.getPoiPosition();
    // apply changes on the noderef
    PoiNodeRef poiNodeRef = poiNodeRefDao.queryForId(event.getPoiId());
    poiNodeRef.setOldPoiId(saveOldVersionOfPoiNodeRef(poiNodeRef));
    poiNodeRef.setLongitude(newLatLng.getLongitude());
    poiNodeRef.setLatitude(newLatLng.getLatitude());
    poiNodeRef.setUpdated(true);
    poiNodeRefDao.createOrUpdate(poiNodeRef);
}
Also used : LatLng(com.mapbox.mapboxsdk.geometry.LatLng) PoiNodeRef(io.jawg.osmcontributor.model.entities.PoiNodeRef) Subscribe(org.greenrobot.eventbus.Subscribe)

Example 9 with PoiNodeRef

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

the class MapFragment method buildEditionPolygon.

private void buildEditionPolygon() {
    // Current selected poiNodeRef
    PoiNodeRef currentPoiNodeRef = wayMarkerSelected.getPoiNodeRef();
    // Polyline related to this poiNodeRef
    PolylineOptions currentPolyline = polylinesWays.get(currentPoiNodeRef.getId());
    // Item of the poiNodeRef in the polilyne
    int indexOfPoiNodeRef = currentPolyline.getPoints().indexOf(new LatLng(currentPoiNodeRef.getLatitude(), currentPoiNodeRef.getLongitude()));
    LatLng previousPoint = currentPolyline.getPoints().get(indexOfPoiNodeRef == 0 ? indexOfPoiNodeRef + 1 : indexOfPoiNodeRef - 1);
    LatLng nextPoint = currentPolyline.getPoints().get(indexOfPoiNodeRef == currentPolyline.getPoints().size() - 1 ? indexOfPoiNodeRef - 1 : indexOfPoiNodeRef + 1);
    editionPolyline = new PolylineOptions().add(previousPoint, currentPolyline.getPoints().get(indexOfPoiNodeRef), nextPoint).alpha(0.4f).width(1.8f).color(Color.parseColor("#F57C00"));
    mapboxMap.addPolyline(editionPolyline);
}
Also used : LatLng(com.mapbox.mapboxsdk.geometry.LatLng) PoiNodeRef(io.jawg.osmcontributor.model.entities.PoiNodeRef) PolylineOptions(com.mapbox.mapboxsdk.annotations.PolylineOptions)

Example 10 with PoiNodeRef

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

the class MapFragment method confirmPosition.

private void confirmPosition() {
    LatLng newPoiPosition;
    LatLng pos;
    switch(mapMode) {
        case POI_CREATION:
            if (getZoomLevel() < zoomVectorial) {
                changeMapZoomSmooth(15d);
            }
            createPoi();
            break;
        case NOTE_CREATION:
            pos = mapboxMap.getCameraPosition().target;
            NoteCommentDialogFragment dialog = NoteCommentDialogFragment.newInstance(pos.getLatitude(), pos.getLongitude());
            dialog.show(getActivity().getFragmentManager(), "dialog");
            break;
        case POI_POSITION_EDITION:
            Poi poi = (Poi) markerSelected.getRelatedObject();
            newPoiPosition = mapboxMap.getCameraPosition().target;
            eventBus.post(new PleaseApplyPoiPositionChange(newPoiPosition, poi.getId()));
            markerSelected.setPosition(newPoiPosition);
            markerSelected.setIcon(IconFactory.getInstance(getActivity()).fromBitmap(bitmapHandler.getMarkerBitmap(poi.getType(), Poi.computeState(false, false, true))));
            poi.setUpdated(true);
            mapboxMap.updateMarker(markerSelected);
            switchMode(MapMode.DETAIL_POI);
            break;
        case NODE_REF_POSITION_EDITION:
            PoiNodeRef poiNodeRef = wayMarkerSelected.getPoiNodeRef();
            newPoiPosition = mapboxMap.getCameraPosition().target;
            eventBus.post(new PleaseApplyNodeRefPositionChange(newPoiPosition, poiNodeRef.getId()));
            wayMarkerSelected.setPosition(newPoiPosition);
            wayMarkerSelected.setIcon(IconFactory.getInstance(getActivity()).fromBitmap(bitmapHandler.getNodeRefBitmap(PoiNodeRef.State.SELECTED)));
            removePolyline(editionPolyline);
            switchMode(MapMode.WAY_EDITION);
            break;
        case DETAIL_POI:
            getActivity().finish();
            break;
        default:
            break;
    }
}
Also used : PleaseApplyNodeRefPositionChange(io.jawg.osmcontributor.ui.events.edition.PleaseApplyNodeRefPositionChange) PleaseApplyPoiPositionChange(io.jawg.osmcontributor.ui.events.edition.PleaseApplyPoiPositionChange) LatLng(com.mapbox.mapboxsdk.geometry.LatLng) Poi(io.jawg.osmcontributor.model.entities.Poi) PoiNodeRef(io.jawg.osmcontributor.model.entities.PoiNodeRef) NoteCommentDialogFragment(io.jawg.osmcontributor.ui.dialogs.NoteCommentDialogFragment)

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