Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to integrate openlayers 3 transform extension

I am working on an openlayers 3 project, developed using typescript, hence:

let ol = require("openlayers");

I would like to use the transform extension plugin, which is not published on NPM (http://viglino.github.io/ol3-ext/interaction/transforminteraction.js)

I tried the following:

let ol = require("openlayers");
require("<path>/ol/transforminteraction");

however I get the following errors:

ERROR TypeError: ol.interaction.Transform is not a constructor

and

Uncaught ReferenceError: ol is not defined

How am I able include/integrate this resource correctly?

like image 985
vicgoyso Avatar asked Jul 02 '17 17:07

vicgoyso


1 Answers

let ol = require("openlayers");

This means ol is not in the global scope, therefore it isn't available to transforminteraction to extend.

Looking at the plugin code, you should be able to wrap it in a

module.exports = function(ol) {
   ...
}

This puts ol into the function scope.

Then you can use it by passing in ol as an argument to extend it. e.g.

let ol = require("openlayers");
require("<path>/ol/transforminteraction")(ol);
like image 195
BSycha Avatar answered Sep 20 '22 00:09

BSycha