Skip to content

Commit

Permalink
Fix initialization of enable3DView state
Browse files Browse the repository at this point in the history
  • Loading branch information
willemarcel committed Nov 19, 2024
1 parent 471213a commit 44c6580
Showing 1 changed file with 4 additions and 5 deletions.
9 changes: 4 additions & 5 deletions src/components/deployments/map.js
Original file line number Diff line number Diff line change
Expand Up @@ -54,10 +54,7 @@ export const DeploymentMap = ({
loading: geojsonLoading,
} = useFetch(`/casei/flight-tracks/${replaceSlashes(campaignName)}.geojson`)
const geojsonBbox = !!geojson && bbox(geojson)
const [enable3DView, setEnable3DView] = useState(
// if the geojson crosses the 80º or -80º latitude, enables 3D view by default
geojsonBbox[1] < -80 || geojsonBbox[3] > 80
)
const [enable3DView, setEnable3DView] = useState(false)
const platforms = getUniquePlatforms(
deployments.flatMap(d => d.collectionPeriods)
).map(i => ({ name: i.item.shortname, type: i.item.platformType.shortname }))
Expand All @@ -66,14 +63,16 @@ export const DeploymentMap = ({
f => f.properties.platform_name
)
const [selectedPlatforms, setSelectedPlatforms] = useState([])
// Set all platforms as selected after the geojson is loaded
useEffect(() => {
if (!geojsonLoading && !selectedPlatforms.length) {
// Set all platforms as selected after the geojson is loaded
setSelectedPlatforms(
platformNames
.filter((name, index) => platformNames.indexOf(name) === index)
.filter(name => platformsWithData?.includes(name))
)
// if the geojson crosses the 80º or -80º latitude, enables 3D view by default
setEnable3DView(geojsonBbox[1] < -80 || geojsonBbox[3] > 80)
}
}, [selectedPlatforms, geojsonLoading])

Expand Down

0 comments on commit 44c6580

Please sign in to comment.