@@ -145,6 +155,15 @@ const VIEW_MODE_COLORS = {
const activePointColor = computed(() => VIEW_MODE_COLORS[mapViewMode.value] || VIEW_MODE_COLORS.offers)
+// Entity type for icons based on view mode
+const VIEW_MODE_ENTITY_TYPES = {
+ offers: 'offer',
+ hubs: 'hub',
+ suppliers: 'supplier'
+} as const
+
+const activeEntityType = computed(() => VIEW_MODE_ENTITY_TYPES[mapViewMode.value] || VIEW_MODE_ENTITY_TYPES.offers)
+
// Node type for server clustering based on view mode
const VIEW_MODE_NODE_TYPES = {
offers: 'offer',
@@ -154,6 +173,9 @@ const VIEW_MODE_NODE_TYPES = {
const activeClusterNodeType = computed(() => VIEW_MODE_NODE_TYPES[mapViewMode.value] || VIEW_MODE_NODE_TYPES.offers)
+// Store current bounds for refetching when view mode changes
+const currentBounds = ref(null)
+
interface MapItem {
uuid: string
latitude?: number | null
@@ -189,7 +211,17 @@ const emit = defineEmits<{
}>()
// Server-side clustering - use computed node type based on view mode
-const { clusteredNodes, fetchClusters } = useClusteredNodes(undefined, activeClusterNodeType)
+const { clusteredNodes, fetchClusters, loading: clusterLoading, clearNodes } = useClusteredNodes(undefined, activeClusterNodeType)
+
+// Refetch clusters when view mode changes
+watch(mapViewMode, async () => {
+ // Clear old data first
+ clearNodes()
+ // Refetch with current bounds if available
+ if (currentBounds.value) {
+ await fetchClusters(currentBounds.value)
+ }
+})
// Map refs
const mapRef = ref<{ flyTo: (lat: number, lng: number, zoom?: number) => void } | null>(null)
@@ -225,6 +257,7 @@ const itemsWithCoords = computed(() =>
)
const onBoundsChange = (bounds: MapBounds) => {
+ currentBounds.value = bounds
emit('bounds-change', bounds)
if (props.useServerClustering) {
fetchClusters(bounds)
diff --git a/app/composables/useClusteredNodes.ts b/app/composables/useClusteredNodes.ts
index 84dc2ad..759457a 100644
--- a/app/composables/useClusteredNodes.ts
+++ b/app/composables/useClusteredNodes.ts
@@ -44,9 +44,14 @@ export function useClusteredNodes(
}
}
+ const clearNodes = () => {
+ clusteredNodes.value = []
+ }
+
return {
clusteredNodes,
loading,
- fetchClusters
+ fetchClusters,
+ clearNodes
}
}