弹出 React 传单地图库

Pop up on react leaflet map library

我在我的 React 应用程序中使用 react-leaftlet 地图库 https://react-leaflet.js.org/en/,我在地图上渲染了一些标记,当用户点击标记时,会出现一个弹出窗口。当用户点击我的地图区域时,我也想打开一个类似的弹出窗口。我怎样才能做到这一点?以下是我使用弹出窗口呈现标记的代码。 (地图使用geojson数据渲染)

markerHospitalRender() {
    return this.props.hospitalData.map(item => {
      const position = [item.district_lat, item.district_long];
      return (
        <Marker position={position} icon={this.grenIcon}>
          <Popup>
            <span style={{ display: "block" }}>{item.name}</span>
          </Popup>
        </Marker>
      );
    });
  }

<Map
   className="map"
   center={center}
>
   <GeoJSON
      data={geo}
      style={this.hospital_style}
   />
   {this.markerHospitalRender()}
</Map>

react-leafletGeoJSON 包装器上使用 onEachFeature 属性来传递类似于 native 传单的箭头函数 onEachFeature function 以便能够生成单击每个地区时弹出。

<GeoJSON
      data={geo}
      style={this.hospital_style}
      onEachFeature={onEachFeature}
   />

const onEachFeature = (feature, layer) => {
  const popupContent = `District Code: ${feature.properties.electoralDistrictCode} <br> District: ${feature.properties.electoralDistrict}`;
  if (feature.properties && feature.properties.popupContent) {
    popupContent += feature.properties.popupContent;
  }
  layer.bindPopup(popupContent);
};