1

I'm looking for some examples in OpenLayers to add in my project, and all those examples had something like this in their JavaScript:`

  import Map from 'ol/Map.js';
  import Overlay from 'ol/Overlay.js';
  import View from 'ol/View.js';
  import {toStringHDMS} from 'ol/coordinate.js';
  import TileLayer from 'ol/layer/Tile.js';
  import {fromLonLat, toLonLat} from 'ol/proj.js';
  import OSM from 'ol/source/OSM.js';`

Where did that come from and how can I use it?

2

Openlayers is a modular library. Map, for example, is one of the available classes and is defined in the source file ol/Map.js of the library.

By using import you can control which of the classes will be available in your application. E.g. the Map class can then be used to construct a new map:

new Map({...})

The development experience involves the use of Node's npm package manager and a bundler like Webpack or Parcel. The website has a good tutorial explaining how to set it up.

  • This is only part of the answer. It doesn't tell anything about that fact that this is inteneded for development environment (like node.js and NPM), where you can run it uncompiled and that it has to compiled to be run on the client side. – TomazicM Jan 30 at 16:38
  • 1
    I added this missing information. – ahocevar Feb 5 at 20:01

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.