'Error calling method on NPObject!' issue with removing a KML added through a network link

Go To StackoverFlow.com

0

I am adding a KMZ file through network link on a ADD KMZ button's onclick as follows :-

var nlFile=null;
function addKMZData(){
    nlFile=ge.createNetworkLink('exampleKMLNL1');
    nlFile.setVisibility(true);
    var link = ge.createLink(" exampleLink1 ");
    link.setHref('http://localhost:8080/KMZs/example.kmz');
    nlFile.setLink(link);
    nlFile.setFlyToView(true);
    nlFile.setName('kmz');
    ge.getGlobe().getFeatures().appendChild(nlFile);
}

The 'example.kmz' file taken here contains a linestring placemark and the installed plugin version is 6.1.0.5001.

Then, I have a REMOVE button, clicking which removes the above added KMZ 's network link from the ge-plugin's instance. The following is the REMOVE button's onclick function :

function clearKMZData(){
    ge.getFeatures().removeChild(ge.getElementById('exampleKMLNL1'));
    nlFile=null;
}

These functions work well for the first time. But any attempt to add the same KMZ file using the addKMZData() function after removing the added KMZ network link, gives the error "Error calling method on NPObject!" at line 1 of the add function. Is this way of adding & removing KMZ/KML data through network links correct? Am I missing something in the above 2 JavaScript functions?

Regards, Shiva

2012-04-04 04:16
by Shiva


0

So long as var nlFile is global

In your first function, change this

      nlFile=ge.createNetworkLink('exampleKMLNL1');

to this

      nlFile=ge.createNetworkLink('');

and change this

      function clearKMZData(){
          ge.getFeatures().removeChild(ge.getElementById('exampleKMLNL1'));
          nlFile=null;
      }

to this

      function clearKMZData(){
          ge.getFeatures().removeChild(nlFile);
      }
2012-04-04 05:12
by lifeIsGood
Thank you 'lifeIsGood' for replying. This worked. I also changed var link = ge.createLink(" exampleLink1 "); to var link = ge.createLink('') - Shiva 2012-04-04 05:55
Ads