Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Don not show the locations icon if no locations are present #693

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 7 additions & 2 deletions src/components/wms/LocationsLayerComponent.vue
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
<template>
<LocationsLayer
v-if="showLocationsLayer"
v-if="showLocationsLayer && hasLocations"
:locationsGeoJson="locationsGeoJson"
:selectedLocationId="props.locationId"
@click="onLocationClick"
/>
<v-chip
v-if="hasLocations"
class="locations-layer__chip"
:class="{ 'pr-0': showLocationsLayer }"
pill
Expand All @@ -31,7 +32,7 @@
</template>

<script setup lang="ts">
import { ref, watch, watchEffect } from 'vue'
import { ref, watch, watchEffect, computed } from 'vue'
import LocationsSearchControl from './LocationsSearchControl.vue'
import LocationsLayer from './LocationsLayer.vue'
import { configManager } from '@/services/application-config'
Expand Down Expand Up @@ -81,6 +82,10 @@ watch(locationsGeoJson, () => {
locations.value = convertGeoJsonToFewsPiLocation(locationsGeoJson.value)
})

const hasLocations = computed(() => {
return locations.value.length > 0
})

function onLocationClick(event: MapLayerMouseEvent | MapLayerTouchEvent): void {
if (!event.features) return
const locationId: string | undefined =
Expand Down
11 changes: 7 additions & 4 deletions src/lib/topology/locations.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,13 @@ export async function fetchLocationsAsGeoJson(
),
)
// Merge them into a single GeoJSON.
const geojson = allGeoJson.reduce((prev, cur) => {
prev.features.concat(cur.features)
return prev
})
const geojson = allGeoJson.reduce(
(prev, cur) => {
prev.features = prev.features.concat(cur.features)
return prev
},
{ type: 'FeatureCollection', features: [] },
)
return geojson
}

Expand Down
Loading