src/main/java/de/blau/android/osm/StorageDelegator.java
/**
     * Replace a Node in a way with a new one
     * 
     * @param node the node to replace
     * @param way the Way
     * @return the new Node
     */
Replace a Node in a way with a new one

@param node the node to replace
@param way the Way
@return the new Node
Replace a Node in a way with a new one @param node the node to replace @param way the Way @return the new Node
@NonNull
    private Node replaceWayNode(@NonNull final Node node, @NonNull final Way way) {
        List<OsmElement> changedElements = new ArrayList<>();
        dirty = true;
        Node newNode = factory.createNodeWithNewId(node.lat, node.lon);
        newNode.addTags(node.getTags());
        insertElementUnsafe(newNode);
        changedElements.add(newNode);
        undo.save(way);
        List<Node> nodes = way.getNodes();
        if (way.isClosed() && way.isEndNode(node)) {
             note:
             this needs to be called before the 1st node is replaced
             or else the way won't be closed anymore
            nodes.set(nodes.size() - 1, newNode);
        }
        nodes.set(nodes.indexOf(node), newNode);
        way.updateState(OsmElement.STATE_MODIFIED);
        apiStorage.insertElementSafe(way);
        changedElements.add(way);
         check if node is in a relation, if yes, add to new node
         should probably check for restrictions
        if (node.hasParentRelations()) {
            List<Relation> relations = node.getParentRelations();
            /*
             * iterate through relations, for all except restrictions add the new node to the relation, for now simply
             * after the old node
             */
            for (Relation r : relations) {
                RelationMember rm = r.getMember(node);
                undo.save(r);
                String type = r.getTagWithKey(Tags.KEY_TYPE);
                if (type != null) {
                    if (type.equals(Tags.VALUE_RESTRICTION)) {
                         doing nothing for now at least gives a chance of being right :-)
                    } else {
                        RelationMember newMember = new RelationMember(rm.getRole(), newNode);
                        r.addMemberAfter(rm, newMember);
                        newNode.addParentRelation(r);
                    }
                } else {
                    RelationMember newMember = new RelationMember(rm.getRole(), newNode);
                    r.addMemberAfter(rm, newMember);
                    newNode.addParentRelation(r);
                }
                r.updateState(OsmElement.STATE_MODIFIED);
                apiStorage.insertElementSafe(r);
                changedElements.add(r);
            }
        }
        onElementChanged(null, changedElements);
        return newNode;
    }
@ NonNull private Node replaceWayNode ( @ NonNull final Node node , @ NonNull final Way way ) { List < OsmElement > changedElements = new ArrayList < > ( ) ; dirty = true ; Node newNode = factory . createNodeWithNewId ( node . lat , node . lon ) ; newNode . addTags ( node . getTags ( ) ) ; insertElementUnsafe ( newNode ) ; changedElements . add ( newNode ) ; undo . save ( way ) ; List < Node > nodes = way . getNodes ( ) ; if ( way . isClosed ( ) && way . isEndNode ( node ) ) { nodes . set ( nodes . size ( ) - 1 , newNode ) ; } nodes . set ( nodes . indexOf ( node ) , newNode ) ; way . updateState ( OsmElement . STATE_MODIFIED ) ; apiStorage . insertElementSafe ( way ) ; changedElements . add ( way ) ; if ( node . hasParentRelations ( ) ) { List < Relation > relations = node . getParentRelations ( ) ; /*
             * iterate through relations, for all except restrictions add the new node to the relation, for now simply
             * after the old node
             */ for ( Relation r : relations ) { RelationMember rm = r . getMember ( node ) ; undo . save ( r ) ; String type = r . getTagWithKey ( Tags . KEY_TYPE ) ; if ( type != null ) { if ( type . equals ( Tags . VALUE_RESTRICTION ) ) { } else { RelationMember newMember = new RelationMember ( rm . getRole ( ) , newNode ) ; r . addMemberAfter ( rm , newMember ) ; newNode . addParentRelation ( r ) ; } } else { RelationMember newMember = new RelationMember ( rm . getRole ( ) , newNode ) ; r . addMemberAfter ( rm , newMember ) ; newNode . addParentRelation ( r ) ; } r . updateState ( OsmElement . STATE_MODIFIED ) ; apiStorage . insertElementSafe ( r ) ; changedElements . add ( r ) ; } } onElementChanged ( null , changedElements ) ; return newNode ; }
Replace a Node in a way with a new one
Replace a Node in a way with a new one
// create a new node that duplicates the given node // replace the given node in the way with the new node // replace last occurrence too // // note: // this needs to be called before the 1st node is replaced // or else the way won't be closed anymore // check if node is in a relation, if yes, add to new node // should probably check for restrictions // doing nothing for now at least gives a chance of being right :-)