Accessing Extendeddata Information Via Google Maps Api V3
Solution 1:
I was looking for the exact same thing. I constructed a jQuery solution from the information I found here.
Since jQuery can parse xml easily, and kml is xml, it works out pretty well. Here's the function I wrote.
functionextendedDataToArray(feature)
{
var returnArray = newArray();
$(feature.getKml()).find("Data").each(function()
{
returnArray[$(this).attr("name")] = $(this).find("value").text();
}
);
return returnArray;
}
The function returns an associative array with keys equal to the names of your data elements, and values as the content of your value tags. Hope this helps!
Solution 2:
Another solution might to pass data in the placemark description and preprocess description when it needs to be used.
/*
<Placemark><name></name><description><![CDATA[
Lorem Ipsum [data]{"datakey":524}[/data]
]]>
</description><Point><coordinates>COORDINATES</coordinates></Point></Placemark>
*/
var map_overlay = new google.maps.KmlLayer(
'URL_TO_KML_FILE',
{
'suppressInfoWindows': true
}
);
map_overlay.setMap( gmap );
var placemarkInfo = new google.maps.InfoWindow();
google.maps.event.addListener(map_overlay, 'click', function (kmlEvent) {
var text_to_process = kmlEvent.featureData.description,
matches = text_to_process.match(/\[data\](.*)\[\/data\]/),
json_data_string = matches[1],
json_data = JSON.parse(json_data_string),
real_description = text_to_process.split('[data]')[0];
alert(json_data.datakey);
placemarkInfo.setContent( real_description );
placemarkInfo.setPosition(kmlEvent.latLng);
placemarkInfo.open(gmap);
});
Solution 3:
I'm looking for the same thing. You can see what data is being returned by using the JSON.stringify()
function on the kmlEvent
object:
alert(JSON.stringify(kmlEvent));
ExtendedData
nodes are partially supported according to the KML Elements Supported in Google Maps page but I have yet to figure out how to properly use them.
Solution 4:
Certain Data is stripped from the ExtendedData, but you can use the getBalloonHtml()
or getBalloonHtmlUnsafe()
if you trust the source of the KML. See 'https://developers.google.com/kml/documentation/extendeddata' for reference.
Post a Comment for "Accessing Extendeddata Information Via Google Maps Api V3"