Skip to content
Snippets Groups Projects
Commit 53dd9c22 authored by Tor-Einar Skog's avatar Tor-Einar Skog
Browse files

feat: Improved sorting of weather stations

parent 7cf68f67
No related branches found
No related tags found
1 merge request!191Add map module and Open-Meteo support
...@@ -55,8 +55,6 @@ ...@@ -55,8 +55,6 @@
}, },
</#list> </#list>
]; ];
const createOption = (value, text, isSelected = false) => { const createOption = (value, text, isSelected = false) => {
...@@ -79,21 +77,12 @@ ...@@ -79,21 +77,12 @@
* @param selectElement the select list to render to * @param selectElement the select list to render to
* @param elementList the list of weather stations to list * @param elementList the list of weather stations to list
* @param selectedId the id (optional) to be preselected * @param selectedId the id (optional) to be preselected
* @param coordinateToMatch [lon, lat] coordinate to match. Optional. If set: The 3 closest weather stations are show at top of list, with distance to coordinate. * @param coordinateToMatch [lon, lat] coordinate to match. Optional. If set: The closest weather stations are show at top of list, with distance to coordinate.
*/ */
window.renderWeatherstationSelect = function(selectElement, elementList, selectedId, coordinateToMatch) window.renderWeatherstationSelect = function(selectElement, elementList, selectedId, coordinateToMatch)
{ {
selectElement.options.length = 0; selectElement.options.length = 0;
<#if isGridForecastSupported>
// Add default option
selectElement.appendChild(createOption(
"-2",
"${i18nBundle.doNotUse} ${i18nBundle.weatherStationPointOfInterestId?lower_case}",
!selectedId
));
</#if>
// Add default option // Add default option
selectElement.appendChild(createOption( selectElement.appendChild(createOption(
"-1", "-1",
...@@ -101,7 +90,7 @@ ...@@ -101,7 +90,7 @@
!selectedId !selectedId
)); ));
// Add all locations that are weatherstations // Render all weather stations, order by distance to coordinate
if(coordinateToMatch != null) if(coordinateToMatch != null)
{ {
let stations = []; let stations = [];
...@@ -118,7 +107,7 @@ ...@@ -118,7 +107,7 @@
stations.forEach(poi => { stations.forEach(poi => {
selectElement.appendChild(createOption( selectElement.appendChild(createOption(
poi.pointOfInterestId, poi.pointOfInterestId,
poi.name + " (" + poi.distance +" km)", poi.name + (poi.distance > 0.0 ? " (" + poi.distance +" km)" : ""),
selectedId && poi.pointOfInterestId == selectedId selectedId && poi.pointOfInterestId == selectedId
)); ));
}); });
...@@ -126,7 +115,7 @@ ...@@ -126,7 +115,7 @@
} }
else else
{ {
// Render all // Render all weather stations alphabetically
elementList.forEach(poi => { elementList.forEach(poi => {
if(poi.pointOfInterestTypeId == POI_TYPE_WEATHERSTATION) if(poi.pointOfInterestTypeId == POI_TYPE_WEATHERSTATION)
{ {
...@@ -161,7 +150,9 @@ ...@@ -161,7 +150,9 @@
}); });
} }
renderWeatherstationSelect(selectWeatherstationElement, locationList, selectedWeatherstationId); renderWeatherstationSelect(selectWeatherstationElement, locationList, selectedWeatherstationId,
<#if forecastConfiguration.weatherStationPointOfInterestId??>[${forecastConfiguration.weatherStationPointOfInterestId.longitude?c},${forecastConfiguration.weatherStationPointOfInterestId.latitude?c}]<#else>null</#if>
);
window.selectPoi = function(selectElement, selectedId) { window.selectPoi = function(selectElement, selectedId) {
if (selectedId) { if (selectedId) {
...@@ -490,7 +481,7 @@ ...@@ -490,7 +481,7 @@
if(selectedLocation.pointOfInterestTypeId == POI_TYPE_WEATHERSTATION) if(selectedLocation.pointOfInterestTypeId == POI_TYPE_WEATHERSTATION)
{ {
renderWeatherstationSelect(weatherstationSelect,locationList, selectedLocation.pointOfInterestId, null); renderWeatherstationSelect(weatherstationSelect,locationList, selectedLocation.pointOfInterestId, selectedLocation.location);
} }
else else
{ {
...@@ -598,9 +589,9 @@ ...@@ -598,9 +589,9 @@
<span class="help-block" id="${formId}_locationPointOfInterestId_validation"></span> <span class="help-block" id="${formId}_locationPointOfInterestId_validation"></span>
</div> </div>
<#if isGridForecastSupported> <#if isGridForecastSupported>
<div class="alert alert-info" role="alert">Velg sted ovenfor først, og velg deretter værdatakilde. Du kan enten velge en av de tilgjengelige værstasjonene, <div class="alert alert-info" role="alert">Velg sted ovenfor først, og velg deretter værdatakilde. Du kan enten velge en av de tilgjengelige værstasjonene (sortert etter avstand til stedet),
eller at ditt valgte steds plassering brukes til å hente værdata fra en ekstern tjeneste. Hvis ditt sted ligger nær eller at ditt valgte steds plassering brukes til å hente værdata fra en ekstern tjeneste. Hvis ditt sted ligger nær
en av værstasjonene, gir det som oftest den beste kvaliteten på værdata. Hvis stedet du har valgt ikke er en værstasjon, vil værstasjonslista sorteres etter avstand til ditt sted.</div> en av værstasjonene, gir det som oftest den beste kvaliteten på værdata.</div>
<#else> <#else>
<div class="alert alert-info" role="alert">Velg sted ovenfor først, og velg deretter værstasjon. Hvis stedet du har valgt ikke er en værstasjon, vil værstasjonslista sorteres etter avstand til ditt sted.</div> <div class="alert alert-info" role="alert">Velg sted ovenfor først, og velg deretter værstasjon. Hvis stedet du har valgt ikke er en værstasjon, vil værstasjonslista sorteres etter avstand til ditt sted.</div>
</#if> </#if>
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment