From 5333f492f8722c49d80c34b1f4580cb4d144e30f Mon Sep 17 00:00:00 2001 From: efarooqui Date: Wed, 30 Sep 2020 13:07:29 -0700 Subject: [PATCH] Getting appropriate clusterZoom; flyto moving to incorrect location on map --- src/common/utilities.js | 4 ++-- src/components/Map.jsx | 11 ++++++++++- src/components/presentational/Map/Clusters.jsx | 8 ++++++-- src/store/initial.js | 4 ++-- 4 files changed, 20 insertions(+), 7 deletions(-) diff --git a/src/common/utilities.js b/src/common/utilities.js index e78bfdc..8a8ed67 100644 --- a/src/common/utilities.js +++ b/src/common/utilities.js @@ -74,8 +74,8 @@ export function insetSourceFrom (allSources) { if (!event.sources) { sources = [] } else { - sources = event.sources.map(src => { - const id = typeof src === 'object' ? src.id : src + sources = event.sources.map(id => { + // const id = typeof src === 'object' ? src.id : src return allSources.hasOwnProperty(id) ? allSources[id] : null }) } diff --git a/src/components/Map.jsx b/src/components/Map.jsx index add532c..492d152 100644 --- a/src/components/Map.jsx +++ b/src/components/Map.jsx @@ -27,6 +27,7 @@ class Map extends React.Component { super() this.projectPoint = this.projectPoint.bind(this) this.locationToGeoJSON = this.locationToGeoJSON.bind(this) + this.onClusterSelect = this.onClusterSelect.bind(this) this.svgRef = React.createRef() this.map = null this.index = null @@ -188,6 +189,14 @@ class Map extends React.Component { return feature } + onClusterSelect (e) { + const { id } = e.target + const { longitude, latitude } = e.target.attributes + const { x, y } = this.projectPoint([latitude.value, longitude.value]) + const expansionZoom = Math.max(this.index.getClusterExpansionZoom(parseInt(id)), this.index.options.minZoom) + this.map.flyTo([x, y], expansionZoom) + } + getClientDims () { const boundingClient = document.querySelector(`#${this.props.ui.dom.map}`).getBoundingClientRect() @@ -296,7 +305,7 @@ class Map extends React.Component { projectPoint={this.projectPoint} clusters={allClusters} numClusters={allClusters.length} - // onSelect={() => {}} + onSelect={this.onClusterSelect} /> ) } diff --git a/src/components/presentational/Map/Clusters.jsx b/src/components/presentational/Map/Clusters.jsx index c1ab621..f7164ab 100644 --- a/src/components/presentational/Map/Clusters.jsx +++ b/src/components/presentational/Map/Clusters.jsx @@ -6,13 +6,15 @@ import { calcOpacity, calcClusterSize } from '../../../common/utilities' function ClusterEvents ({ projectPoint, styleCluster, - // onSelect, + onSelect, svg, clusters, numClusters, }) { function renderClusterBySize (cluster) { const { point_count: pointCount, cluster_id: clusterId } = cluster.properties + const { coordinates } = cluster.geometry + const [longitude, latitude] = coordinates const styles = ({ fill: colors.fallbackEventColor, @@ -26,6 +28,8 @@ function ClusterEvents ({ { onSelect(e)} > {renderClusterBySize(cluster)} {extraRender ? extraRender() : null} diff --git a/src/store/initial.js b/src/store/initial.js index d811cbd..b26b85d 100644 --- a/src/store/initial.js +++ b/src/store/initial.js @@ -49,11 +49,11 @@ const initial = { map: { anchor: [31.356397, 34.784818], startZoom: 11, - minZoom: 6, + minZoom: 2, maxZoom: 18, bounds: null, maxBounds: [[180, -180], [-180, 180]], - clusterRadius: 50, + clusterRadius: 20, }, timeline: { dimensions: {