Skip to content

Commit

Permalink
multipolygons
Browse files Browse the repository at this point in the history
  • Loading branch information
Nicolaidavies committed Aug 6, 2018
1 parent 699573d commit 3d06e24
Showing 1 changed file with 13 additions and 1 deletion.
14 changes: 13 additions & 1 deletion src/apps/irs_plan/helpers/target_areas_helper.js
@@ -1,6 +1,8 @@
import inside from '@turf/inside'
import centroid from '@turf/centroid'
import booleanWithin from '@turf/boolean-overlap'
import { multiPolygon } from '@turf/helpers'
import { getType, getCoords} from '@turf/invariant'

import cache from 'config/cache'
import {get_planning_level_name, get_group_by_for_level} from 'lib/instance_data/spatial_hierarchy_helper'
Expand All @@ -24,11 +26,21 @@ const target_areas_inside_focus_filter_area = ({area_ids, selected_filter_area})

if (!found_area) return false

return inside(centroid(found_area), selected_filter_area) || booleanWithin(found_area, selected_filter_area)
return inside(centroid(found_area), selected_filter_area) || boolean_within_multipolygons(found_area, selected_filter_area)
})
return result
}

function boolean_within_multipolygons(found_area, selected_filter_area) {
if (found_area.geometry.type === 'MultiPolygon') {
// convert our selection polygon to a multipolygon
const coords = getCoords(selected_filter_area)
selected_filter_area = multiPolygon(coords)
}

return booleanWithin(found_area, selected_filter_area)
}

function quick_select_targets_by_risk_inside_focus({areas, selected_filter_area}) {
if (!Array.isArray(areas)) areas = [areas]

Expand Down

0 comments on commit 3d06e24

Please sign in to comment.