1

I'm trying to run the map, with this code:

var map = new ol.Map({
    target: 'map',
    layers: [
      new ol.layer.Tile({
        source: new ol.source.OSM()
      })
    ],
    view: new ol.View({
      center: ol.proj.fromLonLat([{{$obj->config['longitude']}}, {{$obj->config['latitude']}}]),
      zoom: 17
    })
});

var layer = new ol.layer.Vector({
    source: new ol.source.Vector({
        /*
        features: [
            new ol.Feature({
                geometry: new ol.geom.Point(ol.proj.fromLonLat( [ {{$obj->config['longitude']}}, {{$obj->config['latitude']}} ] ))
            })
        ]
        */
    })
});

When I use code library from openlayers CDN everythig works fine. Problem occurs when I try to compile my own library. In this case map doesn't show. Console showing error:

ReferenceError: ol is not defined

My library is compiled in Laravel by npm:

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

It seems to me that the problem is due to the lack of importing a file but I don't know which one.

Jaydeep
  • 1,686
  • 1
  • 16
  • 29
KaBe
  • 11
  • 1
  • 5

0 Answers0