0

I'm trying out a few OL demo apps, and finding I can't combine two of the demo scripts provided in the documentation into one script, because there appear to be conflicts between the imports.

This is very easy to reproduce, import OL into a npm workspace, and then the following code:

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

The last two libraries are the ones which conflict with each other. However remove either of the last two (doesn't matter which one) and it works fine.

In OL, another way of calling the import for the last two lines is to combine them as follows:

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

Which is actually shown here in the demo script:

https://openlayers.org/en/latest/examples/arcgis-tiled.html

Both methods result in an error, but as I say, removing either of them and leaving just one, and it runs fine.

The error I get is:

Uncaught TypeError: Object prototype may only be an Object or null: undefined
    at Function.create (<anonymous>)
    at inherits (util.js:28)
    at Object.parcelRequire.233.../util.js (epsg3857.js:63)
    at newRequire (main.3e0ff667.js:48)
    at localRequire (main.3e0ff667.js:54)
    at Object.parcelRequire.93../sphere.js (proj.js:59)
    at newRequire (main.3e0ff667.js:48)
    at localRequire (main.3e0ff667.js:54)
    at Object.parcelRequire.168.../util.js (Geometry.js:9)
    at newRequire (main.3e0ff667.js:48)

I am running my app as recommended here exactly:

https://openlayers.org/en/latest/doc/tutorials/bundle.html

Any help to explain why I can't use these two components of the OL library together would be really appreciated.

Single Entity
  • 2,925
  • 3
  • 37
  • 66
  • Why is this tagged openlayers-3? It doesn't seem to have anything to do with that specific version of openlayers. – geocodezip Jul 05 '18 at 18:57

1 Answers1

0

I've clearly not and idea why you encounter this issue (error message too terse)

You may want to look at this online demo. Download the code using the following screenshot instruction

Download sandbox

then uncompress the zip in a directory. In this directory, open a terminal, do npm install and npm start to get a local working sample. You can then compare with your code to see where the issue could come from.

Thomas Gratier
  • 2,311
  • 1
  • 14
  • 15