コード例 #1
0
ファイル: drag_node.js プロジェクト: mapillary/iD
 function connectAnnotation(nodeEntity, targetEntity) {
     var nodeGeometry = nodeEntity.geometry(context.graph());
     var targetGeometry = targetEntity.geometry(context.graph());
     if (nodeGeometry === 'vertex' && targetGeometry === 'vertex') {
         var nodeParentWayIDs = context.graph().parentWays(nodeEntity);
         var targetParentWayIDs = context.graph().parentWays(targetEntity);
         var sharedParentWays = _intersection(nodeParentWayIDs, targetParentWayIDs);
         // if both vertices are part of the same way
         if (sharedParentWays.length !== 0) {
             // if the nodes are next to each other, they are merged
             if (sharedParentWays[0].areAdjacent(nodeEntity.id, targetEntity.id)) {
                 return t('operations.connect.annotation.from_vertex.to_adjacent_vertex');
             }
             return t('operations.connect.annotation.from_vertex.to_sibling_vertex');
         }
     }
     return t('operations.connect.annotation.from_' + nodeGeometry + '.to_' + targetGeometry);
 }
コード例 #2
0
ファイル: move.js プロジェクト: Stalfur/iD
        function cacheIntersections(ids) {
            function isEndpoint(way, id) {
                return !way.isClosed() && !!way.affix(id);
            }

            for (var i = 0; i < ids.length; i++) {
                var id = ids[i];

                // consider only intersections with 1 moved and 1 unmoved way.
                var childNodes = graph.childNodes(graph.entity(id));
                for (var j = 0; j < childNodes.length; j++) {
                    var node = childNodes[j];
                    var parents = graph.parentWays(node);
                    if (parents.length !== 2) continue;

                    var moved = graph.entity(id);
                    var unmoved = null;
                    for (var k = 0; k < parents.length; k++) {
                        var way = parents[k];
                        if (!cache.moving[way.id]) {
                            unmoved = way;
                            break;
                        }
                    }
                    if (!unmoved) continue;

                    // exclude ways that are overly connected..
                    if (_intersection(moved.nodes, unmoved.nodes).length > 2) continue;
                    if (moved.isArea() || unmoved.isArea()) continue;

                    cache.intersections.push({
                        nodeId: node.id,
                        movedId: moved.id,
                        unmovedId: unmoved.id,
                        movedIsEP: isEndpoint(moved, node.id),
                        unmovedIsEP: isEndpoint(unmoved, node.id)
                    });
                }
            }
        }
コード例 #3
0
ファイル: select.js プロジェクト: iandees/iD
    // find the common parent ways for nextVertex, previousVertex
    function commonParents() {
        var graph = context.graph();
        var commonParents = [];

        for (var i = 0; i < selectedIDs.length; i++) {
            var entity = context.hasEntity(selectedIDs[i]);
            if (!entity || entity.geometry(graph) !== 'vertex') {
                return [];  // selection includes some not vertexes
            }

            var currParents = _map(graph.parentWays(entity), 'id');
            if (!commonParents.length) {
                commonParents = currParents;
                continue;
            }

            commonParents = _intersection(commonParents, currParents);
            if (!commonParents.length) {
                return [];
            }
        }

        return commonParents;
    }
コード例 #4
0
ファイル: maprules.js プロジェクト: brianhatchl/iD
 var isLineKeysWhiteList = function(key) {
     return _intersection(tagMap[key], Object.keys(_lineKeys[key])).length > 0;
 };
コード例 #5
0
ファイル: maprules.js プロジェクト: brianhatchl/iD
 var isAreaKeyBlackList = function(key) {
     return _intersection(tagMap[key], Object.keys(_areaKeys[key])).length > 0;
 };
コード例 #6
0
ファイル: split.js プロジェクト: brianhatchl/iD
        graph.parentRelations(wayA).forEach(function(relation) {
            var member;

            // Turn restrictions - make sure:
            // 1. Splitting a FROM/TO way - only `wayA` OR `wayB` remains in relation
            //    (whichever one is connected to the VIA node/ways)
            // 2. Splitting a VIA way - `wayB` remains in relation as a VIA way
            if (relation.isRestriction()) {
                var f = relation.memberByRole('from');
                var v = relation.membersByRole('via');
                var t = relation.memberByRole('to');
                var i;

                // 1. split a FROM/TO
                if (f.id === wayA.id || t.id === wayA.id) {
                    var keepB = false;
                    if (v.length === 1 && v[0].type === 'node') {   // check via node
                        keepB = wayB.contains(v[0].id);
                    } else {                                        // check via way(s)
                        for (i = 0; i < v.length; i++) {
                            if (v[i].type === 'way') {
                                var wayVia = graph.hasEntity(v[i].id);
                                if (wayVia && _intersection(wayB.nodes, wayVia.nodes).length) {
                                    keepB = true;
                                    break;
                                }
                            }
                        }
                    }

                    if (keepB) {
                        relation = relation.replaceMember(wayA, wayB);
                        graph = graph.replace(relation);
                    }

                // 2. split a VIA
                } else {
                    for (i = 0; i < v.length; i++) {
                        if (v[i].type === 'way' && v[i].id === wayA.id) {
                            member = {
                                id: wayB.id,
                                type: 'way',
                                role: 'via'
                            };
                            graph = actionAddMember(relation.id, member, v[i].index + 1)(graph);
                            break;
                        }
                    }
                }

            // All other relations (Routes, Multipolygons, etc):
            // 1. Both `wayA` and `wayB` remain in the relation
            // 2. But must be inserted as a pair (see `actionAddMember` for details)
            } else {
                if (relation === isOuter) {
                    graph = graph.replace(relation.mergeTags(wayA.tags));
                    graph = graph.replace(wayA.update({tags: {}}));
                    graph = graph.replace(wayB.update({tags: {}}));
                }

                member = {
                    id: wayB.id,
                    type: 'way',
                    role: relation.memberById(wayA.id).role
                };

                var insertPair = {
                    originalID: wayA.id,
                    insertedID: wayB.id,
                    nodes: origNodes
                };

                graph = actionAddMember(relation.id, member, undefined, insertPair)(graph);
            }
        });