Search code examples
reactjsopenlayers

React app not displaying map using openlayers


I am unable to integrate openlayers map in react app. I followed their tutorial but not sure where I went wrong. I also tried some youtube tutorials.

Can you experts help ?

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;

I am importing this way :

 import "./Base.css"

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

Solution

  • since myMap doesn't return and jsx component using <myMap /> doesn't count as a use, hense you get that message. any way that message does't mean anything and if you implementation works don't bother.