2

I understand that Geoxml3 has a built in feature to load kml extendeddata into variables (from its source code - see bellow), but I couldn't find the way to access those variables after parsing. Does anyone know how to do it? Thanks, cheers.

(line 544 of geoxml3.js of kmz branch):

// add extended data to variables
var extDataNodes = node.getElementsByTagName('ExtendedData');
if (!!extDataNodes && extDataNodes.length > 0) {
var dataNodes = extDataNodes[0].getElementsByTagName('Data');
for (var d = 0; d < dataNodes.length; d++) {
var dn    = dataNodes[d];
var name  = dn.getAttribute('name');
if (!name) continue;
var dName = geoXML3.nodeValue(dn.getElementsByTagName('displayName')[0], name);
var val   = geoXML3.nodeValue(dn.getElementsByTagName('value')[0]);

placemark.vars.val[name]     = val;
placemark.vars.display[name] = dName;
}
}
Rodolpho
  • 39
  • 1
  • 10
  • What are you trying to do with the extended data? Can you provide sample KML? A sample of your map code that shows what you are trying to do? – geocodezip Feb 03 '14 at 22:01
  • I am trying to grab some info to display on the tooltip. See here: http://www.pixel.net.br/unicef/mapa_estado.php. When you mouseover you see the tooltip (thanks) and when you click you can see there is some extra information displayed (as extended data from kml), but I can't make then show on the tooltip. As from the code above, that should be very easy since Geoxml already parse the info :/ – Rodolpho Feb 04 '14 at 03:44
  • @Rodolpho : I dont find the code which you have mentioned in the following geoxml3.js https://code.google.com/p/geoxml3/source/browse/trunk/geoxml3.js Me too want to get the values from the extended data. Any help is much appreciated. – ArunRaj Apr 07 '14 at 12:59
  • 1
    @ArunRaj It is in the kmz branch: https://code.google.com/p/geoxml3/source/browse/branches/kmz/geoxml3.js – Rodolpho May 24 '14 at 20:31

1 Answers1

2

In the kmz branch version of geoxml3, the extended data is stored in placemark.vars.val

name: "Alvarães"
percentil: "29.8"
total: "1699"

So, this should work:

    var contentString = '<div class="maptab">'+
        '<h1>'+placemark.name+'</h1>'+
        'fora da escola: '+placemark.vars.val.total+'<br>'
        'percentual: '+placemark.vars.val.percentil+
        '</div>';
    polygonMouseover(placemark.polygon,contentString);
geocodezip
  • 158,664
  • 13
  • 220
  • 245
  • I wish there were a more extensive documentation on Geoxml3. It works! Thanks :) – Rodolpho Feb 04 '14 at 13:27
  • Feel free to write some, I can add it if it looks good. I don't have the time to do it correctly (at least in the near term). – geocodezip Feb 04 '14 at 13:39
  • Sure, I would love to help. But in fact I am as good programmer as a designer can be :) But keep up the good job. Geoxml is very nice. By the way, some examples of geocodezip.com stoped working. Like this one: http://www.geocodezip.com/geoxml3_test/v3_geoxml3_kmltest_stylemap_marker.html I am trying to destroy Geoxml map instance to load a new KML one with JQuery, and all examples of "LoadKML" seems not to be working... Is it deprecated? Tks! – Rodolpho Feb 04 '14 at 15:52
  • I'm not sure what you mean by [this example](http://www.geocodezip.com/geoxml3_test/v3_geoxml3_kmltest_stylemap_marker.html?filename=http://www.geocodezip.com/geoxml3_test/rollover_kml.xml) stopped working. It works for me if I give it KML with markers. – geocodezip Feb 04 '14 at 16:47
  • It is just that the buttons 'loadKLMlayer', 'hideKMLlayer' and 'showKMLlayer', when pressed, don't seem to produce any effect on the map :/ – Rodolpho Feb 04 '14 at 17:13
  • They work for me on [this example](http://www.geocodezip.com/geoxml3_test/v3_geoxml3_kmltest_stylemap_marker.html?filename=http://www.geocodezip.com/geoxml3_test/rollover_kml.xml) (KmlLayer requires an absolute URL for the KML, if you don't provide that in the query string, KmlLayer won't work (the default path in that page is a polygon example that doesn't really make sense with what that example demonstrates). – geocodezip Feb 04 '14 at 17:18
  • Hummm, I see. My KML files are very big (in kb), I need to change them acording to each brazilian state (loading them all in advance doesn't make sense because of the size of each - 27 states). So I need a solution to load a new klm upon user interaction. I've tried function reload_kml(){ geoXml.hideDocument(); delete geoXml; geoXml = new geoXML3.parser({ map: map, singleInfoWindow: true, afterParse: useTheData }); geoXml.parse(filename); } but it doesn't work for me :/ What would the best aproach be, for that matter? – Rodolpho Feb 04 '14 at 18:43
  • Might be worth loading a KmlLayer with some content to show where data is available, load the geoxml3 parsed version on demand. It would definitely be worthwhile to reduce the size of your KML as much as possible, maybe even compress it to KMZ as you are using that version of the geoxml3 parser anyway. Another option would be to investigate using FusionTables, import your data into a FusionTable and use that ([fusiontips](http://gmaps-utility-gis.googlecode.com/svn/trunk/fusiontips/) shows how to implement mouseovers, but that requires querying the table for all the data). – geocodezip Feb 04 '14 at 19:03
  • It all depends on how big/complex your KML is and what acceptable performance is. – geocodezip Feb 04 '14 at 19:04
  • Compressing to kmz improves performance significantly. I've used that branch for that reason. I have also found an script to reduce curves complexity applying Douglas-Peucker algorithm when kml is dynamically generated. I have 5700 complex polygons (all Brazilian cities) divided into 27 states. If applying the algorithm is acceptable in terms of performance, I'll keep kml dynamic. Else I will compact to kmz. Thanks for all the help. – Rodolpho Feb 04 '14 at 19:30
  • would have a clue why this "hide" button on this page is not working? http://www.pixel.net.br/unicef/mapa_estado.php I have fried my brain already :/ – Rodolpho Feb 04 '14 at 21:23
  • I get two javascript errors on that page: `Uncaught ReferenceError: initialize is not defined mapa_estado.php:93`, `Uncaught ReferenceError: geoXml is not defined`; didn't look at the first, the second (and the reason the hide button doesn't work) is due to the fact that geoXml is local to the function that creates it and not available in the global scope in which click handlers run. – geocodezip Feb 04 '14 at 21:30