How to call function from other js


I'm trying to call in cesium one function from other js.

the file is called airport.js and it is place next Cesium.js.

the fonction I want to call is height() and it's return value of the airport altitude nearest the airplane model.

I add in index.html:

<script type="text/javascript" src="./Build/Cesium/airport.js"></script>

I add also this in the bucket-requirejs.html in case:

<script type="text/javascript" src="../../../Build/Cesium/airport.js"></script>

How I have to call this function to have label upper the model with this value?...

thank you for your help

There are lots of different ways to include a JavaScript file:

One of the easiest is probably to just include it like you have. If your paths are correct it should work. Does that not work? What does airport.js look like?

Hello Omar,

below, my airport.js

var resp;
var elevation;
function nearest(Long,Lat) {
    var res;
    var url = ';’+Long+’,’+Lat;
    var doc= new XMLHttpRequest();
    doc.onreadystatechange = function(){
        if(doc.readyState == XMLHttpRequest.DONE){
            var res1=res.split("<")

            var res2=res1[13]
            var res3=res1[21]
            var res4=res2.split(">")
            var oaci=res4[1]

            var res6=res3.split(">")

            //var res6=res5.split(">")
            //var res7=res6[1]
            //console.log(oaci+" "+elevation);

    };'GET', url, true);


function height()
    return elevation

the function nearest is called by qml file with Qt 5.10.

making console.log(height()) in Qt show that the function is working fine but I receive TypeError: height is not a function when I try to call height() in cesium

Are you testing this in Sandcastle? I would just try working in the HelloWorld.html example (under Apps/) which has a simpler architecture. If you include your script at the top there it should be accessible just fine. If that doesn’t work post your full HTML/JavaScript code for that file here.