From e34e95d7944d12208c303e2b46b2d8ad8f4b727d Mon Sep 17 00:00:00 2001 From: flisowna Date: Fri, 23 Dec 2022 12:09:34 +0100 Subject: [PATCH] Revert "geo data map bug: debug via reducing complexity - step 1" This reverts commit 9146423eec495d74f1f3d77469e484231b908b75. --- packages/nc-gui/components/smartsheet/Map.vue | 67 +++++++++++++++++++ 1 file changed, 67 insertions(+) diff --git a/packages/nc-gui/components/smartsheet/Map.vue b/packages/nc-gui/components/smartsheet/Map.vue index c95425bedb..6c604a8000 100644 --- a/packages/nc-gui/components/smartsheet/Map.vue +++ b/packages/nc-gui/components/smartsheet/Map.vue @@ -68,6 +68,24 @@ const getMapZoomLocalStorageKey = (viewId: string) => { } const getMapCenterLocalStorageKey = (viewId: string) => `mapView.center.${viewId}` +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 + } +} const expandedFormOnRowIdDlg = computed({ get() { @@ -94,6 +112,55 @@ reloadViewDataHook?.on(async () => { loadMapMeta() }) +function addMarker(lat: number, long: number, row: RowType) { + if (markersClusterGroupRef.value == null) { + throw new Error('Map is null') + } + const newMarker = L.marker([lat, long]).on('click', () => { + expandForm(row) + }) + markersClusterGroupRef.value?.addLayer(newMarker) + + // if (newMarker) { + // newMarker.bindPopup(popupContent) + // } +} + +watch([formattedData, mapMetaData, markersClusterGroupRef], () => { + if (markersClusterGroupRef.value == null) { + return + } + + markersClusterGroupRef.value?.clearLayers() + + formattedData.value?.forEach((row) => { + const primaryGeoDataColumnTitle = geoDataFieldColumn.value?.title + + if (primaryGeoDataColumnTitle == null) { + throw new Error('Cannot find primary geo data column title') + } + + 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 + + // return `
  • ${key}:
    ${prettyVal}
  • ` + // }) + // .join('') + + // const popupContent = `` + + if (primaryGeoDataValue == null) { + return + } + + const [lat, long] = primaryGeoDataValue.split(';').map(parseFloat) + + addMarker(lat, long, row) + }) +}) const resetZoomAndCenterBasedOnLocalStorage = () => { if (mapMetaData?.value?.fk_view_id == null) {