Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to include typescript openlayers 3 external module?

I want to try setting up a simple map in openlayers using typescript:

https://github.com/borisyankov/DefinitelyTyped/blob/master/openlayers/openlayers.d.ts

I take that file, put it into

/typings/openlayers/openlayers.d.ts

I have an app.ts file at the top in my root directory that I put:

import { Map } from "olx";

In my tsconfig.json, I've included the path to the openlayers.d.ts file. But I am gettting olx is not defined when I use the tsc command from npm's typescript package.

All I am going for is drawing a simple openlayers3 map, hope to not deviate from javascript too much if possible.

like image 602
Rolando Avatar asked Apr 25 '26 18:04

Rolando


1 Answers

First install openlayers:

npm install openlayers

Then install types openlayers to your dev env:

npm install --save-dev @types/openlayers

To import I tried:

import * as ol from 'openlayers';

Then you can invoke anything in openlayers like this:

new ol.Map();
like image 100
Willie Z Avatar answered Apr 28 '26 11:04

Willie Z



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!