Kazu46Machi / earth-api-samples

Automatically exported from code.google.com/p/earth-api-samples
0 stars 0 forks source link

Add getFeatureById() or similar. #60

Closed GoogleCodeExporter closed 8 years ago

GoogleCodeExporter commented 8 years ago
Currently the only way to find a feature by its id is to recursively search
through the entire feature tree in javascript.

eg:

function getFeatureById(id, recursive, feature) {
        var i;
        var list;

        if (typeof recursive == 'undefined') {
                recursive = false;
        }
        if (typeof feature == 'undefined' ) {
                feature = ge;
        } else if (feature.getId() == id) {
                return feature;
        }
        if ((feature.getType() == 'GEPlugin' || feature.getType() ==
'KmlFolder') && feature.getFeatures().hasChildNodes()) {
                list = feature.getFeatures().getChildNodes();
                for (i = 0; i < list.getLength(); i++) {
                        if (recursive) {
                                return getFeatureById(id, recursive,
list.item(i) );
                        } else if (list.item(i).getId() == id) {
                                return list.item(i);
                        }
                }
        }
        return null;

} 

It would be handy if there was an API function to do the same thing (but
presumably faster).

Original issue reported on code.google.com by cds...@gmail.com on 19 Aug 2008 at 11:16

GoogleCodeExporter commented 8 years ago

Original comment by api.roman.public@gmail.com on 31 Oct 2008 at 12:11

GoogleCodeExporter commented 8 years ago

Original comment by api.roman.public@gmail.com on 9 Apr 2009 at 11:09

GoogleCodeExporter commented 8 years ago

Original comment by api.roman.public@gmail.com on 9 Aug 2009 at 12:55

GoogleCodeExporter commented 8 years ago
FYI: There is a similar function in the extension library:
http://code.google.com/p/earth-api-utility-library/wiki/GEarthExtensionsDomRefer
ence#getObjectById(id,_options)

But be aware, the implementation does not traverse child nodes of all types of 
features. For example child nodes of NetworkLink is not traversed.

Jarl

Original comment by j...@gavia.dk on 12 Jun 2010 at 7:31

GoogleCodeExporter commented 8 years ago
Fixed in 5.2.1.1329

Original comment by jli...@google.com on 16 Jun 2010 at 3:33