maps: ShapeSource does not update dynamically
Describe 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/mapsversion: 7.0.0-rc3- React Native Version 0.59.8
About this issue
- Original URL
- State: closed
- Created 5 years ago
- Reactions: 7
- Comments: 21 (11 by maintainers)
@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.
This is a problem still
Using the newest version of this has not helped my problem. To add to the pool of knowledge, I believe the issue is within the
ShapeSource, if I add a key that updates when theShapeupdates then the icons will properly appear. If I can find out exactly what up in the code, I’ll open a PR and see about fixing this.@arnaudambro This app adds a point onclick and then remove it when clicked again. https://gyazo.com/e68cb2ed6ee0e47246b8588af9f651eb
I guess it’s something with indexing, let’s take my scenario : I have six points on the map. When I delete the for example the third point it will delete it normally. now I have only 5 points , when trying to delete the 4th point (5th point before deletion) the third point will be deleted (which is the 4th point without deletion).