How to integrate openlayers 3 transform extension
Asked Answered
K

3

6

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?

Kastroprauxel answered 2/7, 2017 at 17:35 Comment(0)
P
3
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);
Prudhoe answered 10/7, 2017 at 12:14 Comment(0)
A
0

You can include "transforminteraction.js" code in a separate file that the browser will download alongside the HTML document. Cut JS code from html file,and paste it into your "transforminteraction.js" file,don't forget about window.onload = function() { ...your code js + transforminteraction.js }. Also check:

Clone repository of OL3-ext: https://github.com/Viglino/ol3-ext

or:

https://github.com/Rep1ay/openLayer.git

Automotive answered 27/11, 2017 at 12:19 Comment(0)
D
0

I solved this problem adding in my load.js file:

if (debugMode) { 
    addScriptFile('//cdnjs.cloudflare.com/ajax/libs/ol3/' + olVersion + '/ol-debug.js');
    addScriptFile('//viglino.github.io/ol-ext/dist/ol-ext.js'); 
} else { 
    addScriptFile('//cdnjs.cloudflare.com/ajax/libs/ol3/' + olVersion + '/ol.js');   
    addScriptFile('//viglino.github.io/ol-ext/dist/ol-ext.js'); 
}
Devoice answered 12/4, 2019 at 7:55 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.