如何使用MapBox和React Native将地图置于单击的符号中心?

问题描述 投票:0回答:1

花了很长时间试图这样做:Mapbox在这里展示了如何做到这一点,但我不确定它在React Native中是如何工作的:https://docs.mapbox.com/mapbox-gl-js/example/center-on-symbol/

我正在使用ShapeSource和SymboLayer,从geoJson获取我的标记。我似乎无法定位特定图标及其'坐标。我尝试过类似的东西,但它只需要到第一个功能位置(而不是点击特定图标的位置):

onPress = {()=> {this._map.flyTo(featureCollection.features.geometry(0).coordinates,1000);}}

我的功能如下所示:

{“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”: “餐厅”,“图标”:“食物”},“几何”:{“类型”:“点”,“坐标”:[12.585264,55.683441]}}}

谢谢!

react-native mapbox
1个回答
2
投票

我想我找到了一个合适的答案,但如果你有更好的答案,请纠正我:

constructor(props) {
    super(props);
    this.onPress = this.onPress.bind(this);
  }

  async onPress(e) {
    const feature = e.nativeEvent.payload;
    this.map.flyTo(feature.geometry.coordinates, 1000);
© www.soinside.com 2019 - 2024. All rights reserved.