Browse Source

geodata: work on mapViewStore

pull/4140/head
flisowna 2 years ago
parent
commit
30aedb6f5b
  1. 20
      packages/nc-gui/components/smartsheet/Map.vue
  2. 1
      packages/nc-gui/components/tabs/Smartsheet.vue
  3. 75
      packages/nc-gui/composables/useMapViewDataStore.ts

20
packages/nc-gui/components/smartsheet/Map.vue

@ -37,23 +37,23 @@ onMounted(async () => {
const markerRef = ref()
const myMapRef = ref()
const latitude = ref()
const longitude = ref()
// const latitude = ref()
// const longitude = ref()
const markersRef = ref()
const { loadMapData, mapData } = useMapViewDataStore()
const { staticData } = useMapViewStoreOrThrow()
reloadViewDataHook?.on(async () => {
alert('reloadViewDataHook for Map')
})
function addMarker() {
const markerNew = markerRef.value([parseFloat(latitude.value), parseFloat(longitude.value)])
console.log(markersRef.value)
markersRef.value.addLayer(markerNew)
// function addMarker() {
// const markerNew = markerRef.value([parseFloat(latitude.value), parseFloat(longitude.value)])
// console.log(markersRef.value)
// markersRef.value.addLayer(markerNew)
myMapRef.value.addLayer(markersRef.value)
}
// myMapRef.value.addLayer(markersRef.value)
// }
onMounted(async () => {
const { map, tileLayer, marker } = await import('leaflet')
@ -76,7 +76,7 @@ onMounted(async () => {
<template>
<div class="flex flex-col h-full w-full">
{{ JSON.stringify(view) }}
{{ JSON.stringify(staticData) }}
<!-- <div class="flex m-4 gap-4">
<label :for="latitude">latitude</label>
<input v-model="latitude" />

1
packages/nc-gui/components/tabs/Smartsheet.vue

@ -44,6 +44,7 @@ const reloadViewMetaEventHook = createEventHook<void | boolean>()
const openNewRecordFormHook = createEventHook<void>()
useProvideKanbanViewStore(meta, activeView)
useProvideMapViewStore()
// todo: move to store
provide(MetaInj, meta)

75
packages/nc-gui/composables/useMapViewDataStore.ts

@ -1,32 +1,49 @@
const { project } = useProject()
const [useProvideMapViewStore, useMapViewStore] = useInjectionState(
async function loadMapData() {
if ((!project?.value?.id || !meta.value?.id || !viewMeta?.value?.id) && !isPublic.value) return
// reset formattedData & countByStack to avoid storing previous data after changing grouping field
formattedData.value = new Map<string | null, Row[]>()
countByStack.value = new Map<string | null, number>()
let res
if (isPublic.value) {
res = await fetchSharedViewGroupedData(groupingFieldColumn!.value!.id!)
} else {
res = await api.dbViewRow.groupedDataList(
'noco',
project.value.id!,
meta.value!.id!,
viewMeta.value!.id!,
groupingFieldColumn!.value!.id!,
{},
{},
)
}
// const { project } = useProject()
const [useProvideMapViewStore, useMapViewStore] = useInjectionState(() => {
const staticData = ['1', '2']
for (const data of res) {
const key = data.key
formattedData.value.set(key, formatData(data.value.list))
countByStack.value.set(key, data.value.pageInfo.totalRows || 0)
return {
staticData,
}
})
export { useProvideMapViewStore }
export function useMapViewStoreOrThrow() {
const mapViewStore = useMapViewStore()
if (mapViewStore == null) throw new Error('Please call `useProvideMapViewStore` on the appropriate parent component')
return mapViewStore
}
// async function loadMapData() {
// if ((!project?.value?.id || !meta.value?.id || !viewMeta?.value?.id) && !isPublic.value) return
// // reset formattedData & countByStack to avoid storing previous data after changing grouping field
// formattedData.value = new Map<string | null, Row[]>()
// countByStack.value = new Map<string | null, number>()
// let res
// if (isPublic.value) {
// res = await fetchSharedViewGroupedData(groupingFieldColumn!.value!.id!)
// } else {
// res = await api.dbViewRow.groupedDataList(
// 'noco',
// project.value.id!,
// meta.value!.id!,
// viewMeta.value!.id!,
// groupingFieldColumn!.value!.id!,
// {},
// {},
// )
// }
// for (const data of res) {
// const key = data.key
// formattedData.value.set(key, formatData(data.value.list))
// countByStack.value.set(key, data.value.pageInfo.totalRows || 0)
// }
// }

Loading…
Cancel
Save