I want to encode the polyline format, which I get from Google Maps Directions API.
The decoding works according to a specific algorithm:
https://developers.google.com/maps/documentation/utilities/polylinealgorithm
A JavaScript code for that is on this website:
https://stackoverflow.com/questions/40877840/google-maps-api-draw-a-route-using-points-of-a-polyline
How can I execute this JavaScript Code with JavaScriptCaller in FME 2017 (FME2017.1.2.0)?
I have used JavaScript Mode: Node.js (Technology Preview)
var fme = require('fme');
var fmeobjects = require('fmeobjects');
var a = require('https://maps.googleapis.com/maps/api/js?libraries=geometry');
// To be executed for each feature.
fme.on('feature', (feature) => {
fme.output(feature);
});
// To be executed after all features
// have been received.
fme.on('end', () => {
});
This error occurs:
module.js:471
throw err;
^
Error: Cannot find module 'https://maps.googleapis.com/maps/api/js?libraries=geometry'
at Function.Module._resolveFilename (module.js:469:15)
at Function.Module._load (module.js:417:25)
at Module.require (module.js:497:17)
at require (internal/module.js:20:19)
at Object.<anonymous> (C:\Users\titzg\AppData\Local\Temp\fme_nodejscaller_sourcecode_1520270256806_14296.js:3:9)
at Module._compile (module.js:570:32)
at Object.Module._extensions..js (module.js:579:10)
at Module.load (module.js:487:32)
at tryModuleLoad (module.js:446:12)
at Function.Module._load (module.js:438:3)
When I save the JavaScript file in a local directory, I get an other error somewhere later in the code:
var a = require('D:\\temp\\fme\\itg\\20180305_google_maps_directions_api\\google_maps.js');
Then this error occurs:
D:\temp\fme\itg\20180305_google_maps_directions_api\google_maps.js:1
(function (exports, require, module, __filename, __dirname) { window.google = window.google || {};
^
ReferenceError: window is not defined
at Object.<anonymous> (D:\temp\fme\itg\20180305_google_maps_directions_api\google_maps.js:1:63)
at Module._compile (module.js:570:32)
at Object.Module._extensions..js (module.js:579:10)
at Module.load (module.js:487:32)
at tryModuleLoad (module.js:446:12)
at Function.Module._load (module.js:438:3)
at Module.require (module.js:497:17)
at require (internal/module.js:20:19)
at Object.<anonymous> (C:\Users\titzg\AppData\Local\Temp\fme_nodejscaller_sourcecode_1520270454243_14556.js:4:9)
at Module._compile (module.js:570:32)<br>
Is JavaScript not fully supported?
Does someone of you see another possibility to encode the polyline string (maybe with the Python Caller or another Transformer)?
Thanks for your help!