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

Method mergeCustomGeoJSON

modules/core/LocationSystem.js:252–276  ·  view source on GitHub ↗

* 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)

Source from the content-addressed store, hash-verified

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 /**

Callers 3

mergeMethod · 0.80
getCommunityIndexAsyncFunction · 0.80

Calls 1

geometryMethod · 0.80

Tested by

no test coverage detected