Skip to main content
Announcements
Join us at Qlik Connect for 3 magical days of learning, networking,and inspiration! REGISTER TODAY and save!
cancel
Showing results for 
Search instead for 
Did you mean: 
Not applicable

Help with BodyOnLoad

Hello at all,

i want to make this in my QlikView Extension:

<script type="text/javascript">

    var ge;

    google.load("earth", "1");

    google.load("maps", "2");

    function init() {

      google.earth.createInstance('map3d', initCallback, failureCallback);

      addSampleUIHtml(

        '<input id="location" type="text" value="Hermannstr.106-107,12051 Berlin"/>'

      );

      addSampleButton('Fly Here!', buttonClick)

    }

    function initCallback(instance) {

      ge = instance;

      ge.getWindow().setVisibility(true);

      // add a navigation control

      ge.getNavigationControl().setVisibility(ge.VISIBILITY_AUTO);

      // add some layers

      ge.getLayerRoot().enableLayerById(ge.LAYER_BORDERS, true);

      ge.getLayerRoot().enableLayerById(ge.LAYER_ROADS, true);

      document.getElementById('installed-plugin-version').innerHTML =

        ge.getPluginVersion().toString();

    var link = ge.createLink('');

    var href = 'http://www.rsp-gmbh.de/uploads/berlin2.kmz';

    link.setHref(href);

    var networkLink = ge.createNetworkLink('');

   networkLink.set(link, true, true); // Sets the link, refreshVisibility, and flyToView

    ge.getFeatures().appendChild(networkLink);

    }

    function failureCallback(errorCode) {

    }

<body onload="init()" style="font-family: arial, sans-serif; font-size: 13px; border: 0;">

<script type="text/javascript">

    var ge;

    google.load("earth", "1");

    google.load("maps", "2");

    function init() {

      google.earth.createInstance('map3d', initCallback, failureCallback);

      addSampleUIHtml(

        '<input id="location" type="text" value="Hermannstr.106-107,12051 Berlin"/>'

      );

      addSampleButton('Fly Here!', buttonClick)

    }

    function initCallback(instance) {

      ge = instance;

      ge.getWindow().setVisibility(true);

      // add a navigation control

      ge.getNavigationControl().setVisibility(ge.VISIBILITY_AUTO);

      // add some layers

      ge.getLayerRoot().enableLayerById(ge.LAYER_BORDERS, true);

      ge.getLayerRoot().enableLayerById(ge.LAYER_ROADS, true);

      document.getElementById('installed-plugin-version').innerHTML =

        ge.getPluginVersion().toString();

    var link = ge.createLink('');

    var href = 'http://www.rsp-gmbh.de/uploads/berlin2.kmz';

    link.setHref(href);

    var networkLink = ge.createNetworkLink('');

   networkLink.set(link, true, true); // Sets the link, refreshVisibility, and flyToView

    ge.getFeatures().appendChild(networkLink);

    }

    function failureCallback(errorCode) {

    }

<body onload="init()" style="font-family: arial, sans-serif; font-size: 13px; border: 0;">

How does it work under QlikView with the Body on Load?

Thx

13 Replies
Not applicable
Author

I find this function

Qva.BodyOnLoadFunctionNames.push('init');

But it doesn´t work!

Brian_Munz
Employee
Employee

What happens when you simply have init(); written in the extension?  That should trigger the function.

What does your extension's Script.js look like so far?

Not applicable
Author

When i make it in the extension

Qva.BodyOnLoadFunctionNames.push('init');

Qva.AddExtension('GoogleEarth', function() {

 

     //Write HTML-Page

        var html="";

        html+="<body onload='Qva.Start()'>";

        html+="<div id='map3d' style='width: 600px; height: 400px;'></div>"; 

       this.Element.innerHTML = html;

      

        function init()

        {

        alert('Test');

        }

      

      

},true);

There is no alert.

Brian_Munz
Employee
Employee

I don't know that you need to use that Qva.BodyOnLoadFunctionNames.push('init'); at all.  When I need to do soemthing similar I just call the function outright at the bottom of the extension.  So in your extension it would just be:

Qva.AddExtension('GoogleEarth', function() {

     //Write HTML-Page

        var html="";

        html+="<body onload='Qva.Start()'>";

        html+="<div id='map3d' style='width: 600px; height: 400px;'></div>";

       this.Element.innerHTML = html;

     

        function init()

        {

        alert('Test');

        }

     

init();

     

},true);

Or perhaps you could use document.onload = init(); in the extension somewhere.

Not applicable
Author

Hello,

document.onload = init();

works fine. But i think my extension doesn´t load my JavaScript for Google Earth, because i get an error message that google is not defined.

var QVGlobal;

Qva.LoadScript ("http://www.google.com/jsapi?key=ABQIAAAAjb153tfjyia9Ika9RRA5XRQvj1FOGbPa-QZOl8b2Ik1zUoqqmRQ6gKby6E2c...");   

    var ge;

    google.load("earth", "1");

    google.load("maps", "2");

   

function init()

{

  google.earth.createInstance('map3d', initCallback, failureCallback);

}

Qva.AddExtension('GoogleEarth', function() {

 

      document.onload = init();

     

     //Write HTML-Page

        var html="";

        html+="<div id='map3d' style='width: 600px; height: 400px;'></div>"; 

       this.Element.innerHTML = html;

},true);

The same under HTML/JavaScript Page works without Problems. There is no such a message with the google Variable.

Brian_Munz
Employee
Employee

It's because you're running the init function on document load, but you're trying to write the html (which doesn't yet exist) to the extension before the init has run.  To fix this, try doing putting the html code into the init function.

Also, it's always safer to add the extension after the script is loaded.  So, actually, try this code instead:

var QVGlobal;

function init(xDiv)

{

  google.earth.createInstance('map3d', initCallback, failureCallback);

          //Write HTML-Page

          var html="";

          html+="<div id='map3d' style='width: 600px; height: 400px;'></div>";

          xDiv.innerHTML = html;

}

Qva.LoadScript("http://www.google.com/jsapi?key=ABQIAAAAjb153tfjyia9Ika9RRA5XRQvj1FOGbPa-QZOl8b2Ik1zUoqqmRQ6gKby6E2c...", function() {

          Qva.AddExtension('GoogleEarth', function() {

                    var ge;

                    google.load("earth", "1");

                    google.load("maps", "2");

                    document.onload = init(this.Element);

          },true);

});

Not applicable
Author

Thank you for your code. QlikView show me a message: "An error occured in the postpaint-function in the extension object undefinied". When i click the message away, then nothing happens.

Not applicable
Author

I think the error is the following, when you set a second parameter into the Google Earth Key, they call the callback function.

Brian_Munz
Employee
Employee

Yes, I see that you have two callback functions that don't exist.  One for a successful write and one for a failure.

Also, I might have been incorrect as far as the HTML code needing to be written in the init function.  It looks like all it does is create the div that google write the map into.  So you might want to put it back where it was.