Skip to content

Commit

Permalink
Added support for KML StyleMap element
Browse files Browse the repository at this point in the history
Added support for the KML element StyleMap, see:
https://developers.google.com/kml/documentation/kmlreference#stylemap

Only the 'normal' key-pair is added to the array of existing styles not the 'highlight' one.

New function "parseStyleMap" was added, and is called just after the existing parsing of the KML Style element.
  • Loading branch information
opie committed Oct 18, 2013
1 parent ac00968 commit 662e88b
Showing 1 changed file with 22 additions and 0 deletions.
22 changes: 22 additions & 0 deletions layer/vector/KML.js
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ L.Util.extend(L.KML, {

parseKML: function (xml) {
var style = this.parseStyle(xml);
this.parseStyleMap(xml, style);
var el = xml.getElementsByTagName("Folder");
var layers = [], l;
for (var i = 0; i < el.length; i++) {
Expand Down Expand Up @@ -146,6 +147,27 @@ L.Util.extend(L.KML, {
}
return style;
},

parseStyleMap: function (xml, existingStyles) {
var sl = xml.getElementsByTagName("StyleMap");

for (var i = 0; i < sl.length; i++) {
var e = sl[i], el;
var smKey, smStyleUrl;

el = e.getElementsByTagName("key");
if (el && el[0]) { smKey = el[0].textContent; }
el = e.getElementsByTagName("styleUrl");
if (el && el[0]) { smStyleUrl = el[0].textContent; }

if (smKey=='normal')
{
existingStyles['#' + e.getAttribute('id')] = existingStyles[smStyleUrl];
}
}

return;
},

parseFolder: function (xml, style) {
var el, layers = [], l;
Expand Down

0 comments on commit 662e88b

Please sign in to comment.