Open GoogleCodeExporter opened 9 years ago
not to mention a SetExtendedData() function as well =D
Original comment by trstnmk...@gmail.com
on 1 Sep 2008 at 4:02
Here is a method to provide support for getExtendedData. It takes a string of
Kml as
the argument. It returns any extended data elements that have values in a
key[value]
object. It expects the extended data to be in the format:
<Data name="Foo">
<value>bar</value>
</Data>
Tested in XP - FF3.0, IE7, Chrome
----------------------------------------------------------------
object getExtendedData(string)
----------------------------------------------------------------
function getExtendedData(kmlString) {
var xmlDoc = null;
var keyValue = new Object();
//Parse the kml
try {
//Internet Explorer
xmlDoc = new ActiveXObject("Microsoft.XMLDOM");
xmlDoc.async="false";
xmlDoc.loadXML(kmlString);
} catch(e) {
try {
//Firefox, etc.
var parser = new DOMParser();
xmlDoc = parser.parseFromString(kmlString,"text/xml");
}
catch(e) {
//Failed to parse
alert(e.message);
return;
}
}
// Get all the named elements
var data = xmlDoc.getElementsByTagName("Data");
// Iterate through the data elements
for(var i=0; i<data.length; i++) {
if(data[i].getAttribute("name") &&
data[i].getElementsByTagName("value").length > 0) {
// Get the name and value
var name = data[i].getAttribute("name");
var value = data[i].getElementsByTagName("value")[0].firstChild.data;
// Assign them to the keyValue object
keyValue[name] = value;
}
}
return keyValue;
}
----------------------------------------------------------------
Usage
----------------------------------------------------------------
var data = getExtendedData(kmlString);
for (var name in data) {
var value = data[name];
alert(name + '=' + value);
}
Original comment by fraser.c...@gmail.com
on 16 Jan 2009 at 11:36
Fixed in 5.2.1.1329
Original comment by jli...@google.com
on 16 Jun 2010 at 3:32
This comment is in answer to
https://groups.google.com/group/google-earth-browser-plugin/browse_thread/thread
/418993acc3ad1a7f#
The best way to get a particular value for ExtendedData is using the getKml()
method outlined above by Fraser.
The 5.2.1.1329 release adds a couple new methods for getting the balloon html
(placemark.getBalloonHtml() and placemark.getBalloonHtmlUnsafe() ) which allow
you to render your balloon html appropriately if you have ExtendedData, which
was not possible before this release.
Between these, I think all manipulation and usage of ExtendedData should be
covered, but if there is still something you cannot do with ExendedData, please
add to these comments and I will re-open the ticket or create a new one as
appropriate.
Original comment by jli...@google.com
on 25 Jun 2010 at 3:02
I'm not using ExtendedData in my apps, but I have been using a method similar
to above to capture other information like itemIcon within my kmltree project.
I've found performance to be pretty bad when you start using getKml(). The
reason being you may have a pretty large list of placemarks, and when you call
getKml() on a folder or document, you get all of them back and have to load
them into a DOM. Since ExtendedData can be in a Folder or Document this problem
could come up. If the plugin already has a DOM internally then it might be more
efficient to have some getter method.
Original comment by underbluewaters
on 25 Jun 2010 at 3:11
underbluewaters: I thought we had covered the core needs with the new methods,
but this is a good point. I am reopening this feature request.
Original comment by jli...@google.com
on 25 Jun 2010 at 3:20
Thanks for the response, however I think I have found an alternative way to do
what I want - and the ExtendedData works for everything else I will be / may be
using it for.
Original comment by GregoryH...@gmail.com
on 30 Jun 2010 at 12:37
getExtendedData() and setExtendedData() are critical to our product.
We create placemarks programmatically using the C# api alone and set each of
their properties using api functions.
e.g.
IKmlPlacemark placemark = gePlugin.createPlacemark("1");
placemark.setName("name 1");
placemark.setVisibility(1);
Currently, placemark extended data is not accessible through the api.
The only bypass for accessing it is to execute getKml(), edit the kml
programatically by inserting the extended data element and execute parseKml().
this bypass is very bad in terms of performance.
As mentioned by another user a few comments back, in some scenarios it can take
a lot of time to execute getKml().
This feature request is very important for our project.
Thanks,
Shaul
Original comment by gisdevt...@gmail.com
on 21 Oct 2010 at 3:50
Like @Shaul and @underbluewaters, we need to embed metadata in our KML and then
extract it via js that uses the Google Earth plug-in. The metadata is tiny, but
the KML is large. If we use getKML() and parse it, that is a large overhead.
It doesn't matter too much to us whether getExtendedData() hands us a DOM tree
or a string, but this data needs to be exposed somehow.
Original comment by hutt...@gmail.com
on 21 Nov 2010 at 3:53
Thanks for the additional details for use cases. Indeed there are a occasions
where using setExtendedData and getExtendedData would be very useful. In the
meantime, for those who simply need to attach ExtendedData to a given KML, one
workaround might be to create a placemark or other feature as a placeholder.
Give it an ID of 'metadata' for example, and then use the getElementByUrl
accessor to get just the element that contains this information. Calling
getKml() on this single feature should be significantly faster than calling it
on the Document of a large folder.
I realize this is simply a workaround for what would be useful methods in the
API, but hopefully the technique might be useful to some of you.
Original comment by jli...@google.com
on 21 Nov 2010 at 4:20
[deleted comment]
[deleted comment]
Issue 531 has been merged into this issue.
Original comment by bcke...@google.com
on 12 Mar 2011 at 12:01
Original comment by api.roman.public@gmail.com
on 28 Jul 2011 at 4:08
Hi all,
I'm trying to reproduce a ship incident using data taken from the VDR (Voyage
Data Recorder). I created a gx:track and a tour to show the ship in her last
minutes.
A getExtendedData for <gx:value>'s in a <gx:SimpleArrayData> associated to a
gx:track would enable me to show important informations like wind speed and
direction, wave heights, engine RPM and so on...
So my +1 for a getExtendedData for Tracks!!!
Original comment by risid...@gmail.com
on 23 Apr 2012 at 8:26
Original issue reported on code.google.com by
api.roman.public@gmail.com
on 12 Aug 2008 at 8:45