From aee535025922be83f25aa711660deedeaa0e40bd Mon Sep 17 00:00:00 2001 From: Victor Berchet Date: Fri, 29 Mar 2024 13:24:25 +0100 Subject: [PATCH] Fix div by 0 --- .../fxc-front/src/app/components/2d/adv-marker-element.ts | 3 +-- apps/fxc-front/src/app/components/2d/marker-element.ts | 8 ++++---- 2 files changed, 5 insertions(+), 6 deletions(-) diff --git a/apps/fxc-front/src/app/components/2d/adv-marker-element.ts b/apps/fxc-front/src/app/components/2d/adv-marker-element.ts index 10a34bc4..42732abf 100644 --- a/apps/fxc-front/src/app/components/2d/adv-marker-element.ts +++ b/apps/fxc-front/src/app/components/2d/adv-marker-element.ts @@ -72,8 +72,7 @@ export class AdvancedMarkerElement extends LitElement { disconnectedCallback() { super.disconnectedCallback(); google.maps.event.clearInstanceListeners(this.marker_); - // setTimeout is needed otherwise the marker isn't removed. - setTimeout(() => (this.marker_.map = null), 0); + this.marker_.map = null; } render() { diff --git a/apps/fxc-front/src/app/components/2d/marker-element.ts b/apps/fxc-front/src/app/components/2d/marker-element.ts index 0ad438bd..b901fa31 100644 --- a/apps/fxc-front/src/app/components/2d/marker-element.ts +++ b/apps/fxc-front/src/app/components/2d/marker-element.ts @@ -8,6 +8,7 @@ import { RootState, store } from '../../redux/store'; import { setCurrentTrackId } from '../../redux/track-slice'; import './adv-marker-element'; +import { round } from '@flyxc/common'; const INACTIVE_OPACITY = 0.5; @@ -81,10 +82,9 @@ export class MarkerElement extends connect(store)(LitElement) { const { lat, lon, alt } = sel.getTrackLatLonAlt(store.getState())(timeSec, this.track) as common.LatLonAlt; const altAboveMin = (alt ?? 0) - this.track.minAlt; const altDelta = this.track.maxAlt - this.track.minAlt; - const scale = (50 * altAboveMin) / altDelta + 20; - // todo - this.path.setAttribute('transform', `scale(${scale / 512})`); - this.path.setAttribute('stroke-width', `${2 / (scale / 512)}`); + const scale = 20 + (50 * altAboveMin) / Math.max(altDelta, 1); + this.path.setAttribute('transform', `scale(${round(scale / 512, 4)})`); + this.path.setAttribute('stroke-width', `${round(2 / (scale / 512), 4)}`); let label = ''; if (this.displayLabels) {