UNPKG

@seasketch/geoprocessing

Version:

Geoprocessing and reporting framework for SeaSketch 2.0

64 lines 2.37 kB
import { getJsonUserAttribute } from "../helpers/index.js"; import { iucnCategoriesMap, } from "./iucnProtectionLevel.js"; /** * Given list of allowed activities in the sketch, returns the highest category allowable * The lack of an activity assumes it is not allowed * @param sketch * @param activityAttrib */ export const getIucnCategoryForActivities = (activities) => { if (activities.length === 0) return iucnCategoriesMap["1a"]; // Get first category where all activities allowed in sketch are allowed by the category let firstCategory = undefined; const categoryIds = Object.keys(iucnCategoriesMap).sort(); for (const categoryId of categoryIds) { const curCategory = iucnCategoriesMap[categoryId]; const matchCategory = activities .map((act) => curCategory.allowedActivities.includes(act)) .reduce((acc, hasActivity) => acc && hasActivity, true); if (matchCategory) { firstCategory = curCategory; break; } } if (!firstCategory) firstCategory = iucnCategoriesMap["None"]; return firstCategory; }; /** * Return Category for each sketch keyed by sketchId */ export const getIucnCategoryForSketches = (sketches) => { const sketchCategoryMap = sketches.reduce((acc, sketch) => { // Get sketch allowed activities, then category const activities = getJsonUserAttribute(sketch, "ACTIVITIES", []); const category = getIucnCategoryForActivities(activities); return { ...acc, [sketch.properties.id]: category, }; }, {}); return sketchCategoryMap; }; /** * Return Category name for each sketch keyed by sketchId */ export const getIucnCategoryNameForSketches = (sketches) => { const sketchCatMap = getIucnCategoryForSketches(sketches); return Object.keys(sketchCatMap).reduce((sofar, sketchId) => ({ ...sofar, [sketchId]: sketchCatMap[sketchId].category, }), {}); }; /** * Return level name for each sketch keyed by sketchId */ export const getIucnLevelNameForSketches = (sketches) => { const sketchCatMap = getIucnCategoryForSketches(sketches); return Object.keys(sketchCatMap).reduce((sofar, sketchId) => ({ ...sofar, [sketchId]: sketchCatMap[sketchId].level, }), {}); }; //# sourceMappingURL=helpers.js.map