Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement clustering properties to ShapeSource for v10 mapbox versions #1916

Closed
woodybury opened this issue May 19, 2022 · 0 comments · Fixed by #1922
Closed

Implement clustering properties to ShapeSource for v10 mapbox versions #1916

woodybury opened this issue May 19, 2022 · 0 comments · Fixed by #1922
Labels
bug 🪲 Something isn't working v10

Comments

@woodybury
Copy link

woodybury commented May 19, 2022

Describe the bug
Recent PR "Implement clustering properties to ShapeSource" #1745 implemented clusterProperties attribute for ShapeSource, which enables declaring custom aggregated properties for clustered features on the map (feature request #693) 🎉

However, it's not yet implemented for v10 mapbox versions.

To Reproduce

  • Create example app using latest from rnmapbox/maps#main and $RNMapboxMapsVersion = '~> 10.5.0-beta1'
  • Create ShapeSource w/ clusterProperties
  • Notice clusterProperties do not show up on clustered SymbolLayer

Example:

import React from 'react';
import { Button } from 'react-native';
import {
  MapView,
  ShapeSource,
  SymbolLayer,
  CircleLayer,
  Camera,
} from '@rnmapbox/maps';

const styles = {
  mapView: { flex: 1 },
  circleLayer: {
    circleRadiusTransition: { duration: 5000, delay: 0 },
    circleColor: '#ff0000',
  },
};

const features = {
  type: 'FeatureCollection',
  features: [
    {
      type: 'Feature',
      id: 'a-feature',
      properties: {
        icon: 'example',
        text: 'example-icon-and-label',
        count: 2
      },
      geometry: {
        type: 'Point',
        coordinates: [-74.00597, 40.71427],
      },
    },
    {
      type: 'Feature',
      id: 'b-feature',
      properties: {
        text: 'just-label',
        count: 1
      },
      geometry: {
        type: 'Point',
        coordinates: [-74.001097, 40.71527],
      },
    },
    {
      type: 'Feature',
      id: 'c-feature',
      properties: {
        icon: 'example',
        count: 3
      },
      geometry: {
        type: 'Point',
        coordinates: [-74.00697, 40.72427],
      },
    },
  ],
};

class BugReportExample extends React.Component {
  state = {
    radius: 20,
  };

  render() {
    const circleLayerStyle = {
      ...styles.circleLayer,
      ...{ circleRadius: this.state.radius },
    };

    return (
      <>
        <Button
          title="Grow"
          onPress={() => this.setState({ radius: this.state.radius + 20 })}
        />
        <MapView style={styles.mapView}>
          <Camera centerCoordinate={[-74.00597, 40.71427]} zoomLevel={14} />
          <ShapeSource 
             id={'shape-source-id-0'} 
             shape={features}
             cluster={true}
	    clusterMaxZoom={14}
	    clusterRadius={50}
	    clusterProperties={{
		sum: [["+", ["accumulated"], ["get", "sum"]], ["get", "count"]],
	    }}
          >
            <SymbolLayer
		filter={['has', 'point_count']}
		id="pointCount"
		style={{
	                textField: ['get', 'sum'],
	                textSize: 12,
	                textColor: 'white',
	                textPitchAlignment: 'map',
                }}
	     />
            <CircleLayer id={'circle-layer'} style={circleLayerStyle} />
            <SymbolLayer
              id="symbol-id"
              style={{
                iconImage: ['get', 'icon'],
              }}
            />
          </ShapeSource>
        </MapView>
      </>
    );
  }
}

export default BugReportExample;

Expected behavior
Clustered SymbolLayer should render the calculated sum from the cluster properties

Actual behavior
The cluster properties are not passed to the clustered SymbolLayer

Versions (please complete the following information):

  • Platform: iOS
  • Platform OS: iOS 15.2
  • Device: iPhone 12
  • Emulator/ Simulator: both
  • Dev OS: OSX
  • @rnmapbox/maps latest from #main
  • Mapbox GL version 10.5.0-beta1
  • React Native Version 0.64.3
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug 🪲 Something isn't working v10
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants