MCPcopy Create free account
hub / github.com/facebook/Rapid / _resolveLocationSet

Method _resolveLocationSet

modules/core/LocationSystem.js:198–221  ·  view source on GitHub ↗

* _resolveLocationSet * Does everything that `_validateLocationSet()` does, but then "resolves" the locationSet into GeoJSON. * This step is a bit more computationally expensive, so really only needed if you intend to render the shape. * * Note: You need to call `_rebuildIndex()` after y

(obj)

Source from the content-addressed store, hash-verified

196 * @param `obj` Object to check, it should have `locationSet` property
197 */
198 _resolveLocationSet(obj) {
199 this._validateLocationSet(obj);
200
201 if (this._resolved.has(obj.locationSetID)) return; // work was done already
202
203 try {
204 const result = LOCO.resolveLocationSet(obj.locationSet);
205 const locationSetID = result.id;
206 obj.locationSetID = locationSetID;
207
208 if (!result.feature.geometry.coordinates.length || !result.feature.properties.area) {
209 throw new Error(`locationSet ${locationSetID} resolves to an empty feature.`);
210 }
211
212 let geojson = JSON.parse(JSON.stringify(result.feature)); // deep clone
213 geojson.id = locationSetID; // Important: always use the locationSet `id` (`+[Q30]`), not the feature `id` (`Q30`)
214 geojson.properties.id = locationSetID;
215 this._resolved.set(locationSetID, geojson);
216
217 } catch (err) {
218 obj.locationSet = { include: ['Q2'] }; // default worldwide
219 obj.locationSetID = '+[Q2]';
220 }
221 }
222
223
224 /**

Callers 1

constructorMethod · 0.95

Calls 1

_validateLocationSetMethod · 0.95

Tested by

no test coverage detected