ShapeSource does not update dynamically
See original GitHub issueDescribe the bug
When a SymbolLayer
is dynamically added to a ShapeSource
, it seems it is not shown.
To Reproduce
Based on CustomIcon
example, I replaced the code with the code below. To reproduce, just copy-paste the code in place of the existing code in CustomIcon
example.
import React from 'react';
import { View, Text } from 'react-native';
import MapboxGL from '@react-native-mapbox-gl/maps';
import sheet from '../styles/sheet';
import BaseExamplePropTypes from './common/BaseExamplePropTypes';
import Page from './common/Page';
import Bubble from './common/Bubble';
const styles = {
icon: {
iconAllowOverlap: true,
},
view: {
width: 60,
height: 60,
borderColor: 'black',
borderWidth: 1,
alignItems: 'center',
justifyContent: 'center'
},
text: {
fontSize: 50
}
};
const customIcons = ['😀', '🤣', '😋', '😢', '😬']
class CustomIcon extends React.Component {
constructor(props) {
super(props);
this.state = {
featureCollection: {
type: 'FeatureCollection',
features: [{
type: 'Feature',
geometry: {
coordinates: [-73.970895, 40.723279],
type: 'Point'
},
id: 1,
properties: {
customIcon: customIcons[0]
}
}]
},
};
this.onPress = this.onPress.bind(this);
this.onSourceLayerPress = this.onSourceLayerPress.bind(this);
}
onPress(e) {
const feature = {
type: 'Feature',
geometry: e.geometry,
id: Date.now(),
properties: {
customIcon: customIcons[this.state.featureCollection.features.length]
}
};
this.setState(({ featureCollection }) => ({
featureCollection: {
type: 'FeatureCollection',
features: [
...featureCollection.features,
feature
]
}
}));
}
onSourceLayerPress(e) {
const feature = e.nativeEvent.payload;
console.log('You pressed a layer here is your feature', feature); // eslint-disable-line
}
render() {
return (
<Page {...this.props}>
<MapboxGL.MapView
ref={c => (this._map = c)}
onPress={this.onPress}
style={sheet.matchParent}
>
<MapboxGL.Camera
zoomLevel={9}
centerCoordinate={[-73.970895, 40.723279]}
/>
<MapboxGL.ShapeSource
id="symbolLocationSource"
hitbox={{width: 20, height: 20}}
onPress={this.onSourceLayerPress}
shape={this.state.featureCollection}
>
{this.state.featureCollection.features.map((feature, ind) => (
<MapboxGL.SymbolLayer
id={"symbolLocationSymbols" + feature.id}
key={feature.id}
filter={['==', 'customIcon', customIcons[ind]]}
minZoomLevel={1}
style={styles.icon}
>
<View style={styles.view}>
<Text style={styles.text}>
{feature.properties.customIcon}
</Text>
</View>
</MapboxGL.SymbolLayer>
))}
</MapboxGL.ShapeSource>
</MapboxGL.MapView>
<Bubble>
<Text>Tap to add an icon</Text>
</Bubble>
</Page>
);
}
}
export default CustomIcon;
Expected behavior “Tap to add an icon”
Versions (please complete the following information):
- Platfrom: [iOS]
- Device: [iPhone5, iOS 10.3]
- OS: [iOS 10.3]
react-native-mapbox-gl/maps
version: 7.0.0-rc3- React Native Version 0.59.8
Issue Analytics
- State:
- Created 4 years ago
- Reactions:7
- Comments:21 (11 by maintainers)
Top Results From Across the Web
ShapeSource does not update dynamically #248 - GitHub
Describe the bug When a SymbolLayer is dynamically added to a ShapeSource, it seems it is not shown. To Reproduce Based on CustomIcon ......
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 >How to update MapboxGL.ShapeSource dynamically?-Reactjs
To make it short : I wanted to use dynamics SVGs as SymbolLayer (so that I can change the colour for instance), but...
Read more >MGLShapeSource Class Reference - Mapbox
You can update a shape source by setting its shape or URL property. MGLShapeSource is optimized for data sets that change dynamically and...
Read more >rnmapbox/Lobby - Gitter
I using a shapesource and symbol layer to dynamically load markers with remote ... The issue is resolved if i "refresh" the map...
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 FreeTop 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
Top GitHub Comments
@mfazekas, @kristfal do you know anything about why this happens? It makes it kinda impossible to create a map with annotations that are queried from an API and displayed dynamically, which is a rather common use case for annotations and is what I am trying to as well.
I confirm, It’s a big issue with this library right now. I’d like to help.