[PLUGINS] ~maj globale
[lhc/web/www.git] / www / plugins / gis / lib / leaflet / plugins / KML.js
index acdc4e8..096c1c3 100755 (executable)
@@ -3,7 +3,7 @@ L.KML = L.FeatureGroup.extend({
                async: true
        },
 
-       initialize: function(kml, options) {
+       initialize: function (kml, options) {
                L.Util.setOptions(this, options);
                this._kml = kml;
                this._layers = {};
@@ -13,7 +13,7 @@ L.KML = L.FeatureGroup.extend({
                }
        },
 
-       loadXML: function(url, cb, options, async) {
+       loadXML: function (url, cb, options, async) {
                if (async === undefined) async = this.options.async;
                if (options === undefined) options = this.options;
 
@@ -36,6 +36,7 @@ L.KML = L.FeatureGroup.extend({
                        setTimeout(function () { xdr.send(); }, 0);
                } else {
                        req.open('GET', url, async);
+                       req.setRequestHeader('Accept', 'application/vnd.google-earth.kml+xml');
                        try {
                                req.overrideMimeType('text/xml'); // unsupported by IE
                        } catch (e) { }
@@ -47,13 +48,13 @@ L.KML = L.FeatureGroup.extend({
                }
        },
 
-       addKML: function(url, options, async) {
+       addKML: function (url, options, async) {
                var _this = this;
-               var cb = function(gpx, options) { _this._addKML(gpx, options); };
+               var cb = function (kml) { _this._addKML(kml); };
                this.loadXML(url, cb, options, async);
        },
 
-       _addKML: function(xml, options) {
+       _addKML: function (xml) {
                var layers = L.KML.parseKML(xml);
                if (!layers || !layers.length) return;
                for (var i = 0; i < layers.length; i++) {
@@ -106,7 +107,7 @@ L.Util.extend(L.KML, {
                return !e || e === folder;
        },
 
-       parseStyles: function(xml) {
+       parseStyles: function (xml) {
                var styles = {};
                var sl = xml.getElementsByTagName('Style');
                for (var i=0, len=sl.length; i<len; i++) {
@@ -122,9 +123,9 @@ L.Util.extend(L.KML, {
        parseStyle: function (xml) {
                var style = {}, poptions = {}, ioptions = {}, el, id;
 
-               var attributes = { color: true, width: true, Icon: true, href: true, hotSpot: true };
+               var attributes = {color: true, width: true, Icon: true, href: true, hotSpot: true};
 
-               function _parse(xml) {
+               function _parse (xml) {
                        var options = {};
                        for (var i = 0; i < xml.childNodes.length; i++) {
                                var e = xml.childNodes[i];
@@ -224,22 +225,14 @@ L.Util.extend(L.KML, {
                return new L.FeatureGroup(layers);
        },
 
-       parsePlacemark: function (place, xml, style) {
-               var h, i, j, k, el, il, options = {};
-
-               var multi = ['MultiGeometry', 'MultiTrack', 'gx:MultiTrack'];
-               for (h in multi) {
-                       el = place.getElementsByTagName(multi[h]);
-                       for (i = 0; i < el.length; i++) {
-                               return this.parsePlacemark(el[i], xml, style);
-                       }
-               }
+       parsePlacemark: function (place, xml, style, options) {
+               var h, i, j, k, el, il, opts = options || {};
 
                el = place.getElementsByTagName('styleUrl');
                for (i = 0; i < el.length; i++) {
                        var url = el[i].childNodes[0].nodeValue;
                        for (var a in style[url]) {
-                               options[a] = style[url][a];
+                               opts[a] = style[url][a];
                        }
                }
                
@@ -248,10 +241,18 @@ L.Util.extend(L.KML, {
                        var inlineStyle = this.parseStyle(place);
                        if (inlineStyle) {
                                for (k in inlineStyle) {
-                                       options[k] = inlineStyle[k];
+                                       opts[k] = inlineStyle[k];
                                }
                        }
                }
+
+               var multi = ['MultiGeometry', 'MultiTrack', 'gx:MultiTrack'];
+               for (h in multi) {
+                       el = place.getElementsByTagName(multi[h]);
+                       for (i = 0; i < el.length; i++) {
+                               return this.parsePlacemark(el[i], xml, style, opts);
+                       }
+               }
                
                var layers = [];
 
@@ -260,7 +261,7 @@ L.Util.extend(L.KML, {
                        var tag = parse[j];
                        el = place.getElementsByTagName(tag);
                        for (i = 0; i < el.length; i++) {
-                               var l = this['parse' + tag.replace(/gx:/, '')](el[i], xml, options);
+                               var l = this['parse' + tag.replace(/gx:/, '')](el[i], xml, opts);
                                if (l) { layers.push(l); }
                        }
                }
@@ -286,7 +287,7 @@ L.Util.extend(L.KML, {
                }
 
                if (name) {
-                       layer.on('add', function(e) {
+                       layer.on('add', function () {
                                layer.bindPopup('<h2>' + name + '</h2>' + descr);
                        });
                }
@@ -399,7 +400,7 @@ L.Util.extend(L.KML, {
                        ]
                );
                var attributes = {Icon: true, href: true, color: true};
-               function _parse(xml) {
+               function _parse (xml) {
                        var options = {}, ioptions = {};
                        for (var i = 0; i < xml.childNodes.length; i++) {
                                var e = xml.childNodes[i];
@@ -469,7 +470,7 @@ L.RotatedImageOverlay = L.ImageOverlay.extend({
         if (L.DomUtil.TRANSFORM) {
             // use the CSS transform rule if available
             this._image.style[L.DomUtil.TRANSFORM] += ' rotate(' + this.options.angle + 'deg)';
-        } else if(L.Browser.ie) {
+        } else if (L.Browser.ie) {
             // fallback for IE6, IE7, IE8
             var rad = this.options.angle * (Math.PI / 180),
                 costheta = Math.cos(rad),
@@ -478,7 +479,7 @@ L.RotatedImageOverlay = L.ImageOverlay.extend({
                 costheta + ', M12=' + (-sintheta) + ', M21=' + sintheta + ', M22=' + costheta + ')';                
         }
        },
-       getBounds: function() {
+       getBounds: function () {
                return this._bounds;
        }
 });