* mergeCustomGeoJSON * Accepts a FeatureCollection-like object containing custom locations * Each feature must have a filename-like `id`, for example: `something.geojson` * { * "type": "FeatureCollection" * "features": [ * { * "type": "Feature", * "id": "p
(fc)
| 250 | * @param `fc` FeatureCollection-like Object containing custom locations |
| 251 | */ |
| 252 | mergeCustomGeoJSON(fc) { |
| 253 | if (!fc || fc.type !== 'FeatureCollection' || !Array.isArray(fc.features)) return; |
| 254 | |
| 255 | fc.features.forEach(feature => { |
| 256 | feature.properties = feature.properties || {}; |
| 257 | let props = feature.properties; |
| 258 | |
| 259 | // Get `id` from either `id` or `properties` |
| 260 | let id = feature.id || props.id; |
| 261 | if (!id || !/^\S+\.geojson$/i.test(id)) return; |
| 262 | |
| 263 | // Ensure `id` exists and is lowercase |
| 264 | id = id.toLowerCase(); |
| 265 | feature.id = id; |
| 266 | props.id = id; |
| 267 | |
| 268 | // Ensure `area` property exists |
| 269 | if (!props.area) { |
| 270 | const area = calcArea.geometry(feature.geometry) / 1e6; // m² to km² |
| 271 | props.area = Number(area.toFixed(2)); |
| 272 | } |
| 273 | |
| 274 | LOCO._cache[id] = feature; // insert directly into LocationConflations internal cache |
| 275 | }); |
| 276 | } |
| 277 | |
| 278 | |
| 279 | /** |
no test coverage detected