MCPcopy Create free account
hub / github.com/Project-OSRM/osrm-backend / addWay

Function addWay

features/step_definitions/data.js:126–175  ·  view source on GitHub ↗
(row)

Source from the content-addressed store, hash-verified

124 );
125
126 const addWay = (row) => {
127 const way = new OSM.Way(
128 this.makeOSMId(),
129 env.OSM_USER,
130 env.OSM_TIMESTAMP,
131 env.OSM_UID,
132 !!add_locations,
133 );
134
135 const nodes = row.nodes;
136 if (this.nameWayHash.nodes)
137 throw new Error(util.format('*** duplicate way %s', nodes));
138
139 for (let i = 0; i < nodes.length; i++) {
140 const c = nodes[i];
141 if (!c.match(/[a-z]/))
142 throw new Error(
143 util.format('*** ways can only use names a-z (%s)', c),
144 );
145 const node = this.findNodeByName(c);
146 if (!node) throw new Error(util.format('*** unknown node %s', c));
147 way.addNode(node);
148 }
149
150 const tags = {
151 highway: 'primary',
152 };
153
154 for (const key in row) {
155 tags[key] = row[key];
156 }
157
158 delete tags.nodes;
159
160 if (row.highway === '(nil)') delete tags.highway;
161
162 // Handle various ways to specify way names in test tables:
163 // - undefined: use node sequence as name
164 // - empty quotes: set empty name
165 // - '(nil)' or empty: delete name tag entirely
166 // - otherwise: use literal value
167 if (row.name === undefined) tags.name = nodes;
168 else if (row.name === '""' || row.name === '\'\'') tags.name = '';
169 else if (row.name === '' || row.name === '(nil)') delete tags.name;
170 else tags.name = row.name;
171
172 way.setTags(tags);
173 this.OSMDB.addWay(way);
174 this.nameWayHash[nodes] = way;
175 };
176
177 table.hashes().forEach((row) => addWay(row));
178 callback();

Callers 1

data.jsFile · 0.85

Calls 6

addNodeMethod · 0.95
setTagsMethod · 0.95
makeOSMIdMethod · 0.80
findNodeByNameMethod · 0.80
addWayMethod · 0.80
matchMethod · 0.45

Tested by

no test coverage detected