|React+Openlayuers 模板(学习中,持续更新)( 三 )


        //将overlay添加到地图
        map.current.addOverlay(overlay)
        //设置地图左键点击事件
        map.current.on('click' (event: any) => {
          if (overlayInfo.innerHTML !== ' ') {
            // 清空
            reactDom.unmountComponentAtNode(overlayInfo);
         
          // 获取点击的feature
          const feature = map.current.forEachFeatureAtPixel(event.pixel function (feature: any vectorLayer: any) {
            return feature;
          )
          if (feature && feature.id_ != undefined) {
            const infoData = https://mparticle.uc.cn/api/feature.getGeometry().flatCoordinates;
            const infoDom = (<div>
              经度: {infoData[0 维度:{infoData[1

            </div>
            )
            //将overlayInfo插入infoDom
            reactDom.render(infoDom overlayInfo);
            // 设置overlay位置
            overlay.setPosition(infoData)
         
        )
     
      return (
        <span>
          <div id=\"map\" className={styles.map ref={mapDom />
        </span>
      )
   
    export default Index



【|React+Openlayuers 模板(学习中,持续更新)】