2

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
  • 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();
Dawid Rutkowski
  • 2,658
  • 1
  • 29
  • 36
  • I think you are confusing yourself with respect to nodejs. It is a very useful tool for development. It will do the module loading for you, package management and much more. You don't need to have nodejs installed on IIS at all. Just build your sources and copy the result to the server. Then just install [openlayers](https://www.npmjs.com/package/ol) and [types](https://www.npmjs.com/package/@types/ol) using npm. – transporter_room_3 Jul 09 '19 at 09:48
  • 1
    I know ALL of that... Like I wrote in the first bullet point - no Node.js at any stage of development. – Dawid Rutkowski Jul 10 '19 at 07:03
  • @DawidRutkowski great question! thx! i have exactly the same requirements. where did get the definition files from (i don't have a typings folder or any *.d.ts files in the current npm package)? – PrinceCharles Jul 11 '19 at 17:46
  • I will probably give up and do not use TypeScript as I don't have a solution for it. Will go with standard ES5 and reference `ol.js`. – Dawid Rutkowski Jul 12 '19 at 07:10
  • @DawidRutkowski too bad! this is not acceptable for me (i.e. the project) since i have a lot of framework methods in typescript that i have to reference/interact with. after a `npm install` i do not even have a `ol.js`. no clue how to build that in a asp.net mvc core environment. poor documentation :-/ – PrinceCharles Jul 12 '19 at 07:16
  • `npm install` will not give you `ol.js`. Grab it from here: https://github.com/openlayers/openlayers/releases/download/v5.3.0/v5.3.0-dist.zip – Dawid Rutkowski Jul 12 '19 at 13:10

0 Answers0