* _validateLocationSet * Pass an Object with a `locationSet` property. * Validates the `locationSet` and sets a `locationSetID` property on the object. * To avoid so much computation we only resolve the include and exclude regions, but not the locationSet itself. * * Use `_resolveLoca
(obj)
| 120 | * @param `obj` Object to check, it should have `locationSet` property |
| 121 | */ |
| 122 | _validateLocationSet(obj) { |
| 123 | if (obj.locationSetID) return; // work was done already |
| 124 | |
| 125 | try { |
| 126 | let locationSet = obj.locationSet; |
| 127 | if (!locationSet) { |
| 128 | throw new Error('object missing locationSet property'); |
| 129 | } |
| 130 | if (!locationSet.include) { // missing `include`, default to worldwide include |
| 131 | locationSet.include = ['Q2']; // https://github.com/openstreetmap/iD/pull/8305#discussion_r662344647 |
| 132 | } |
| 133 | |
| 134 | // Validate the locationSet only |
| 135 | // Resolve the include/excludes |
| 136 | const locationSetID = LOCO.validateLocationSet(locationSet).id; |
| 137 | obj.locationSetID = locationSetID; |
| 138 | if (this._knownLocationSets.has(locationSetID)) return; // seen one like this before |
| 139 | |
| 140 | let area = 0; |
| 141 | |
| 142 | // Resolve and index the 'includes' |
| 143 | (locationSet.include || []).forEach(location => { |
| 144 | const locationID = LOCO.validateLocation(location).id; |
| 145 | let geojson = this._resolved.get(locationID); |
| 146 | |
| 147 | if (!geojson) { // first time seeing a location like this |
| 148 | geojson = LOCO.resolveLocation(location).feature; // resolve to GeoJSON |
| 149 | this._resolved.set(locationID, geojson); |
| 150 | } |
| 151 | area += geojson.properties.area; |
| 152 | |
| 153 | let s = this._locationIncludedIn.get(locationID); |
| 154 | if (!s) { |
| 155 | s = new Set(); |
| 156 | this._locationIncludedIn.set(locationID, s); |
| 157 | } |
| 158 | s.add(locationSetID); |
| 159 | }); |
| 160 | |
| 161 | // Resolve and index the 'excludes' |
| 162 | (locationSet.exclude || []).forEach(location => { |
| 163 | const locationID = LOCO.validateLocation(location).id; |
| 164 | let geojson = this._resolved.get(locationID); |
| 165 | |
| 166 | if (!geojson) { // first time seeing a location like this |
| 167 | geojson = LOCO.resolveLocation(location).feature; // resolve to GeoJSON |
| 168 | this._resolved.set(locationID, geojson); |
| 169 | } |
| 170 | area -= geojson.properties.area; |
| 171 | |
| 172 | let s = this._locationExcludedIn.get(locationID); |
| 173 | if (!s) { |
| 174 | s = new Set(); |
| 175 | this._locationExcludedIn.set(locationID, s); |
| 176 | } |
| 177 | s.add(locationSetID); |
| 178 | }); |
| 179 |
no test coverage detected