Google Earth API

Object Containers

  1. Introduction
  2. Modifying containers

Introduction

There are a number of container objects in the Google Earth API. These are used to hold arrays of related objects:

  • A GELinearRingContainer holds an array of linear ring objects. For example, a polygon's inner boundaries are stored in a linear ring container.
  • GEFeatureContainers contain features, as with folders in KML.
  • GEGeometryContainers hold any number of geometries in a MultiGeometry object.

Containers are abstract classes and cannot be created directly from the API.

Modifying containers

Containers have methods that allow you to enumerate, add, remove, and manipulate individual items in the collection. Some common methods are described below; for a full list, refer to the API Reference for the applicable container type.

Adding a child

To add a child to a container, use appendChild(). For example, to add an inner boundary to a polygon:

var inner = ge.createLinearRing('');
inner.getCoordinates().pushLatLngAlt(48.73, -121.83, 700);
inner.getCoordinates().pushLatLngAlt(48.73, -121.87, 700);
inner.getCoordinates().pushLatLngAlt(48.77, -121.87, 700);
inner.getCoordinates().pushLatLngAlt(48.77, -121.83, 700);

polygon.getInnerBoundaries().appendChild(inner);

You can also insert a new child into a specific position in the array, using insertBefore():

polygon.getInnerBoundaries().insertBefore(inner, 2);

Finding the number of children

To discover the length of an array, use getChildNodes().getLength():

ge.getFeatures().getChildNodes().getLength();

Retrieving a specific child

To return a specific child of a container, use one of:

  • getFirstChild()
  • getLastChild()
  • getChildNodes().item()

In addition, getNextSibling() and getPreviousSibling allow for enumeration of DOM siblings.

For example, the following two calls return the same child:

ge.getFeatures().getFirstChild();
ge.getFeatures().getChildNodes().item(0);

Likewise:

polygon.getLastChild();
polygon.getChildNodes().item(polygon.getChildNodes().getLength() - 1);

Removing all features from the plugin

To remove all features from the plugin:

var features = ge.getFeatures();
while (features.getFirstChild())
   features.removeChild(features.getFirstChild());

Authentication required

You need to be signed in with Google+ to do that.

Signing you in...

Google Developers needs your permission to do that.