-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #77 from SpeciesFileGroup/development
Update distribution endpoints, add aggregate type
- Loading branch information
Showing
14 changed files
with
163 additions
and
64 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,7 @@ | ||
| export const Aggregate = { | ||
| color: 'rgb(var(--color-map-aggregate))', | ||
| weight: 1, | ||
| dashArray: '3', | ||
| dashOffset: '3', | ||
| fillOpacity: 0.25 | ||
| } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,3 +1,4 @@ | ||
| export * from './Aggregate' | ||
| export * from './AssertedDistribution' | ||
| export * from './CollectionObject' | ||
| export * from './TypeMaterial' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| export * from './loadDistribution' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,51 @@ | ||
| import { | ||
| isRankGrpup, | ||
| removeDuplicateShapes, | ||
| makeGeoJSONFeature | ||
| } from '../../utils' | ||
| import TaxonWorks from '../../services/TaxonWorks' | ||
|
|
||
| export const actionLoadDistribution = { | ||
| async loadDistribution({ otuId, rankString }) { | ||
| const isSpeciesGroup = isRankGrpup('SpeciesGroup', rankString) | ||
|
|
||
| const getAggregateShape = async (otuId) => { | ||
| TaxonWorks.getOtuDistribution(otuId) | ||
| .then(({ data }) => { | ||
| const geojson = JSON.parse(data.cached_map.geo_json) | ||
|
|
||
| this.distribution.currentShapeTypes = ['Aggregate'] | ||
| this.distribution.geojson = { | ||
| features: [makeGeoJSONFeature(geojson, 'Aggregate')] | ||
| } | ||
| }) | ||
| .catch((e) => { | ||
| this.distribution.errorMessage = e.response.data.error | ||
| this.distribution.currentShapeTypes = [] | ||
| this.distribution.geojson = [] | ||
| }) | ||
| } | ||
|
|
||
| if (isSpeciesGroup) { | ||
| TaxonWorks.getOtuGeoJSONDistribution(otuId) | ||
| .then(({ data }) => { | ||
| if (data.request_too_large) { | ||
| this.distribution.geojson = null | ||
| this.distribution.errorMessage = data.message | ||
| } else { | ||
| const { features, shapeTypes } = removeDuplicateShapes(data) | ||
|
|
||
| this.distribution.currentShapeTypes = shapeTypes | ||
| this.distribution.geojson = { | ||
| features | ||
| } | ||
| } | ||
| }) | ||
| .catch((e) => { | ||
| getAggregateShape(otuId) | ||
| }) | ||
| } else { | ||
| getAggregateShape(otuId) | ||
| } | ||
| } | ||
| } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,3 @@ | ||
| export * from './isRankGroup' | ||
| export * from './makeGeoJSONFeature' | ||
| export * from './removeDuplicateShapes' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| export function isRankGrpup(compareRank, rank) { | ||
| const rankGroup = rank.split('::').at(2) | ||
|
|
||
| return rankGroup === compareRank | ||
| } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,13 @@ | ||
| export function makeGeoJSONFeature(geometry, type) { | ||
| return { | ||
| type: 'Feature', | ||
| geometry, | ||
| properties: { | ||
| base: [ | ||
| { | ||
| type | ||
| } | ||
| ] | ||
| } | ||
| } | ||
| } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,40 @@ | ||
| export function removeDuplicateShapes(data) { | ||
| const features = [] | ||
| const shapeTypes = [] | ||
|
|
||
| data.features.forEach((feature) => { | ||
| const shapeId = feature.properties.shape.id | ||
| const shapeType = feature.properties.shape.type | ||
|
|
||
| if (!shapeTypes.includes(feature.properties.base.type)) { | ||
| shapeTypes.push(feature.properties.base.type) | ||
| } | ||
|
|
||
| const index = features.findIndex( | ||
| (item) => | ||
| item.properties.shape.id === shapeId && | ||
| item.properties.shape.type === shapeType | ||
| ) | ||
|
|
||
| if (index > -1) { | ||
| const currentFeature = features[index] | ||
|
|
||
| currentFeature.properties.base.push(feature.properties.base) | ||
| currentFeature.properties.target.push(feature.properties.target) | ||
| } else { | ||
| const item = structuredClone(feature) | ||
|
|
||
| item.properties.base = [item.properties.base] | ||
| item.properties.target = [item.properties.target] | ||
|
|
||
| features.push(item) | ||
| } | ||
| }) | ||
|
|
||
| shapeTypes.sort() | ||
|
|
||
| return { | ||
| shapeTypes, | ||
| features | ||
| } | ||
| } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters