我想在json文件中按下一个按钮并在地图上显示时按名称调用特定对象。然后缩放并在该标记上放置地图。
Json文件的结构:
type": "FeatureCollection",
"features": [
{
"type": "Feature",
"geometry": {
"type": "Point",
"coordinates": [26.41389781, 41.9425557]
},
"properties": {
"Name": "Парцел 1",
"Crops": "Ябълки"
}
},
{
"type": "Feature",
"geometry": {
"type": "Point",
"coordinates": [26.41472289, 41.95044877]
},
"properties": {
"Name": "Парцел 2",
"Crops": "Ябълки"
}
},
当我有一个状态为true或false时。当为false时,地图上没有标记,但是为true时,它显示了传单地图上的所有标记。现在我要有两个或三个按钮,并且当按下以调用json文件中的特定标记并在地图上显示时]
按钮代码,单击使条件为真:
<button value={this.state.geojsonvisible} onClick={this.onGeojsonToggle} > Object 1 </button>
显示标记的弹出窗口:
onEachFeaturePoint(feature, layer) { console.log("feature: ", feature); console.log("layer: ", layer); var popupContent = feature.properties.Name + " " + feature.properties.Crops; layer.bindPopup(popupContent); layer.on({ click: function (e) { console.log("e: ", e); console.log("click"); }, }); }
这是我的geojson标签:
{this.state.geojsonvisible && (
<GeoJSON
data={points}
onEachFeature={this.onEachFeaturePoint.bind(this)}
// pointToLayer={this.pointToLayer.bind(this)}
/>
)}
我想在json文件中按下一个按钮并在地图上显示时按名称调用特定对象。然后缩放并在该标记上放置地图。 Json文件的结构:类型“:” ...
将标记坐标放置在featureGroup
上,并使用所选标记所驻留的组的边界来拟合地图的边界。