13 Replies Latest reply: Oct 19, 2011 1:50 PM by Brian Munz RSS

    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;">

       

       

       

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

       

      Thx

        • Qva.BodyOnLoadFunctionNames.push

          I find this function

           

          Qva.BodyOnLoadFunctionNames.push('init');

           

          But it doesn´t work!

            • Qva.BodyOnLoadFunctionNames.push
              Brian Munz

              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?

                • Qva.BodyOnLoadFunctionNames.push

                  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.

                    • Qva.BodyOnLoadFunctionNames.push
                      Brian Munz

                      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.

                        • Qva.BodyOnLoadFunctionNames.push

                          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-QZOl8b2Ik1zUoqqmRQ6gKby6E2c3dL_ES9A1p73d8BT3Q");   

                           

                              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.

                            • Qva.BodyOnLoadFunctionNames.push
                              Brian Munz

                              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-QZOl8b2Ik1zUoqqmRQ6gKby6E2c3dL_ES9A1p73d8BT3Q", function() {

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

                                                  var ge;

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

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

                                                  document.onload = init(this.Element);

                                        },true);

                              });

                                • Qva.BodyOnLoadFunctionNames.push

                                  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.

                                    • Qva.BodyOnLoadFunctionNames.push

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

                                        • Qva.BodyOnLoadFunctionNames.push
                                          Brian Munz

                                          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.

                                            • Qva.BodyOnLoadFunctionNames.push

                                              When i put it back, i have the same error: google is not defined.

                                               

                                               

                                               

                                               

                                               

                                               

                                              function init()

                                              {

                                               

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

                                              }

                                               

                                              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();

                                                  }

                                                 

                                              function failureCallback(errorCode) {

                                                  }

                                               

                                               

                                               

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

                                               

                                              var QVGlobal;

                                                                  var ge;

                                               

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

                                               

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

                                               

                                                         

                                                                  document.onload = init();

                                               

                                               

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

                                                        //Write HTML-Page

                                               

                                                          var html="";

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

                                                      this.Element.innerHTML = html;

                                               

                                               

                                                        },true);