Skip to content

Conversation

@geoerika
Copy link
Contributor

@geoerika geoerika commented Sep 22, 2021

Cluster implementation:

  1. Users have the choice to select between cluster or icon mode
  2. When cluster mode is used, cluster layer will be replaced with icon layer when, at any given zoom, cluster calculations don't return any cluster node for the POIs that are displayed in the current viewport.

Storybook: https://60f06c1c5a1772003b824d76-dbmgbrqtav.chromatic.com/
Logic for state use: https://www.figma.com/file/g2ww5nK6pazEWRTlmPKXXV/POIMap---cluster-logic

Recording:

Screen.Recording.2021-09-28.at.9.27.59.AM.mov

@geoerika geoerika marked this pull request as draft September 22, 2021 23:03
@geoerika geoerika changed the title [WIP] Poi map clusters [WIP] POIMap clusters Sep 22, 2021
… we see or not clusters in the current viewport
…luster to state and use it to change map layers and view
…erclusterRadius from constants and shared/utils
…tate; refactor useEffect for showClusters state; add onViewStateChange to get zoom; refactor onInteractionStateChange
…add switch for Show Clusters; adjust mapLayers to the new state; add conditions for switch elements
…onViewStateChange; move setLayerVisibleData to onAfterRender; fix useEffect fro clusterZoom
@geoerika geoerika force-pushed the POIMap-clusters branch 4 times, most recently from c40f0bb to 20238f9 Compare September 28, 2021 13:31
@geoerika geoerika changed the title [WIP] POIMap clusters [G2M] POIMap clusters Sep 28, 2021
@geoerika geoerika marked this pull request as ready for review September 28, 2021 13:40
Copy link
Contributor

@woozyking woozyking left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good, minor suggestions

Comment on lines 310 to 314
if (mapLayers.includes('POICluster')) {
setClusterClick(true)
} else {
setClusterClick(false)
}
Copy link
Contributor

@woozyking woozyking Sep 28, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  • perhaps
Suggested change
if (mapLayers.includes('POICluster')) {
setClusterClick(true)
} else {
setClusterClick(false)
}
setClusterClick(mapLayers.includes('POICluster'))

const index = new Supercluster({
maxZoom: props.superclusterZoom,
radius: props.getSuperclusterRadius(this.context.viewport.zoom, props.sizeScale),
radius: props.getSuperclusterRadius({ zoom: this.context.viewport.zoom }),
Copy link
Contributor

@woozyking woozyking Sep 28, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  • ```suggestion

      radius: props.getSuperclusterRadius(this.context.viewport),
    

Copy link

@kc-leung kc-leung left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

After I get zoom in by clicking a POI and I toggle the show cluster or show radius it zooms me back to its map original view. Is this how it supposed to behave?

Screen.Recording.2021-09-28.at.10.18.27.AM.mov

@geoerika
Copy link
Contributor Author

After I get zoom in by clicking a POI and I toggle the show cluster or show radius it zooms me back to its map original view. Is this how it supposed to behave?

Yes, the integration with POIManage will use the onClick event that will select an activePOI with the result of selecting that activePOI as the only POI on the map, so this is not seen in POIManage. Here is how it works:

Screen.Recording.2021-09-28.at.12.19.24.PM.mov

@geoerika geoerika force-pushed the POIMap-clusters branch 5 times, most recently from eef8978 to 55eecfb Compare September 29, 2021 23:47
@geoerika geoerika changed the title [G2M] POIMap clusters [WIP] POIMap clusters Sep 29, 2021
@geoerika geoerika marked this pull request as draft September 29, 2021 23:48
@geoerika geoerika force-pushed the POIMap-clusters branch 3 times, most recently from 1351464 to fe32f81 Compare September 30, 2021 22:58
…state in useLayoutEffect; simplify conditions for switch rendering
@geoerika geoerika force-pushed the POIMap-clusters branch 2 times, most recently from a50f011 to 4a600a1 Compare October 1, 2021 15:54
@geoerika geoerika changed the title [WIP] POIMap clusters [G2M] POIMap clusters Oct 1, 2021
@geoerika geoerika marked this pull request as ready for review October 1, 2021 17:21
@geoerika geoerika requested review from kc-leung and woozyking October 1, 2021 17:21
Copy link
Contributor

@woozyking woozyking left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

approved with some minor observations

*/
const setLayer = ({ layer, props, visible }) =>
layer === 'POICluster' ?
new eqMapLayers[layer]({ ...props, visible }) :
Copy link
Contributor

@woozyking woozyking Oct 1, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  • why does the POICluster type layer require new to instantiate?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cluster layer is a class component - I am pretty sure you asked that before, like a year ago LOL. When I have time will try change it into function.
Source: https://github.com/visgl/deck.gl/blob/8.5-release/examples/website/icon/icon-cluster-layer.js

*/
export const isClusterZoomLevel = ({ layerVisibleData, viewportBBOX, zoom }) => {
const visiblePOIs = layerVisibleData.reduce((agg, elem) => {
return elem.objects ? [...agg, ...elem.objects] : [...agg, elem.object]
Copy link
Contributor

@woozyking woozyking Oct 1, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  • would you mean
return Array.isArray(elem.objects) ? [...agg, ...elem.objects] : [...agg, elem.object]

Copy link
Contributor Author

@geoerika geoerika Oct 1, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No need, as 'objects' key doesn't exist when we have just one element in Cluster layer. It only exists at all when we have a cluster of locations.
So, this is how an icon with number one looks like in layerVisibleData:
Screen Shot 2021-10-01 at 4 00 45 PM

This is how a cluster with several locations looks like:
Screen Shot 2021-10-01 at 4 01 02 PM

return elem.objects ? [...agg, ...elem.objects] : [...agg, elem.object]
}, [])

if (visiblePOIs?.length) {
Copy link
Contributor

@woozyking woozyking Oct 1, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  • with a reduce operation like ^ visiblePOIs should be guaranteed as an Array, thus the optional chain should be unnecessary

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

squashed

… there was a delay in the POICluster of calc zoom and we had cluster icons changing quick between 2 zooms; set transitionDuration to 2 sec; remove optional chain for visiblePOI in isClusterZoomLevel
@geoerika geoerika merged commit dcdc955 into master Oct 1, 2021
@geoerika geoerika deleted the POIMap-clusters branch October 1, 2021 20:12
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants