Reactjs 如何使用Openlayer';覆盖层';内部反应?

Reactjs 如何使用Openlayer';覆盖层';内部反应?,reactjs,openlayers,Reactjs,Openlayers,我用react创建了一张简单的卡片,我想显示一个覆盖图。 但是叠加没有显示,我在控制台中没有错误 我在构造函数中声明映射 // Declaration of the map this.olmap = new Map({ target: null, layers: [this.osm], view: new View({ center: this.state.center, zoom: this.state.zoom

我用react创建了一张简单的卡片,我想显示一个覆盖图。 但是叠加没有显示,我在控制台中没有错误

我在构造函数中声明映射

 // Declaration of the map
    this.olmap = new Map({
      target: null,
      layers: [this.osm],
      view: new View({
        center: this.state.center,
        zoom: this.state.zoom
      })

    })

    // Déclaration of the Marker
    this.marker = new Overlay({
      position: fromLonLat([1.3529599, 44.0221252]),
      positioning: "center-center",
      element: document.getElementById("marker"),
      stopEvent: false
    });
    //console.log(this.marker);

    // Adding to the Map Object
    this.olmap.addOverlay(this.marker);

这是渲染图

render() {

    return (
      <>
        <div id="map15" style={{ width: "100%", height: "360px" }} />
        <div style={{ display: "none" }}>
          {/* Marker */}
          <div 
          id="marker" 
          title="Marker"
          style={{
            width: "20px",
            height: "20px",
            border: "1px solid #088",
            borderRadius: "10px",
            backgroundColor: "#0FF",
            opacity: "0.5"
          }}
          />
        </div>
      </>
    );
  }
}
render(){
返回(
{/*标记*/}
);
}
}

我终于找到了解决方案,我在
componentDidMount

componentDidMount() {
    this.olmap.setTarget("map15");

    // Déclaration of the Marker
    this.marker = new Overlay({
      position: fromLonLat([-43.3307, -22.9201]),
      positioning: "center-center",
      element: document.getElementById("marker"),
      stopEvent: false
    });
    //console.log(this.marker);

    // Adding to the Map Object
    this.olmap.addOverlay(this.marker);
    console.log(this.olmap);
  }

你确定你的地图上可以看到Lat Long吗?我们发现
div class=“ol overlay container”
位于
position:fromlont([1.3529599,44.0221252])
指示的位置,但我不明白的是,这个
div
应该包含一个
div id=“marker”title=“marker”
什么都没有。