Skip to content

Commit

Permalink
feat: Add information about meteorological model and elements (closes #…
Browse files Browse the repository at this point in the history
  • Loading branch information
claustres committed Aug 29, 2024
1 parent 6c31074 commit b1b5fb8
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 8 deletions.
12 changes: 11 additions & 1 deletion src/components/MapActivity.vue
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
<script>
import _ from 'lodash'
import L from 'leaflet'
import sift from 'sift'
import moment from 'moment'
import 'leaflet-rotate/dist/leaflet-rotate-src.js'
import 'leaflet-arrowheads'
Expand Down Expand Up @@ -197,7 +198,16 @@ export default {
},
getHighlightTooltip (feature, layer, options) {
if ((options.name === kMapComposables.HighlightsLayerName) && this.isWeatherProbe(feature)) {
const html = this.getForecastAsHtml(feature)
// Get labels from forecast layers
const layers = _.values(this.layers).filter(sift({ tags: ['weather', 'forecast'] }))
const variables = _.reduce(layers, (result, layer) => result.concat(_.get(layer, 'variables', [])), [])
const fields = this.getProbedLocationForecastFields()
_.forOwn(fields, (value, key) => {
// Take care that weather fields are prefixed by 'properties.' because they target feature
const variable = _.find(variables, { name: `${value.property.replace('properties.', '')}` })
if (variable) value.label = variable.label
})
const html = this.getForecastAsHtml(feature, fields)
return L.tooltip({ permanent: false }, layer).setContent(`<b>${html}</b>`)
}
},
Expand Down
20 changes: 13 additions & 7 deletions src/utils/utils.time-series.js
Original file line number Diff line number Diff line change
Expand Up @@ -57,17 +57,20 @@ export function getChartOptions (title) {
export async function updateTimeSeries (previousTimeSeries) {
const { CurrentActivity, hasSelectedItems, getSelectedItems, hasProbedLocation, getProbedLocation } = kMapComposables.useCurrentActivity()
const activity = unref(CurrentActivity)

// Weather probe targets variables coming from multiple layers
const forecastLayers = _.values(activity.layers).filter(sift({ tags: ['weather', 'forecast'] }))
const featureLevel = activity.selectableLevelsLayer ? ` - ${activity.selectedLevel} ${activity.selectableLevels.unit}` : ''

let timeSeries = []
if (hasProbedLocation()) {
const featureLevel = activity.selectableLevelsLayer ? ` - ${activity.selectedLevel} ${activity.selectableLevels.unit}` : ''
const layers = _.values(activity.layers).filter(sift({ tags: ['weather', 'forecast'] }))
const coordinates = kMapUtils.formatUserCoordinates(getProbedLocation().lat, getProbedLocation().lng, Store.get('locationFormat', 'FFf'))
const label = `${activity.forecastModel.label} (${coordinates})` + featureLevel
timeSeries.push({
id: 'probe',
label: `${activity.forecastModel.label} (${getProbedLocation().lng.toFixed(2)}°, ${getProbedLocation().lat.toFixed(2)}°)` + featureLevel,
label,
series: kMapUtils.getTimeSeries({
location: getProbedLocation(),
layers,
layers: forecastLayers,
level: activity.selectedLevel,
forecastModel: activity.forecastModel,
forecastLevel: activity.forecastLevel,
Expand All @@ -79,13 +82,16 @@ export async function updateTimeSeries (previousTimeSeries) {
getSelectedItems().forEach(item => {
const featureLabel = _.get(item, `feature.properties.${item.layer.featureLabel || 'name'}`)
const featureId = kMapUtils.getFeatureId(item.feature, item.layer)
const featureLevel = activity.selectableLevelsLayer ? ` - ${activity.selectedLevel} ${activity.selectableLevels.unit}` : ''
const label = (_.has(item, 'layer.probe') ?
`${activity.forecastModel.label} (${item.layer.label} - ${featureLabel})` + featureLevel :
`${item.layer.label} - ${featureLabel}` + featureLevel)
timeSeries.push({
id: `${item.layer.name}-${featureId}`,
label: `${item.layer.label} - ${featureLabel}` + featureLevel,
label,
series: kMapUtils.getTimeSeries({
feature: item.feature,
layer: item.layer,
layers: _.has(item, 'layer.probe') ? forecastLayers : [],
level: activity.selectedLevel,
forecastModel: activity.forecastModel,
forecastLevel: activity.forecastLevel,
Expand Down

0 comments on commit b1b5fb8

Please sign in to comment.