繁体   English   中英

当标记在重新加载时移除时,react-native-maps 中的标注视图不会消失

[英]callout View in react-native-maps does not disappear when the marker is remove on reload

我正在为我的 react-native 项目使用 react-native-maps。 我在地图上显示从 UI 分配和取消分配的标记。 我使用 API 来获取标记数据并将它们显示在地图中。 每个标记都有一个标题和描述,单击标记时会显示这些标题和描述。

                   <MapView.Marker
                        coordinate={{ latitude:lat, longitude:lon }}
                        title={title}
                        description={desc}
                        image={image}
                        onCalloutPress={this.onPress()}>
                    </MapView.Marker>

但是,当我单击一个标记然后从 UI 中删除该标记时。 我会收到通知并重新加载新数据。 但 callOut 不会被删除,而是会转到最近的标记处。

重新加载标记数据时,如何关闭或删除 callOut?

注意:我无法重新加载整个地图,所以我使用 fetch 来获取最新数据并更新它们。

以下对我有用。 当您需要隐藏它时,尝试调用this.marker.hideCallout()怎么样?

<MapView.Marker
        coordinate={coord}
        ref={_marker => {
          this.marker = _marker;
        }}
        onPress={() => {}}
        onCalloutPress={() => {
          this.marker.hideCallout();
        }}>
        <Image
          source={require(img)}
          style={{ width: 60, height: 60 }}
        />
        <View>
          <Text>
            marker text
          </Text>
        </View>
        <MapView.Callout
          tooltip={true}>
              <View>
                <Text>
                  callout text
                </Text>
              </View>
        </MapView.Callout>
      </MapView.Marker>

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM