Methods
buildWeatherSnapshot(basePlace, weather) → {object}
Bygger ett väderobjekt med typ, ikon och etikett.
Parameters:
| Name | Type | Description |
|---|---|---|
basePlace |
object | |
weather |
object |
- Source:
Returns:
- Type
- object
closePOIModal()
Stänger POI-modalen.
closeSunModal()
Stänger sol-modalen.
- Source:
createPoiMarkerIcon(poi) → {L.DivIcon}
Skapar en enkel emoji-ikon för POI-markörer.
Parameters:
| Name | Type | Description |
|---|---|---|
poi |
object |
Returns:
- Type
- L.DivIcon
createSunnyPlaceMarkerIcon(place) → {L.DivIcon}
Skapar en enkel emoji-ikon för vädermarkörer i Leaflet.
Parameters:
| Name | Type | Description |
|---|---|---|
place |
object |
Returns:
- Type
- L.DivIcon
detectPoiType(tags) → {string}
Avgör vilken typ av POI ett objekt är baserat på tags.
Parameters:
| Name | Type | Description |
|---|---|---|
tags |
object |
Returns:
- Type
- string
drawPOIs(pois)
Ritar POI-markörer på kartan.
Parameters:
| Name | Type | Description |
|---|---|---|
pois |
Array.<object> |
drawRoute(coordinates)
Ritar rutt på kartan.
Parameters:
| Name | Type | Description |
|---|---|---|
coordinates |
Array.<Array.<number>> | ORS-koordinater i [lon, lat] |
drawSunnyPlaces(places)
Ritar ut solplatser som markörer på kartan.
Parameters:
| Name | Type | Description |
|---|---|---|
places |
Array.<object> |
(async) fetchOverpassWithFallback(query) → {Promise.<object>}
Hämtar JSON från Overpass och provar flera endpoints om en instans faller bort.
Parameters:
| Name | Type | Description |
|---|---|---|
query |
string |
Returns:
- Type
- Promise.<object>
fetchPOIs(routeCoords) → {Promise.<Array.<object>>}
Hämtar POI nära en lista av koordinater.
Använder dynamisk sampling för att undvika onödigt stor fråga på långa rutter.
Parameters:
| Name | Type | Description |
|---|---|---|
routeCoords |
Array.<Array.<number>> |
Returns:
- Type
- Promise.<Array.<object>>
fetchRoute(startCoords, endCoords) → {Promise.<Array.<Array.<number>>>}
Hämtar en rutt mellan två koordinater.
Parameters:
| Name | Type | Description |
|---|---|---|
startCoords |
Array.<number> | [lon, lat] |
endCoords |
Array.<number> | [lon, lat] |
Returns:
- Type
- Promise.<Array.<Array.<number>>>
(async) fetchWeatherForPlace(place) → {Promise.<object>}
Hämtar väderdata för en plats från Open-Meteo.
Parameters:
| Name | Type | Description |
|---|---|---|
place |
object |
- Source:
Returns:
- Type
- Promise.<object>
filterPOIs(pois, filters) → {Array.<object>}
Filtrerar POI utifrån vilka checkboxar som är aktiva.
Parameters:
| Name | Type | Description |
|---|---|---|
pois |
Array.<object> | |
filters |
object |
Returns:
- Type
- Array.<object>
generateCandidatePlaces(center, radiusKm) → {Array.<object>}
Skapar kandidatplatser runt en startpunkt.
Parameters:
| Name | Type | Description |
|---|---|---|
center |
Array.<number> | |
radiusKm |
number |
- Source:
Returns:
- Type
- Array.<object>
geocodePlace(query) → {Promise.<Array.<number>>}
Geokodar en plats till koordinater.
Parameters:
| Name | Type | Description |
|---|---|---|
query |
string |
Returns:
[lon, lat]
- Type
- Promise.<Array.<number>>
(async) geocodePlace(query) → {Promise.<Array.<number>>}
Gör om ortnamn till koordinater [lon, lat].
Parameters:
| Name | Type | Description |
|---|---|---|
query |
string |
- Source:
Returns:
- Type
- Promise.<Array.<number>>
getActiveFilters() → {object}
Läser av vilka filter i 'Visa stopp längs vägen' som är aktiva just nu.
Returns:
- Type
- object
getClosestRouteIndex(poi, routeCoords) → {number}
Hittar index för den punkt i rutten som ligger närmast ett POI.
Parameters:
| Name | Type | Description |
|---|---|---|
poi |
object | |
routeCoords |
Array.<Array.<number>> |
Returns:
- Type
- number
getDistanceFromRouteKm(poi, routeCoords) → {number}
Räknar ut minsta avstånd i kilometer mellan ett POI och en rutt.
Jämför POI:t med alla koordinatpunkter i rutten och tar det minsta värdet.
Parameters:
| Name | Type | Description |
|---|---|---|
poi |
object | |
routeCoords |
Array.<Array.<number>> |
Returns:
- Type
- number
getDistanceKm(pointA, pointB) → {number}
Räknar ut ungefärligt avstånd i kilometer mellan två koordinater.
Använder Haversine-beräkning för sampling längs rutt.
Parameters:
| Name | Type | Description |
|---|---|---|
pointA |
Array.<number> | [lon, lat] |
pointB |
Array.<number> | [lon, lat] |
Returns:
- Type
- number
getDistanceKm(pointA, pointB) → {number}
Räknar ut avstånd i km mellan två punkter.
Parameters:
| Name | Type | Description |
|---|---|---|
pointA |
Array.<number> | |
pointB |
Array.<number> |
- Source:
Returns:
- Type
- number
getHourlyWeatherAtIndex(hourly, index) → {object|null}
Hämtar väderdata för en viss timme i prognosen.
Parameters:
| Name | Type | Description |
|---|---|---|
hourly |
object | |
index |
number |
- Source:
Returns:
- Type
- object | null
getPoiCategory(type) → {string}
Översätter teknisk POI-typ till ett användarvänligt kategorinamn.
Parameters:
| Name | Type | Description |
|---|---|---|
type |
string |
Returns:
- Type
- string
getPoiMarkerEmoji(poi) → {string}
Hämtar emoji för ett POI beroende på typ.
Parameters:
| Name | Type | Description |
|---|---|---|
poi |
object |
Returns:
- Type
- string
getPoiPlaceName(tags) → {string}
Hämtar platsnamn för ett POI från OSM-taggar.
Försöker hitta ort eller kommun i en enkel prioriterad ordning.
Parameters:
| Name | Type | Description |
|---|---|---|
tags |
object |
Returns:
- Type
- string
getRouteLengthKm(routeCoords) → {number}
Räknar ut ungefärlig total längd i kilometer för en rutt.
Parameters:
| Name | Type | Description |
|---|---|---|
routeCoords |
Array.<Array.<number>> |
Returns:
- Type
- number
getSamplePointsByDistance(routeCoords, sampleDistanceKm) → {Array.<Array.<number>>}
Väljer ut stopp-punkter med jämnt avstånd längs rutten.
Parameters:
| Name | Type | Description |
|---|---|---|
routeCoords |
Array.<Array.<number>> | |
sampleDistanceKm |
number |
Returns:
- Type
- Array.<Array.<number>>
getStopListLabel(poi) → {string}
Bygger etikett för stopp i listan.
Visar namn och ort om ort finns.
Parameters:
| Name | Type | Description |
|---|---|---|
poi |
object |
Returns:
- Type
- string
getSunnyPlaceMarkerEmoji(place) → {string}
Returnerar emoji för en väderplats.
Parameters:
| Name | Type | Description |
|---|---|---|
place |
object |
Returns:
- Type
- string
getUserPosition() → {Promise.<Array.<number>>}
Hämtar användarens position från webbläsaren.
Returnerar koordinater i formatet [lon, lat]
- Source:
Returns:
- Type
- Promise.<Array.<number>>
getWeatherIcon(weatherType) → {string}
Returnerar ikon för vald vädertyp.
Parameters:
| Name | Type | Description |
|---|---|---|
weatherType |
string |
- Source:
Returns:
- Type
- string
getWeatherLabel(weatherCode, cloudCover, precipitation) → {string}
Returnerar en enkel vädertext utifrån API-data.
Parameters:
| Name | Type | Description |
|---|---|---|
weatherCode |
number | |
cloudCover |
number | |
precipitation |
number |
- Source:
Returns:
- Type
- string
getWeatherType(weather) → {string}
Returnerar vädertyp för sortering och presentation.
Parameters:
| Name | Type | Description |
|---|---|---|
weather |
object |
- Source:
Returns:
- Type
- string
groupPOIsByCategory(pois) → {Object.<string, Array.<object>>}
Grupperar normaliserade POI efter kategori.
Parameters:
| Name | Type | Description |
|---|---|---|
pois |
Array.<object> |
Returns:
- Type
- Object.<string, Array.<object>>
groupSunPlacesByTime(places) → {Object.<string, Array.<object>>}
Grupperar väderplatser för nu, senare idag och imorgon.
Parameters:
| Name | Type | Description |
|---|---|---|
places |
Array.<object> |
- Source:
Returns:
- Type
- Object.<string, Array.<object>>
initMap(mapId, initialView, initialZoom) → {L.Map|null}
Initierar kartan.
Parameters:
| Name | Type | Description |
|---|---|---|
mapId |
string | |
initialView |
Array.<number> | [lat, lon] |
initialZoom |
number |
Returns:
- Type
- L.Map | null
initPOIModalEvents(pois, onShowOnMap)
Kopplar eventlyssnare i stopplistan till modal.
Eventen registreras en gång, men använder alltid senaste POI-listan.
Parameters:
| Name | Type | Description |
|---|---|---|
pois |
Array.<object> | |
onShowOnMap |
function |
initSunModalEvents(onShowOnMap)
Kopplar event till sol-modalen.
Körs en gång när solsidan startar.
Parameters:
| Name | Type | Description |
|---|---|---|
onShowOnMap |
function |
- Source:
initTheme()
Initierar temasystemet:
- laddar sparat tema
- sätter tema på body
- kopplar klick på knappar
initWeather()
Startar funktionalitet för solsidan.
- Source:
isGoodWeather(weather) → {boolean}
Avgör om vädret räknas som fint.
Parameters:
| Name | Type | Description |
|---|---|---|
weather |
object |
- Source:
Returns:
- Type
- boolean
limitPOIsPerCategory(groupedPOIs, maxPerCategory) → {Object.<string, Array.<object>>}
Begränsar antal POI per kategori.
Förutsätter att listan redan är sorterad i ruttens ordning.
Parameters:
| Name | Type | Description |
|---|---|---|
groupedPOIs |
Object.<string, Array.<object>> | |
maxPerCategory |
number |
Returns:
- Type
- Object.<string, Array.<object>>
normalizePOIs(pois) → {Array.<object>}
Normaliserar rå POI-data från Overpass till ett enhetligt format.
Parameters:
| Name | Type | Description |
|---|---|---|
pois |
Array.<object> |
Returns:
- Type
- Array.<object>
openPOIModal(poi)
Öppnar modalen och fyller den med information om valt stopp.
Parameters:
| Name | Type | Description |
|---|---|---|
poi |
object |
openSunModal(place)
Öppnar sol-modalen och fyller den med data om vald plats.
Parameters:
| Name | Type | Description |
|---|---|---|
place |
object |
- Source:
pickEvenlyDistributedPOIs(pois, maxPerCategory) → {Array.<object>}
Väljer ut POI jämnt utspridda över en redan sorterad lista.
Parameters:
| Name | Type | Description |
|---|---|---|
pois |
Array.<object> | |
maxPerCategory |
number |
Returns:
- Type
- Array.<object>
renderStopsGroups(groupedPOIs)
Renderar grupperade stopp i stopplistan.
Parameters:
| Name | Type | Description |
|---|---|---|
groupedPOIs |
Object.<string, Array.<object>> |
renderSunResultsList(places)
Renderar grupperade väderresultat i utfällbara listor.
Parameters:
| Name | Type | Description |
|---|---|---|
places |
Array.<object> |
- Source:
showPOIOnMap(poi)
Visar ett specifikt POI på kartan genom att zooma till markören
och öppna dess popup.
Parameters:
| Name | Type | Description |
|---|---|---|
poi |
object |
showSunnyPlaceOnMap(place)
Zoomar kartan till en specifik solplats (t.ex. vid klick i listan/modal)
och öppnar dess popup.
Parameters:
| Name | Type | Description |
|---|---|---|
place |
object |
sortAndNameSunGroupPlaces(places) → {Array.<object>}
Sorterar och döper om väderplatser inom en grupp.
Parameters:
| Name | Type | Description |
|---|---|---|
places |
Array.<object> |
- Source:
Returns:
- Type
- Array.<object>
sortPOIsAlongRoute(pois, routeCoords) → {Array.<object>}
Sorterar POI i den ordning de ligger längs rutten.
Närmaste punkt i routeCoords används som ungefärlig position.
Parameters:
| Name | Type | Description |
|---|---|---|
pois |
Array.<object> | |
routeCoords |
Array.<Array.<number>> |
Returns:
- Type
- Array.<object>
updateFavicon(theme)
Byter favicon utifrån valt tema
Parameters:
| Name | Type | Description |
|---|---|---|
theme |
string |
updateFilteredPOIView()
Uppdaterar karta och stopplista utifrån aktiva filter.