From a73b70ac037f3beaa5a70521a6700c078b90d1e5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andrei=20Ioni=C8=9B=C4=83?= Date: Fri, 8 Nov 2024 09:47:58 +0000 Subject: [PATCH] wip --- resources/js/map.js | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/resources/js/map.js b/resources/js/map.js index a58b4e7..02fa64a 100644 --- a/resources/js/map.js +++ b/resources/js/map.js @@ -11,6 +11,14 @@ import.meta.glob( } ); +const hasValue = (value) => { + if (typeof value === 'undefined') { + return false; + } + + return value !== '' && value != 0 && value !== null; +}; + export default () => ({ map: null, tooltip: L.tooltip(), @@ -43,16 +51,17 @@ export default () => ({ opacity: 0.75, fillOpacity: 1, color: 'white', - fillColor: this.$wire.data[feature.properties?.id]?.color || '#DDD', + fillColor: hasValue(this.$wire.data[feature.properties?.id]?.value) + ? this.$wire.data[feature.properties?.id]?.color || '#DDD' + : '#DDD', }), onEachFeature: (feature, layer) => { - if (!feature.properties?.id) { + if (!feature.properties?.id || !hasValue(this.$wire.data[feature.properties.id]?.value)) { return; } layer.bindTooltip( - `${feature.properties.name}
- ${this.$wire.data[feature.properties.id]?.value || '—'}`, + `${feature.properties.name}
${this.$wire.data[feature.properties.id].value}`, { sticky: true, direction: 'top',