Skip to content

Commit 1ffb763

Browse files
committed
feat(mapa): Adiciona mapa de especies
1 parent 3a6c1a3 commit 1ffb763

File tree

4 files changed

+58
-12
lines changed

4 files changed

+58
-12
lines changed

web/src/components/Map.astro

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,25 @@
11
---
22
interface Props {
3-
stateList: string[]
3+
full?: boolean
4+
data?: [string, any][]
5+
stateList?: string[]
46
}
57
6-
const { stateList } = Astro.props
7-
const data = [
8-
['Estado', 'Ocorrência'],
9-
...stateList.map((state) => [state, state])
10-
]
8+
const { full, stateList } = Astro.props
9+
const data =
10+
Astro.props.data ??
11+
(stateList && [
12+
['Estado', 'Ocorrência'],
13+
...stateList.map((state) => [state, state])
14+
])
1115
---
1216

1317
<script type="module">
1418
import 'https://cdn.skypack.dev/@google-web-components/google-chart'
1519
</script>
1620

1721
<google-chart
18-
class="h-[200px] w-auto"
22+
class={full ? 'w-full h-full' : 'h-[200px] w-auto'}
1923
type="geo"
2024
data={JSON.stringify(data)}
2125
options='{"region":"BR", "resolution":"provinces","title":"Ocorrências"}'

web/src/lib/mongo.ts

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,32 @@ export async function countTaxa(filter: Record<string, unknown> = {}) {
7272
return await taxa.countDocuments(filter)
7373
}
7474

75+
export async function countTaxaRegions() {
76+
const taxa = await getCollection('dwc2json', 'taxa')
77+
return await taxa
78+
.aggregate([
79+
{
80+
$match: {
81+
taxonomicStatus: 'NOME ACEITO'
82+
}
83+
},
84+
{
85+
$unwind: {
86+
path: '$distribution.occurrence'
87+
}
88+
},
89+
{
90+
$group: {
91+
_id: '$distribution.occurrence',
92+
count: {
93+
$count: {}
94+
}
95+
}
96+
}
97+
])
98+
.toArray()
99+
}
100+
75101
export async function getTaxon(
76102
kingdom: 'Plantae' | 'Fungi' | 'Animalia',
77103
id: string,

web/src/pages/mapa.astro

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
---
2+
import Map from '../components/Map.astro'
3+
import { countTaxaRegions } from '../lib/mongo'
4+
5+
const taxaRegions: { _id: string; count: number }[] = await countTaxaRegions()
6+
---
7+
8+
<div
9+
class="h-screen w-screen flex items-stretch justify-stretch overflow-hidden"
10+
>
11+
<Map
12+
full
13+
data={[
14+
['Estado', 'Taxa'],
15+
...taxaRegions.map(({ _id, count }) => [_id, count] as [string, number])
16+
]}
17+
/>
18+
</div>

web/src/pages/taxa.astro

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
---
22
import BaseLayout from '../layouts/base.astro'
3-
import { listTaxaPaginated } from '../lib/mongo'
4-
5-
import { countTaxa } from '../lib/mongo'
3+
import { countTaxa, listTaxaPaginated } from '../lib/mongo'
64
75
const taxaNum = await countTaxa()
86
@@ -43,8 +41,8 @@ const searchParamsWithPage = (page: number) => {
4341
}
4442
---
4543

46-
<img src="/logoReflora.svg" alt="Reflora Logo" />
47-
<BaseLayout useTransition title="Procura de Taxa">
44+
<BaseLayout title="Procura de Taxa">
45+
<img src="/logoReflora.svg" alt="Reflora Logo" />
4846
<section class="m-2 p-2 border rounded border-slate-400 inline-block">
4947
<h2 class="text-xl font-bold">Filtro</h2>
5048
<form class="inline-flex flex-col gap-1">

0 commit comments

Comments
 (0)