React 应用程序不使用 openlayers 显示地图

React app not displaying map using openlayers

我无法在 React 应用程序中集成 openlayers 地图。我按照他们的教程进行操作,但不确定哪里出错了。我也尝试了一些 youtube 教程。

各位专家能帮忙吗?

https://openlayers.org/en/latest/examples/simple.html

import 'ol/ol.css';
import Map from 'ol/Map';
import OSM from 'ol/source/OSM';
import TileLayer from 'ol/layer/Tile';
import View from 'ol/View';

var map = new Map({
  layers: [
    new TileLayer({
      source: new OSM(),
    }) ],
  target: 'map',
  view: new View({
    center: [0, 0],
    zoom: 2,
  }),
});

export default map;

我是这样导入的:

 import "./Base.css"

function Base() {
    return (
      <div className = "map" id="map"/>
    );
  }
  
export default Base;  

因为 myMap 没有 return 并且使用 <myMap /> 的 jsx 组件不算作使用,所以你会收到该消息。无论如何,该消息并不意味着什么,如果您的实施有效,请不要打扰。