X-Git-Url: http://git.cyclocoop.org/?a=blobdiff_plain;f=www%2Fplugins%2Fgis%2Flib%2Fleaflet%2Fplugins%2FGPX.js;fp=www%2Fplugins%2Fgis%2Flib%2Fleaflet%2Fplugins%2FGPX.js;h=f582d5a4a85b04af6c9714f81b54dfcfe4c3ff26;hb=c0f18416f529232b5555c6410a8765a5125ebcd3;hp=e2e7d6ae1a24a3b2a01911fecae81a46c8064ac0;hpb=50522c53acc9e61a4a7de3a1890c4ba93e2f61b4;p=lhc%2Fweb%2Fwww.git diff --git a/www/plugins/gis/lib/leaflet/plugins/GPX.js b/www/plugins/gis/lib/leaflet/plugins/GPX.js index e2e7d6ae..f582d5a4 100755 --- a/www/plugins/gis/lib/leaflet/plugins/GPX.js +++ b/www/plugins/gis/lib/leaflet/plugins/GPX.js @@ -1,5 +1,5 @@ L.GPX = L.FeatureGroup.extend({ - initialize: function(gpx, options) { + initialize: function (gpx, options) { L.Util.setOptions(this, options); this._gpx = gpx; this._layers = {}; @@ -9,7 +9,7 @@ L.GPX = 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; @@ -17,48 +17,48 @@ L.GPX = L.FeatureGroup.extend({ req.open('GET', url, async); try { req.overrideMimeType('text/xml'); // unsupported by IE - } catch(e) {} - req.onreadystatechange = function() { + } catch (e) {} + req.onreadystatechange = function () { if (req.readyState !== 4) return; - if(req.status === 200) cb(req.responseXML, options); + if (req.status === 200) cb(req.responseXML, options); }; req.send(null); }, - _humanLen: function(l) { + _humanLen: function (l) { if (l < 2000) return l.toFixed(0) + ' m'; else return (l/1000).toFixed(1) + ' km'; }, - _polylineLen: function(line)//line is a L.Polyline() + _polylineLen: function (line)//line is a L.Polyline() { var ll = line._latlngs; var d = 0, p = null; for (var i = 0; i < ll.length; i++) { - if(i && p) + if (i && p) d += p.distanceTo(ll[i]); p = ll[i]; } return d; }, - addGPX: function(url, options, async) { + addGPX: function (url, options, async) { var _this = this; - var cb = function(gpx, options) { _this._addGPX(gpx, options); }; + var cb = function (gpx, options) { _this._addGPX(gpx, options); }; this.loadXML(url, cb, options, async); }, - _addGPX: function(gpx, options) { + _addGPX: function (gpx, options) { var layers = this.parseGPX(gpx, options); if (!layers) return; this.addLayer(layers); this.fire('loaded'); - }, + }, - parseGPX: function(xml, options) { + parseGPX: function (xml, options) { var j, i, el, layers = []; var named = false, tags = [['rte','rtept'], ['trkseg','trkpt']]; @@ -91,8 +91,8 @@ L.GPX = L.FeatureGroup.extend({ return layer; }, - parse_name: function(xml, layer) { - var i, el, txt='', name, descr='', len=0; + parse_name: function (xml, layer) { + var i, el, txt='', name, descr='', link, len=0; el = xml.getElementsByTagName('name'); if (el.length) name = el[0].childNodes[0].nodeValue; @@ -101,18 +101,22 @@ L.GPX = L.FeatureGroup.extend({ for (var j = 0; j < el[i].childNodes.length; j++) descr = descr + el[i].childNodes[j].nodeValue; } + el = xml.getElementsByTagName('link'); + if (el.length) + link = el[0].getAttribute('href'); - if(layer instanceof L.Path) + if (layer instanceof L.Path) len = this._polylineLen(layer); if (name) txt += '

' + name + '

' + descr; if (len) txt += '

' + this._humanLen(len) + '

'; - + if (link) txt += '

[...]

'; + if (layer && layer._popup === undefined) layer.bindPopup(txt); return txt; }, - parse_trkseg: function(line, xml, options, tag) { + parse_trkseg: function (line, xml, options, tag) { var el = line.getElementsByTagName(tag); if (!el.length) return []; var coords = []; @@ -132,10 +136,17 @@ L.GPX = L.FeatureGroup.extend({ return l; }, - parse_wpt: function(e, xml, options) { + parse_wpt: function (e, xml, options) { var m = new L.Marker(new L.LatLng(e.getAttribute('lat'), e.getAttribute('lon')), options); - this.fire('addpoint', {point:m}); + var attributes = {}; + for (var i = 0; i < e.childNodes.length; i++) { + var ch = e.childNodes[i]; + if (ch.nodeName !== '#text') { + attributes[ch.nodeName] = ch.textContent; + } + } + this.fire('addpoint', {point:m, attributes:attributes}); return m; } });