* _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)
| 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 | /** |
no test coverage detected