Browse Source

WIP mapViewStore

pull/4140/head
flisowna 2 years ago
parent
commit
9e6271dd4e
  1. 40
      packages/nc-gui/components/smartsheet/Map.vue
  2. 3
      packages/nc-gui/composables/useMapViewDataStore.ts

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

@ -15,18 +15,18 @@ provide(ReadonlyInj, !isUIAllowed('xcDatatableEditable'))
const reloadViewDataHook = inject(ReloadViewDataHookInj) const reloadViewDataHook = inject(ReloadViewDataHookInj)
// const meta = inject(MetaInj, ref()) // const meta = inject(MetaInj, ref())
const view = inject(ActiveViewInj, ref()) // const view = inject(ActiveViewInj, ref())
// const { loadData, formattedData: data } = useViewData(meta, view) // const { loadData, formattedData: data } = useViewData(meta, view)
const { formattedData, loadMapData } = useMapViewStoreOrThrow() const { formattedData, loadMapData } = useMapViewStoreOrThrow()
watch(view, async (nextView) => { // watch(view, async (nextView) => {
if (nextView?.type === ViewTypes.MAP) { // if (nextView?.type === ViewTypes.MAP) {
// loadData() // // loadData()
console.log('change') // console.log('change')
alert('JO') // alert('JO')
} // }
}) // })
// const { isUIAllowed } = useUIPermission() // const { isUIAllowed } = useUIPermission()
@ -35,9 +35,19 @@ onMounted(async () => {
// const geodata = data.value[0].row.geo.split(';') // const geodata = data.value[0].row.geo.split(';')
}) })
watch(formattedData, () => {
formattedData.value?.forEach((row) => {
// const [lat, long] =
console.log('row', row)
const [lat, long] = row?.['geo'].split(';').map(parseFloat)
console.log('lat', lat)
addMarker(lat, long)
})
})
const markerRef = ref() const markerRef = ref()
const myMapRef = ref() const myMapRef = ref()
// const latitude = ref() // const latitude = formattedData.value
// const longitude = ref() // const longitude = ref()
const markersRef = ref() const markersRef = ref()
@ -45,13 +55,13 @@ reloadViewDataHook?.on(async () => {
loadMapData() loadMapData()
}) })
// function addMarker() { function addMarker(lat: number, long: number) {
// const markerNew = markerRef.value([parseFloat(latitude.value), parseFloat(longitude.value)]) const markerNew = markerRef.value([lat, long])
// console.log(markersRef.value) console.log(markersRef.value)
// markersRef.value.addLayer(markerNew) markersRef.value.addLayer(markerNew)
// myMapRef.value.addLayer(markersRef.value) myMapRef.value.addLayer(markersRef.value)
// } }
onMounted(async () => { onMounted(async () => {
const { map, tileLayer, marker } = await import('leaflet') const { map, tileLayer, marker } = await import('leaflet')

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

@ -1,13 +1,14 @@
import type { ComputedRef, Ref } from 'vue' import type { ComputedRef, Ref } from 'vue'
import type { MapType, TableType, ViewType } from 'nocodb-sdk' import type { MapType, TableType, ViewType } from 'nocodb-sdk'
import { ref, useApi, useInjectionState } from '#imports' import { ref, useApi, useInjectionState } from '#imports'
import type { Row } from '~/lib'
const [useProvideMapViewStore, useMapViewStore] = useInjectionState( const [useProvideMapViewStore, useMapViewStore] = useInjectionState(
( (
meta: Ref<TableType | MapType | undefined>, meta: Ref<TableType | MapType | undefined>,
viewMeta: Ref<ViewType | MapType | undefined> | ComputedRef<(ViewType & { id: string }) | undefined>, viewMeta: Ref<ViewType | MapType | undefined> | ComputedRef<(ViewType & { id: string }) | undefined>,
) => { ) => {
const formattedData = ref<string[]>() const formattedData = ref<Row[]>()
const { api } = useApi() const { api } = useApi()
const { project } = useProject() const { project } = useProject()

Loading…
Cancel
Save