Skip to content

Commit

Permalink
no need promise
Browse files Browse the repository at this point in the history
  • Loading branch information
bvandercar-vt committed Jun 20, 2024
1 parent b41996a commit d488d21
Showing 1 changed file with 31 additions and 33 deletions.
64 changes: 31 additions & 33 deletions src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,9 @@ import _ from 'lodash'
import { DateTime } from 'luxon'
import { type CustomGeoJson } from './mapMyRide'

const METERS_TO_MILES = 0.000621371
const METERS_TO_FEET = 3.28084

const map = createMap('map', {
center: latLng(39.7327258, -104.9851469),
zoom: 13,
Expand Down Expand Up @@ -57,42 +60,37 @@ const lineStyleHovered: PathOptions = {
import geoJsons_ from '../geoJsons.json' assert { type: 'json' }
const geoJsons = geoJsons_ as CustomGeoJson[]

const METERS_TO_MILES = 0.000621371
const METERS_TO_FEET = 3.28084

await Promise.all(
geoJsons.map(async (geoJson) => {
const { workout, route } = geoJson.properties
const feature = geoJSON(geoJson, {
style: lineStyle,
filter: (feature) => feature.geometry.type !== 'Point',
}).addTo(map)
geoJsons.forEach((geoJson) => {
const { workout, route } = geoJson.properties
const feature = geoJSON(geoJson, {
style: lineStyle,
filter: (feature) => feature.geometry.type !== 'Point',
}).addTo(map)

const date = DateTime.fromISO(workout.start_datetime)
const dateStr = date.toFormat('EEE. MMMM d, yyyy h:mma')
const distanceStr = _.round(route.distance * METERS_TO_MILES, 1)
const ascentStr = _.round(route.total_ascent * METERS_TO_FEET, 0)
const popover = document.createElement('div')
popover.classList.add('route-popover')
popover.innerHTML = `<b>${dateStr}</b><br><i><b>Distance: ${distanceStr}mi</b></i><br><i>Total Ascent: ${ascentStr}ft</i>`
const date = DateTime.fromISO(workout.start_datetime)
const dateStr = date.toFormat('EEE. MMMM d, yyyy h:mma')
const distanceStr = _.round(route.distance * METERS_TO_MILES, 1)
const ascentStr = _.round(route.total_ascent * METERS_TO_FEET, 0)
const popover = document.createElement('div')
popover.classList.add('route-popover')
popover.innerHTML = `<b>${dateStr}</b><br><i><b>Distance: ${distanceStr}mi</b></i><br><i>Total Ascent: ${ascentStr}ft</i>`

let layerPopup: Popup | null
const createPopover = function (e: LeafletMouseEvent) {
layerPopup = popup().setLatLng(e.latlng).setContent(popover.outerHTML).openOn(map)
feature.setStyle(lineStyleHovered)
feature.bringToFront()
let layerPopup: Popup | null
const createPopover = function (e: LeafletMouseEvent) {
layerPopup = popup().setLatLng(e.latlng).setContent(popover.outerHTML).openOn(map)
feature.setStyle(lineStyleHovered)
feature.bringToFront()
}
feature.on('mouseover', createPopover)
feature.on('click', createPopover)
feature.on('mouseout', function () {
if (layerPopup) {
map.closePopup(layerPopup)
layerPopup = null
}
feature.on('mouseover', createPopover)
feature.on('click', createPopover)
feature.on('mouseout', function () {
if (layerPopup) {
map.closePopup(layerPopup)
layerPopup = null
}
feature.setStyle(lineStyle)
})
}),
)
feature.setStyle(lineStyle)
})
})

const numRoutes = geoJsons.length
const distances = geoJsons.map(({ properties }) => properties.route.distance)
Expand Down

0 comments on commit d488d21

Please sign in to comment.