Refering to external library in Widget + Widget checker fails

0
Hi everybody, We are trying to incorporate the drawing library in a widget. We do this in the following way (not debating if this is the best way btw):   define([... "dojo/text!GoogleMapsDrawings/widget/template/GoogleMapsDrawings.html", "https://maps.googleapis.com/maps/api/js?key=<<mykey>>&libraries=drawing", "GoogleMapsDrawings/lib/jsapi" ], function (declare, _WidgetBase, _TemplatedMixin, domStyle, domConstruct, dojoArray, lang, widgetTemplate, draw, googleDraw) { "use strict"; ...   When we do the widgetcheck, we keep getting errors on the https part (error log provides us with an ILLEGAL token. We have no idea what it could be. Checked all different kind of editors etc. So,  Could it be that it is not allowed to directly include a library like this when we deploy to the cloud? Localhost: everything works as designed this way. How should we include a library as stated above?   Hope you can help! Final bump to actual deploying it :-)   Cheers! Laurens
asked
3 answers
1

I would recommend checking out some other widgets in the app store to see how they load external libraries:

For example d3TreeView widgets packages a copy of the external javascript library together with the widget under a lib folder and then references it with

"D3TreeView/lib/d3-v3-min"

https://github.com/ivosturm/D3TreeView/blob/master/src/D3TreeView/widget/D3TreeView.js
I have personally loaded external libs in the postCreate method. If you use this approach you need to set the loaded flag so that mendix knows when your widget is ready see https://apidocs.mendix.com/7/client/tutorial-widget-lifecycle.html

Hope this helps

answered
1

Hello both, 

A bit of a late reply as I've been tackling this issue the last few days myself - I found that you can include HTTP/HTTPS libraries through the Dojo AMD loader, but you cannot use them in the Define statement as they get marked as invalid for the cloud. 

What you can do is is add them in the require statement, that way you cannot directly reference the js package in your declare statement but you can use any keywords and libraries defined within the js. 

i.e. require(["GoogleMapsDrawings/widget/widget/GoogleMapsDrawings/widget","https://maps.googleapis.com/maps/api/js?key=<<mykey>>&libraries=drawing""]);

Hope this is of some use!

answered
0

Discovered something interesting (thanks to the reply by Andrej). If i refer directly to the library using the http statement in define, it works locally but not in the cloud. When I download the library and use the reference, it works locally AND in the cloud. Now I'm not sure if this remains functional but lets see how it goes.

Kind regards!

Laurens

answered