Skip to main content
Question

How to execute JavaScript Code with JavaScriptCaller?


gtitz
Contributor
Forum|alt.badge.img+3
  • Contributor

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 (exportsrequiremodule, __filename, __dirname) { window.google = window.google || {};
                                                              ^

ReferenceErrorwindow 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!

2 replies

redgeographics
Celebrity
Forum|alt.badge.img+49

I don't have a solution for you, but it looks like it'd be useful for the GeometryReplacer and GeometryExtractor to support this Encoded Polyline, so if you want you can create an idea for it.


gtitz
Contributor
Forum|alt.badge.img+3
  • Author
  • Contributor
  • March 5, 2018
redgeographics wrote:

I don't have a solution for you, but it looks like it'd be useful for the GeometryReplacer and GeometryExtractor to support this Encoded Polyline, so if you want you can create an idea for it.

Okay, thanks for your advice. I created a new idea: https://knowledge.safe.com/idea/65263/extend-geometryextractor-and-geometryreplacer-with.html

 

That's a convenient place for that functionality.

 


Reply


Cookie policy

We use cookies to enhance and personalize your experience. If you accept you agree to our full cookie policy. Learn more about our cookies.

 
Cookie settings