diff --git a/src/common/utilities.js b/src/common/utilities.js index 4c74d30..3e094ef 100644 --- a/src/common/utilities.js +++ b/src/common/utilities.js @@ -181,7 +181,11 @@ export function isLongitude (lng) { } export function mapClustersToLocations (clusters, locations) { - return clusters.map(cl => locations.find(location => location.label === cl.properties.id)) + return clusters.reduce((acc, cl) => { + const foundLocation = locations.find(location => location.label === cl.properties.id) + if (foundLocation) acc.push(foundLocation) + return acc + }, []) } export const dateMin = function () { diff --git a/src/components/Map.jsx b/src/components/Map.jsx index aa9c5d0..c0ab746 100644 --- a/src/components/Map.jsx +++ b/src/components/Map.jsx @@ -144,7 +144,7 @@ class Map extends React.Component { } loadClusterData (locations) { - if (locations && locations.length !== 0 && this.index) { + if (locations && locations.length > 0 && this.index) { const convertedLocations = locations.reduce((acc, loc) => { const { longitude, latitude } = loc const validCoordinates = !!latitude && !!longitude @@ -167,6 +167,8 @@ class Map extends React.Component { this.index.load(convertedLocations) this.setState({ indexLoaded: true }) this.update() + } else { + this.setState({ clusters: [] }) } }