Skip to content

Commit

Permalink
Merge pull request #237 from SpeciesFileGroup/development
Browse files Browse the repository at this point in the history
Development
  • Loading branch information
jlpereira authored Oct 21, 2024
2 parents 5cf6ca2 + fcadddc commit db9d817
Show file tree
Hide file tree
Showing 10 changed files with 58 additions and 36 deletions.
2 changes: 1 addition & 1 deletion src/modules/otus/components/Panel/PanelKeys/PanelKeys.vue
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ import { onMounted, onBeforeUnmount, ref, computed } from 'vue'
const props = defineProps({
otuId: {
type: Object
type: Number
}
})
Expand Down
26 changes: 2 additions & 24 deletions src/modules/otus/components/Panel/PanelMap/PanelMap.vue
Original file line number Diff line number Diff line change
Expand Up @@ -69,9 +69,10 @@

<script setup>
import { ref, onMounted, onBeforeUnmount } from 'vue'
import { useDistributionStore } from '@/modules/otus/store/useDistributionStore.js'
import { useDistributionStore } from './store/useDistributionStore.js'
import { makeClusterIconFor } from './clusters/makeClusterIconFor'
import { useGeojsonOptions } from './composables/useGeojsonOptions.js'
import { LEGEND } from './constants'
import MapPopup from './components/MapPopup.vue'
import CachedMap from './components/CachedMap.vue'
import OtuSearch from './components/Search/OtuSearch.vue'
Expand Down Expand Up @@ -107,29 +108,6 @@ const store = useDistributionStore()
const popupElement = ref(null)
const { popupItem, geojsonOptions } = useGeojsonOptions({ popupElement })
const LEGEND = {
AssertedDistribution: {
label: 'Asserted distribution',
background: 'bg-map-asserted'
},
Georeference: {
label: 'Georeference',
background: 'bg-map-georeference'
},
TypeMaterial: {
label: 'Type material',
background: 'bg-map-type-material'
},
CollectionObject: {
label: 'Collection object',
background: 'bg-map-collection-object'
},
Aggregate: {
label: 'Aggregate (Asserted distribution & Georeference)',
background: 'bg-map-aggregate'
}
}
onMounted(() => {
isLoading.value = true
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export * from './legend'
22 changes: 22 additions & 0 deletions src/modules/otus/components/Panel/PanelMap/constants/legend.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
export const LEGEND = {
Aggregate: {
label: 'Aggregate (Asserted distribution & Georeference)',
background: 'bg-map-aggregate'
},
AssertedDistribution: {
label: 'Asserted distribution',
background: 'bg-map-asserted'
},
Georeference: {
label: 'Georeference',
background: 'bg-map-georeference'
},
CollectionObject: {
label: 'Collection object',
background: 'bg-map-collection-object'
},
TypeMaterial: {
label: 'Type material',
background: 'bg-map-type-material'
}
}
Original file line number Diff line number Diff line change
@@ -1,12 +1,31 @@
import TaxonWorks from '../services/TaxonWorks'
import TaxonWorks from '../../../../services/TaxonWorks'
import { defineStore } from 'pinia'
import { useOtuPageRequest } from '../helpers/useOtuPageRequest'
import { RESPONSE_ERROR } from '../constants'
import { useOtuPageRequest } from '../../../../helpers/useOtuPageRequest'
import { RESPONSE_ERROR } from '../../../../constants'
import {
isRankGrpup,
isRankGroup,
removeDuplicateShapes,
makeGeoJSONFeature
} from '../utils'
import { LEGEND } from '../constants'

function sortFeaturesByType(arr, reference) {
const referenceMap = new Map()

reference.forEach((item, index) => {
referenceMap.set(item, index)
})

return arr.toSorted((a, b) => {
const indexA = referenceMap.has(a.properties.base.type)
? referenceMap.get(a.properties.base.type)
: Infinity
const indexB = referenceMap.has(b.properties.base.type)
? referenceMap.get(b.properties.base.type)
: Infinity
return indexA - indexB
})
}

export const useDistributionStore = defineStore('distributionStore', {
state: () => {
Expand Down Expand Up @@ -60,7 +79,7 @@ export const useDistributionStore = defineStore('distributionStore', {

async loadDistribution({ otuId, rankString }) {
const isSpeciesGroup =
rankString && isRankGrpup('SpeciesGroup', rankString)
rankString && isRankGroup('SpeciesGroup', rankString)

this.controller = new AbortController()

Expand All @@ -75,7 +94,9 @@ export const useDistributionStore = defineStore('distributionStore', {
this.distribution.geojson = null
this.distribution.errorMessage = data.message
} else {
const { features, shapeTypes } = removeDuplicateShapes(data)
const { features, shapeTypes } = removeDuplicateShapes(
sortFeaturesByType(data.features, Object.keys(LEGEND))
)

this.distribution.currentShapeTypes = shapeTypes
this.distribution.geojson = {
Expand Down
3 changes: 3 additions & 0 deletions src/modules/otus/components/Panel/PanelMap/utils/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export * from './isRankGroup'
export * from './makeGeoJSONFeature'
export * from './removeDuplicateShapes'
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
export function isRankGrpup(compareRank, rank) {
export function isRankGroup(compareRank, rank) {
const rankGroup = rank.split('::').at(2)

return rankGroup === compareRank
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ export function removeDuplicateShapes(data) {
const features = []
const shapeTypes = []

data.features.forEach((feature) => {
data.forEach((feature) => {
const shapeId = feature.properties.shape.id
const shapeType = feature.properties.shape.type

Expand Down
3 changes: 0 additions & 3 deletions src/modules/otus/utils/index.js
Original file line number Diff line number Diff line change
@@ -1,4 +1 @@
export * from './isAvailableForRank'
export * from './isRankGroup'
export * from './makeGeoJSONFeature'
export * from './removeDuplicateShapes'

0 comments on commit db9d817

Please sign in to comment.