I have created a time-aware animation involving thousands of placemarks representing population estimates at http://www.catalinagis.org/foxrecovery
I want to know how to count the sum of the total number of placemarks (in this case, points) that are visible at a given point in time. . .something like a time-based query.
The population estimate fluctuates year-to-year, so some points only last for a brief time span before they're extinguished; others persist from the beginning of the time span until the end. There are over 3,000 points, so I don't want to go back through the KML one-by-one.
I was given yearly population estimates and then simulated die-off and repopulation on a monthly time scale to make the animation seem more "natural." I created the KML some time ago and want to check myself to see if I did it correctly. . .and also display the count as the time slider is moved.
I am still not sure 'rendered on screen' is what you mean - are you sure you don't want to count placemarks that would be rendered if they were in view (on by time but on the other side of the planet for example).
If you do mean rendered then issue with counting placemarks is that the only way to do it would be to compute the bounds of the current view, then test to see if a loaded placemark falls within the bounds and is visible.
This could take quite a long time if the KML dom is large as it requires the full DOM to be walked each tick of time then a check on each element in the DOM against the bounds view. You could possibly achieve something by executing the code as a batch function with the api.
If you want to try this then I would suggest you take a look at earth-api-utility-library it has useful methods for traversing the Kml dom and computing bounds objects - you should be able to use it to help you most of the way.
EDIT: If you don't mean rendered then that is much easier, it is still essentially the same iterative process - but now you don't need to compute the view bounds or do any comparison against it.
To get the total visible placemarks at any point you simply need to walk the KML dom and check each placemarks visibility via getVisiblity()
- something like so.
var gex = new GEarthExtensions(ge);
var function countVisiblePlacemarks() {
var count = 0;
gex.dom.walk({
rootObject: ge,
visitCallback: function() {
if ('getType' in this &&
this.getType() == 'KmlPlacemark' &&
this.getVisibility())
++count;
}
});
return count;
}
Obviously how you call countVisiblePlacemarks
is up to you - on a timer, an api event, a button, etc). What you do with the resulting count is also up to you.
If you do use the extension library which I recommended and used in the example above check the developers guide it is pretty useful.