diff --git a/packages/nc-gui/components/smartsheet/Map.vue b/packages/nc-gui/components/smartsheet/Map.vue index 41893be8cb..f5835dbf91 100644 --- a/packages/nc-gui/components/smartsheet/Map.vue +++ b/packages/nc-gui/components/smartsheet/Map.vue @@ -4,9 +4,13 @@ import L from 'leaflet' import 'leaflet.markercluster' import { IsGalleryInj, IsGridInj, IsMapInj, onMounted, provide, ref } from '#imports' +import type { Row as RowType } from '~/lib' + provide(IsGalleryInj, ref(false)) provide(IsGridInj, ref(false)) provide(IsMapInj, ref(true)) +const route = useRoute() +const router = useRouter() const reloadViewDataHook = inject(ReloadViewDataHookInj) const { formattedData, loadMapData, loadMapMeta, mapMetaData, geoDataFieldColumn } = useMapViewStoreOrThrow() @@ -14,8 +18,34 @@ const markersClusterGroupRef = ref() const mapContainerRef = ref() const myMapRef = ref() +const meta = inject(MetaInj, ref()) +const view = inject(ActiveViewInj, ref()) + +const expandedFormDlg = ref(false) +const expandedFormRow = ref() +const expandedFormRowState = ref>() + console.log('meta', mapMetaData) +const expandForm = (row: RowType, state?: Record) => { + const rowId = extractPkFromRow(row.row, meta.value!.columns!) + + // debugger + + if (rowId) { + router.push({ + query: { + ...route.query, + rowId, + }, + }) + } else { + expandedFormRow.value = row + expandedFormRowState.value = state + expandedFormDlg.value = true + } +} + onBeforeMount(async () => { await loadMapMeta() await loadMapData() @@ -26,16 +56,18 @@ reloadViewDataHook?.on(async () => { loadMapMeta() }) -function addMarker(lat: number, long: number, popupContent: string) { +function addMarker(lat: number, long: number, row: RowType) { if (markersClusterGroupRef.value == null) { throw new Error('Map is null') } - const newMarker = L.marker([lat, long]) + const newMarker = L.marker([lat, long]).on('click', () => { + expandForm(row) + }) markersClusterGroupRef.value?.addLayer(newMarker) - if (newMarker) { - newMarker.bindPopup(popupContent) - } + // if (newMarker) { + // newMarker.bindPopup(popupContent) + // } } watch([formattedData, mapMetaData, markersClusterGroupRef], () => { @@ -54,15 +86,15 @@ watch([formattedData, mapMetaData, markersClusterGroupRef], () => { const primaryGeoDataValue = row.row[primaryGeoDataColumnTitle] - const listItems = Object.entries(row) - .map(([key, val]) => { - const prettyVal = val !== null && (typeof val === 'object' || Array.isArray(val)) ? JSON.stringify(val) : val + // const listItems = Object.entries(row) + // .map(([key, val]) => { + // const prettyVal = val !== null && (typeof val === 'object' || Array.isArray(val)) ? JSON.stringify(val) : val - return `
  • ${key}:
    ${prettyVal}
  • ` - }) - .join('') + // return `
  • ${key}:
    ${prettyVal}
  • ` + // }) + // .join('') - const popupContent = `
      ${listItems}
    ` + // const popupContent = `
      ${listItems}
    ` if (primaryGeoDataValue == null) { return @@ -70,7 +102,7 @@ watch([formattedData, mapMetaData, markersClusterGroupRef], () => { const [lat, long] = primaryGeoDataValue.split(';').map(parseFloat) - addMarker(lat, long, popupContent) + addMarker(lat, long, row) }) }) @@ -116,9 +148,28 @@ onMounted(async () => {