Slow adding of 500 placemarks of Firefox

146 views
Skip to first unread message

Sachelis

unread,
Dec 8, 2011, 10:24:35 AM12/8/11
to KML Developer Support - Google Earth Plug-in
It takes IE (9) and Safari (5.1.1 on Mac OS) less than 2 seconds to
add 500 placemarks. It takes IE (7), Chrome (15), and Firefox (8) 60
seconds to add the same placemarks.

I wrote a simple initCB() function with a loop to time the loading.
(Note that I used a "." to help indent the code on the forum).

function initCB(instance) {
....ge = instance;
....ge.getWindow().setVisibility(true);
....
....var startTime = new Date().getTime();
....
....for( var iLp=0; iLp<500; iLp++ ) {
........// Create the placemark.
........var placemark = ge.createPlacemark('');
........
........// Set the placemark's location.
........var point = ge.createPoint('');
........point.setLatitude(40 + (iLp*0.01));
........point.setLongitude(-111 + (iLp*0.01));
........placemark.setGeometry(point);
........
........// Set the placemark's name.
........placemark.setName( 'Mark #'+iLp );
........
........// Add the placemark to Earth.
........ge.getFeatures().appendChild(placemark);
....}
....
....var elapsedTime = new Date().getTime() - startTime ;
....alert( "Loading time: " + elapsedTime );
....
....// Create a new LookAt
....var lookAt = ge.createLookAt('');
....// Set the position values
....lookAt.setLatitude(40);
....lookAt.setLongitude(-111);
....lookAt.setRange(20000.0);
....
....// Update the view in Google Earth
....ge.getView().setAbstractView(lookAt);
}

Any ideas why the load times are so different?

Thanks!

StarTraX

unread,
Dec 8, 2011, 3:11:56 PM12/8/11
to KML Developer Support - Google Earth Plug-in
It's not an answer I know, but a long time ago I abandoned creating
placemarks this way precisely for performance reasons. It's much
faster, and really not much more trouble to create the kml in a string
and use parseKml to generate the placemarks.
From the back end, the browsers are more different than they are the
same!

Sachelis

unread,
Dec 8, 2011, 8:18:00 PM12/8/11
to KML Developer Support - Google Earth Plug-in
Thanks for the suggestion, StarTranX. I changed my code to load from a
(long) kml string and the loading time on Firefox (et al) dropped from
60 seconds to less than 1 second! Crazy that appendChild() is so slow
on all but two browsers (IE v9 and Safari 5.x on Mac). My code is much
uglier building up the string, but much better performance!

> > Thanks!- Hide quoted text -
>
> - Show quoted text -

Nymor

unread,
Dec 12, 2011, 11:11:43 AM12/12/11
to KML Developer Support - Google Earth Plug-in
Hi,

While it would seem parseKml has obviously speeded things up for you
another way, if ever needed, is to use the google.earth.executeBatch()
function. This allows you to do lots of updates and have ge add all
the features in one hit.

Example at
http://earth-api-samples.googlecode.com/svn/trunk/examples/batch.html

In your code

google.earth.executeBatch(ge, function () {


for( var iLp=0; iLp<500; iLp++ ) {

...etc etc
}
});

Regards
Nymor

Reply all
Reply to author
Forward
0 new messages