Spent a long time trying to do this: Mapbox show how to do it here, but I'm unsure how it works in React Native: https://docs.mapbox.com/mapbox-gl-js/example/center-on-symbol/
I'm using ShapeSource and SymboLayer, getting my markers from a geoJson. I can't seem to target the specific icon and its' coordinates. I've tried something like this, but it just takes be to the first feature location (not the location of the specific icon clicked):
onPress={() => {this._map.flyTo(featureCollection.features.geometry(0).coordinates, 1000);}}
My features look like this:
{ "type": "FeatureCollection", "features": [ { "type": "Feature", "id": 1, "properties": { "name": "Hotel", "icon": "sleep" }, "geometry": { "type": "Point", "coordinates": [ 12.584664, 55.680532 ] } }, { "type": "Feature", "id": 2, "properties": { "name": "Restaurant", "icon": "food" }, "geometry": { "type": "Point", "coordinates": [ 12.585264, 55.683441 ] } } }
Thanks!
onPress={() => {this._map.flyTo(featureCollection.features[0].geometry.coordinates, 1000);}}
Also can you post an example of your feature? – cb64map.on('click', 'myLayer', function (e){})
and you need to capture the target withe.features[0].geometry.coordinates.slice();
so maybe tryonPress={(e) => {this._map.flyTo(e.features[0].geometry.coordinates, 1000);}}
oronPress={(e) => {this._map.flyTo(e.features[0].geometry.coordinates.slice(), 1000);}};
– cb64