1

I would like to use the latest version of OpenLayers (5.3) in small project. The requirements are:

  • no Node.js - I will be running thing on the site hosted on IIS, simple HTML files
  • scripts need to be written in TypeScript
  • List item
  • ES5

I've read a lot of different discussions and I'm a bit confused. It this even possible? The new OpenLayers has ol npm package, there are (at least two) types definitions for OpenLayers but I can't get it to work in the browser.

First, it complaining about import statements which are not recognized. The other issues are that even if I will include full ol.js I can't get typings to work in TypeScript.

Does anyone have some successful examples?

Fo example bellow the ol namespace is not recognized:

/// <reference path="ol.js"/>
/// <reference path="../Typings/ol/Map.d.ts"/>

// no imports as they are not working without Node.js

class MainMap {

    createMap() {
        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([37.41, 8.82]),
                zoom: 4
            })
        });
    }    
}

let map = new MainMap();
map.createMap();

Anyone is successful with using OpenLayers typings in TypeScript without using Node.js?

  • Here is a compiler with docs github.com/niutech/typescript-compile , I don’t see any reason to use ts like that though. – dmh126 Jul 3 at 7:34
  • 1
    That was not the goal of my question. I know how to compile TypeScript - that is quite obvious that it needs to be compiled. Above code is just an example, my TS scripts will be much bigger so that I see a lot of reasons of using TypeScript (e.g.: because I can use classes). The main problem is that the TS typings are generaed for ol npm package (for for big ol.js) and they are not working in my TS files. – Dawid Rutkowski Jul 3 at 8:27

Your Answer

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

Browse other questions tagged or ask your own question.