【发布时间】:2021-07-06 09:48:56
【问题描述】:
我有一个湖泊和河流的 GeoJSON 数据。我正在使用下面的代码显示它们。
<MapView.Geojson
geojson={barajVeGolet}
strokeColor="#39A2DB"
fillColor="#D0E8F2"
strokeWidth={3}
/>
该组件将地图中的数据呈现如下图。
MapView.Geojson Component display example
我希望在用户点击湖内任意位置时出现一个弹出窗口,例如标记。
我尝试过的:
我用TouchableOpacity 组件包裹了MapView.Geojson,以便使用
它的onPress 属性。
<TouchableOpacity onPress={onPress}>
<MapView.Geojson
geojson={barajVeGolet}
strokeColor="#39A2DB"
fillColor="#D0E8F2"
strokeWidth={3}
></MapView.Geojson>
</TouchableOpacity>
我使用了MapView.Geojson 的onPress 属性
<MapView.Geojson
geojson={barajVeGolet}
strokeColor="#39A2DB"
fillColor="#D0E8F2"
strokeWidth={3}
onPress={onPress}
></MapView.Geojson>
我在MapView.Geojson 中放了一个Callout 组件并带有文本
<MapView.Geojson
geojson={barajVeGolet}
strokeColor="#39A2DB"
fillColor="#D0E8F2"
strokeWidth={3}
>
<MapView.Callout>
<View style={{ width: 200 }}>
<Text style={styles.barajInfoTitle}>Test</Text>
</View>
</MapView.Callout>
</MapView.Geojson>
有什么方法可以点击 Geojson 或 Polygon 组件内的任意位置,这会打开一个弹出窗口,就像 Marker 组件一样?
【问题讨论】:
标签: javascript reactjs react-native geojson react-native-maps