Network Links in a Region in the Google Earth API

I have many large KML datasets that are served using a network link hierarchy in a region; as described in the KML link :

Using areas in conjunction with NetworkLinks, you can create a hierarchy of pointers, each of which points to a specific subregion. <viewRefreshMode>as shown in the following KML file, has the onRegion parameter, which sets the region to load data only if the region is active. If you provide nested regions with several levels of detail, more data is only loaded when the user's point of view launches the next load.

This works well when uploading to Google Earth.

Now I want to download them to the application using the Google Earth plugin . And I need to access the downloaded content using the Google Earth API; (i.e. attach click events, change styles) to integrate content into the application.

The problem is that I did not find the on-load event links for network links. In my opinion, this will work:

  • Download the top-level network link through the API by adding a callback function that will be called when the network link is loaded.
  • In the callback function, parse the KML returned by the network link. For intermediate levels in the regionalization hierarchy, this KML will contain only network links to the next regionalization level. Load them into the plugin via the API, again specifying the same callback function that will be called when they are loaded (i.e. when their area becomes visible).
  • In the end, the returned KML will contain the actual "content". At this point, we load the actual content (i.e. tags) into the plug-in after making any desired changes (for example, adding listener events, tuning styles, etc.).

, javascript . : , . , .

//create network link
var networkLink = ge.createNetworkLink("");
networkLink.setName("Regionated hierarchy root");

// create a Link object
//the network-links contained in the kml that will be returned in this file
//are region-based; they will only be loaded when the user zooms into the relevant
//region. 
var link = ge.createLink("");
link.setHref("http://foo.com/regionatedRoot.kml");

// attach the Link to the NetworkLink
networkLink.setLink(link);

//specify the callback function to be invoked when the network link is loaded
//this is is the part that doesn't actually exist; pure fiction...
networkLink.onLoad = networkLinkLoaded;

// add the NetworkLink feature to Earth
ge.getFeatures().appendChild(networkLink);

// function which will be invoked when a network-link is loaded
// i.e. when its region becomes active
function networkLinkLoaded(kml) {

   //parse the kml returned for child network links,
   //this will create the network link KmlObject, with a 
   //region specified on it.
   for (childNetworkLink in parseNetworkLinks(kml)) {
      //and append them, again hooking up the call-back
      childNetworkLink.onLoad = networkLinkLoaded;
      ge.getFeatures().appendChild(childNetworkLink);
   }

   //if the user has zoomed in far enough, then the kml returned will
   //contain the actual content (i.e. placemarks).
   //parse the kml returned for content (in this case placemarks)
   for (placemark in parsePlacemarks(kml)) {
      //here we would attach event-listeners to the placemark
      ge.getFeatures().appendChild(placemark);
   }
}

?
? , KML, , API.

, : , - Google , . (, 5 ). , , - .

?

+5
2

, . , , . , , , click .

, mousedown , , . , - , , . - .

.

window.google.earth.addEventListener(ge.getWindow(), 'mousedown', onWindowMouseDown);

var onWindowMouseDown = function(event) {
  if (event.getTarget().getType() == 'KmlPlacemark') {
    // get the placemark that was clicked
    var placemark = event.getTarget();

    // do something with it, or one of its relative objects...
    var document = placemark.getOwnerDocument();
    var parent = placemark.getParentNode();

    // etc...
  }
}
+1

, , , kmltree api, :

  • kml- kml
  • "kmlloaded"

http://code.google.com/p/kmltree/

function initCB(instance){
    ge = instance;
    ge.getWindow().setVisibility(true);

    var gex = gex = new GEarthExtensions(ge);

    var tree = kmltree({
        url: 'http://foo.com/regionatedRoot.kml',
        gex: gex, 
        mapElement: $('#map3d'), 
        element: $('#tree'),
    });

    $(tree).bind('kmlLoaded', function(event, kmlObject){ //do something here });

    tree.load();
}

, js api, .

, kml...

, fetchKml(), URL- ?

google.earth.fetchKml(ge, 'http://foo.com/regionatedRoot.kml', function(kmlObject){
     //do logic here
});
0

All Articles