How to test dependency widget with a sample widget?

Ankita Kolhe
Tera Contributor

Hello Community,

 

I have created below dependency widget:

The baseline widget makes use of a JavaScript library called OpenLayers. See https://openlayers.org/.

 

Requirements

 

1. Setup Widget Dependency

First we will setup the dependency, JS include, CSS include, UI script, and style sheet.

 

Create Widget Dependency [sp_dependency]

Name: "OpenLayers v10.7.0"

JS Includes: <create new, see below>

CSS Includes: <create new, see below>

 

Create JS Include [sp_js_include]

Display name: "ol.js"

Source: UI Script

UI script: <create new, see below>

 

Create CSS Include [sp_css_include]

Name: "ol.css"

Source: Style Sheet

Style sheet: <create new, see below>

 

Create UI Script [sys_ui_script]

API Name: "ol.js"

UI Type: All

Script: copy and paste contents from

https://cdn.jsdelivr.net/npm/ol@v10.7.0/dist/ol.js

 

Create Style Sheet [sp_css]

Name: "ol.css"

CSS: copy and paste contents from 

https://cdn.jsdelivr.net/npm/ol@v10.7.0/ol.css

Turn off SCSS compilation: true

 

2. If This Does Not Work

It may be that the minified ol.js will not work as a UI script for some reason. If that is the case, we can apply the following workaround:

 

Change JS Include

Display name: "ol.js"

Source: URL

JS file URL: 

https://cdn.jsdelivr.net/npm/ol@v10.7.0/dist/ol.js

 

Change CSS Include

Name: "ol.css"

Source: URL

CSS file URL: 

https://cdn.jsdelivr.net/npm/ol@v10.7.0/ol.css

 

 

Sample widget created for testing:

HTML:

<div>

<h3>Dependency Test</h3>

<div id="map" style="height:400px;"></div>

</div>

 

 

Client:

api.controller = function() {
 
 
    alert('t: ' + typeof ol);
    alert('ol: ' + ol);
 
    var c = this;
 
    console.log("OL object:", ol);
 
    if (typeof ol !== 'undefined') {
        console.log("OpenLayers loaded successfully");
 
        const map = new ol.Map({
            target: 'map',
            layers: [
                new ol.layer.Tile({
                    source: new ol.source.OSM()
                })
            ],
            view: new ol.View({
                center: [0, 0],
                zoom: 2
            })
        });
 
    } else {
        console.error("OpenLayers NOT loaded");
    }
 
 
};
 
 
ol is displaying as undefined. Also, I have attached dependency to sample widget.Could someone please help why is this not working?
 
Thanks

 

I have tried above methods 

0 REPLIES 0