Updating MapboxGL.ShapeSource clusterMaxZoomLevel not working
See original GitHub issueDescribe the bug
Setting clusterMaxZoomLevel initially works, but if it needs to be updated after ShapeSource was added to the map, setting clusterMaxZoomLevel is not having any effect on the map layer.
To Reproduce
- Create a ShapeSource with an initial clusterMaxZoomLevel stored in the state.
- Use a setTimeout to change the clusterMaxZoomLevel in the state, this triggers a render with the new state.
Expected result The symbols to be rendered using a different clusterMaxZoomLevel
Actual result The symbols are rendered with the initial clusterMaxZoomLevel
Example:
import React from 'react';
import {View} from 'react-native';
import MapboxGL from '@react-native-mapbox-gl/maps';
const SF_OFFICE_COORDINATE = [-122.400021, 37.789085];
const styleMatchParent = {flex: 1};
const layerStyles = {
singlePoint: {
circleColor: 'green',
circleOpacity: 0.84,
circleStrokeWidth: 2,
circleStrokeColor: 'white',
circleRadius: 5,
circlePitchAlignment: 'map',
},
clusteredPoints: {
circlePitchAlignment: 'map',
circleColor: [
'step',
['get', 'point_count'],
'#51bbd6',
100,
'#f1f075',
750,
'#f28cb1',
],
circleRadius: ['step', ['get', 'point_count'], 20, 100, 30, 750, 40],
circleOpacity: 0.84,
circleStrokeWidth: 2,
circleStrokeColor: 'white',
},
clusterCount: {
textField: '{point_count}',
textSize: 12,
textPitchAlignment: 'map',
},
};
class App extends React.Component {
constructor(props) {
super(props);
this.state = {
clusterMaxZoomLevel: 3,
};
}
componentDidMount() {
setTimeout(() => {
console.log('Set clusterMaxZoomLevel to 13');
this.setState({
clusterMaxZoomLevel: 13,
});
}, 15000);
}
render() {
const {clusterMaxZoomLevel} = this.state;
return (
<View style={styleMatchParent}>
<MapboxGL.MapView
style={styleMatchParent}
styleURL={MapboxGL.StyleURL.Dark}>
<MapboxGL.Camera
zoomLevel={8}
pitch={45}
centerCoordinate={SF_OFFICE_COORDINATE}
/>
<MapboxGL.ShapeSource
id="earthquakes"
cluster
clusterRadius={50}
clusterMaxZoomLevel={clusterMaxZoomLevel}
url="https://earthquake.usgs.gov/earthquakes/feed/v1.0/summary/all_week.geojson">
<MapboxGL.SymbolLayer
id="pointCount"
style={layerStyles.clusterCount}
/>
<MapboxGL.CircleLayer
id="clusteredPoints"
belowLayerID="pointCount"
filter={['has', 'point_count']}
style={layerStyles.clusteredPoints}
/>
<MapboxGL.CircleLayer
id="singlePoint"
filter={['!', ['has', 'point_count']]}
style={layerStyles.singlePoint}
/>
</MapboxGL.ShapeSource>
</MapboxGL.MapView>
</View>
);
}
}
export default App;
Additional context
In our use case, we are rendering on the map user-created points and the user has the option to change the clusterMaxZoomLevel from the app for the points and changing it after it is added to the map is not working.
Issue Analytics
- State:
- Created 3 years ago
- Comments:8 (6 by maintainers)
Top Results From Across the Web
Updating MapboxGL.ShapeSource clusterMaxZoomLevel not ...
Describe the bug Setting clusterMaxZoomLevel initially works, but if it needs to be updated after ShapeSource was added to the map, ...
Read more >How to update MapboxGL.ShapeSource dynamically?
To make it short : I wanted to use dynamics SVGs as SymbolLayer (so that I can change the colour for instance), but...
Read more >rnmapbox/Lobby - Gitter
Hello, I am a beginner in programming and I would like you to help me solve a configuration problem with react native mapbox....
Read more >How to update MapboxGL.ShapeSource dynamically?-Reactjs
The whole discussion about the subject is in here: https://github.com/react-native-mapbox-gl/maps/issues/248. To make it short : I wanted to use dynamics ...
Read more >react-native-mapbox-gl/maps/index.d.ts - UNPKG
The CDN for @react-native-mapbox-gl/maps. ... as mentioned in issue https://github.com/react-native-mapbox-gl/maps/issues/1213 ... 289, refresh(): void;.
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
This issue is still relevant, but unfortunately we haven’t had time to look into it.
Is it possible that a maintainer can open it again so it doesn’t get lost?
On v10/iOS we cannot implement this because: #1641 also not supported on android.