Document name in geoxml3 -


my kml under

<?xml version="1.0" encoding="utf-8"?> <kml xmlns="http://www.opengis.net/kml/2.2">     <document>         <name>car parks</name>         <description>car parks</description>         <folder>             <name>data objects</name>             <open>1</open>             <description>data objects</description>             <placemark id="cp11">                 <name>cp11</name>                 <description>cp11</description>                 <styleurl>#0-normal</styleurl>                       <point>                     <coordinates>4.878205,52.371968,0</coordinates>                 </point>             </placemark>         </folder>     </document> </kml> 

my javascript under

geoxml = new geoxml3.parser({                 createmarker: createmarker                         });   createmarker:function(placemark, doc) {      var markeroptions = {       optimized: false     };      // create marker on map     var marker = new google.maps.marker(markeroptions);     if (!doc) {         doc.markers.push(marker);     }      google.maps.event.addlistener(marker, 'click', function()      {                      // want access document name here of 'car parks'          alert(doc.document);     });   } 

how can document name in marker click event of marker? when click marker on map, want know type of marker user has clicked on.

there optional placemark parse function

pmparsefn 

which passed reference xml dom associated placemark. example using it

it isn't designed purpose, if kml format fixed, can <name> of <document> tag doing this:

var map; var geoxml = null;  function initialize() {     var latlong = new google.maps.latlng(59.32, 13.48);      var googlemaps_options = {         zoom: 18,         center: latlong,         maptypeid: google.maps.maptypeid.satellite,         streetviewcontrol: false     }      map = new google.maps.map(document.getelementbyid('map_canvas'), googlemaps_options);     geoxml = new geoxml3.parser({                createmarker: createmarker,                pmparsefn: parseplacemark,            map:map                });     geoxml.parse("http://www.geocodezip.com/geoxml3_test/so_20140306_name.kml"); }  // custom placemark parse function function parseplacemark (node, placemark) {       var addressnodes = node.parentnode.parentnode.getelementsbytagname('name');       var address = null;       if (addressnodes && addressnodes.length && (addressnodes.length > 0)) {         placemark.docname = geoxml3.nodevalue(addressnodes[0]);       } }    function createmarker(placemark, doc) {     var markeroptions = {       optimized: false,       position: placemark.latlng,       map: map     };      // create marker on map     var marker = new google.maps.marker(markeroptions);     if (!doc) {         doc.markers.push(marker);     }      google.maps.event.addlistener(marker, 'click', function()      {                      // want access document name here of 'car parks'          alert(placemark.docname);     });   }       google.maps.event.adddomlistener(window, 'load', initialize); 

working example

working example 2 different kml files


Comments

Popular posts from this blog

c# - How to get the current UAC mode -

postgresql - Lazarus + Postgres: incomplete startup packet -

javascript - Ajax jqXHR.status==0 fix error -