uygar donduran
uygar donduran

Reputation: 1207

Accessing a placemark with google earth api through Region-Based Network Linked kml files

I have a huge set of placemarks loaded using regionated kml files. (around 1000 kml files generated). For example , I have a button, when clicked camera flies to the location of the placemark I want to access. So I think the kml file that includes this placemark is loaded after this process. Let's say this is 5.kml and I tried to get the placemark object using getElementByUrl method. But this didn't work. I can also use ge.getElementsByType("KmlPlacemark") method but I need to have a loop to get the placemark object I need. This works but I couldn't find a way to make it work fast. Below is my code

google.earth.addEventListener(ge.getView(), 'viewchangeend', function() {                 
      // after button click and camera centered on the placemark with id 1767
      var p = ge.getElementByUrl('http://localhost/Test/5.kml#1767');
      alert(p.getId());  // this does not work because p is null
      var placemarks = ge.getElementsByType('KmlPlacemark'); 
      for (var i = 0; i < placemarks.getLength(); ++i) {
         var placemark = placemarks.item(i);
         if(placemark.getId() == 1767)
         {              
            alert(placemark.getId()); // this works      
            return;
         }
     }      
});

 function button_click()
{
    var camera = ge.getView().copyAsCamera(ge.ALTITUDE_RELATIVE_TO_GROUND);
    camera.setLatitude(30);
    camera.setLongitude(50);
    camera.setAltitude(2000);
    ge.getView().setAbstractView(camera);   
  }

I wish I found a way to access the object which is imported from KML(when region beomes active). Waiting for your answers. Thanks.

Upvotes: 1

Views: 1526

Answers (1)

Mano Marks
Mano Marks

Reputation: 8819

NetworkLink's don't load files into the DOM, which is why getElementByUrl doesn't find the Placemark you're looking for. You would need to fetch the KML. This article should be helpful in explaining the different ways to load KML in the Google Earth API.

Upvotes: 1

Related Questions