l = this.parsePlacemark(el[j], xml, style);
if (l) { layers.push(l); }
}
+ el = xml.getElementsByTagName('GroundOverlay');
+ for (var k = 0; k < el.length; k++) {
+ l = this.parseGroundOverlay(el[k]);
+ if (l) { layers.push(l); }
+ }
return layers;
},
var style = {};
var sl = xml.getElementsByTagName('Style');
- //for (var i = 0; i < sl.length; i++) {
- 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) {
var options = {};
l = this.parsePlacemark(el[j], xml, style);
if (l) { layers.push(l); }
}
+ el = xml.getElementsByTagName('GroundOverlay');
+ for (var k = 0; k < el.length; k++) {
+ if (!this._check_folder(el[k], xml)) { continue; }
+ l = this.parseGroundOverlay(el[k]);
+ if (l) { layers.push(l); }
+ }
if (!layers.length) { return; }
if (layers.length === 1) { return layers[0]; }
return new L.FeatureGroup(layers);
},
parsePlacemark: function (place, xml, style) {
- var i, j, el, options = {};
+ var h, i, j, el, 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);
+ }
+ }
+
el = place.getElementsByTagName('styleUrl');
for (i = 0; i < el.length; i++) {
var url = el[i].childNodes[0].nodeValue;
}
var layers = [];
- var parse = ['LineString', 'Polygon', 'Point'];
+ var parse = ['LineString', 'Polygon', 'Point', 'Track', 'gx:Track'];
for (j in parse) {
- // for jshint
- if (true)
- {
- var tag = parse[j];
- el = place.getElementsByTagName(tag);
- for (i = 0; i < el.length; i++) {
- var l = this['parse' + tag](el[i], xml, options);
- if (l) { layers.push(l); }
- }
+ 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);
+ if (l) { layers.push(l); }
}
}
return new L.Polyline(coords, options);
},
+ parseTrack: function (line, xml, options) {
+ var el = xml.getElementsByTagName('gx:coord');
+ if (el.length === 0) { el = xml.getElementsByTagName('coord'); }
+ var coords = [];
+ for (var j = 0; j < el.length; j++) {
+ coords = coords.concat(this._read_gxcoords(el[j]));
+ }
+ if (!coords.length) { return; }
+ return new L.Polyline(coords, options);
+ },
+
parsePoint: function (line, xml, options) {
var el = line.getElementsByTagName('coordinates');
if (!el.length) {
coords.push(new L.LatLng(ll[1], ll[0]));
}
return coords;
+ },
+
+ _read_gxcoords: function (el) {
+ var text = '', coords = [];
+ text = el.firstChild.nodeValue.split(' ');
+ coords.push(new L.LatLng(text[1], text[0]));
+ return coords;
+ },
+
+ parseGroundOverlay: function (xml) {
+ var latlonbox = xml.getElementsByTagName('LatLonBox')[0];
+ var bounds = new L.LatLngBounds(
+ [
+ latlonbox.getElementsByTagName('south')[0].childNodes[0].nodeValue,
+ latlonbox.getElementsByTagName('west')[0].childNodes[0].nodeValue
+ ],
+ [
+ latlonbox.getElementsByTagName('north')[0].childNodes[0].nodeValue,
+ latlonbox.getElementsByTagName('east')[0].childNodes[0].nodeValue
+ ]
+ );
+ var attributes = {Icon: true, href: true, color: true};
+ function _parse(xml) {
+ var options = {}, ioptions = {};
+ for (var i = 0; i < xml.childNodes.length; i++) {
+ var e = xml.childNodes[i];
+ var key = e.tagName;
+ if (!attributes[key]) { continue; }
+ var value = e.childNodes[0].nodeValue;
+ if (key === 'Icon') {
+ ioptions = _parse(e);
+ if (ioptions.href) { options.href = ioptions.href; }
+ } else if (key === 'href') {
+ options.href = value;
+ } else if (key === 'color') {
+ options.opacity = parseInt(value.substring(0, 2), 16) / 255.0;
+ options.color = '#' + value.substring(6, 8) + value.substring(4, 6) + value.substring(2, 4);
+ }
+ }
+ return options;
+ }
+ var options = {};
+ options = _parse(xml);
+ if (latlonbox.getElementsByTagName('rotation')[0] !== undefined) {
+ var rotation = latlonbox.getElementsByTagName('rotation')[0].childNodes[0].nodeValue;
+ options.rotation = parseFloat(rotation);
+ }
+ return new L.RotatedImageOverlay(options.href, bounds, {opacity: options.opacity, angle: options.rotation});
}
});
this.style.width = i.width + 'px';
this.style.height = i.height + 'px';
- if (this.anchorType.x === 'UNITS_FRACTION' || this.anchorType.x === 'fraction') {
+ if (this.anchorType.x === 'fraction' && this.anchorType.y === 'fraction') {
img.style.marginLeft = (-this.anchor.x * i.width) + 'px';
- }
- if (this.anchorType.y === 'UNITS_FRACTION' || this.anchorType.x === 'fraction') {
img.style.marginTop = (-(1 - this.anchor.y) * i.height) + 'px';
}
+ if (this.anchorType.x === 'pixels' && this.anchorType.y === 'pixels') {
+ img.style.marginLeft = (-this.anchor.x) + 'px';
+ img.style.marginTop = (this.anchor.y - i.height + 1) + 'px';
+ }
this.style.display = '';
};
return img;
}
});
+// Inspired by https://github.com/bbecquet/Leaflet.PolylineDecorator/tree/master/src
+L.RotatedImageOverlay = L.ImageOverlay.extend({
+ options: {
+ angle: 0
+ },
+ _reset: function () {
+ L.ImageOverlay.prototype._reset.call(this);
+ this._rotate();
+ },
+ _animateZoom: function (e) {
+ L.ImageOverlay.prototype._animateZoom.call(this, e);
+ this._rotate();
+ },
+ _rotate: function () {
+ 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) {
+ // fallback for IE6, IE7, IE8
+ var rad = this.options.angle * (Math.PI / 180),
+ costheta = Math.cos(rad),
+ sintheta = Math.sin(rad);
+ this._image.style.filter += ' progid:DXImageTransform.Microsoft.Matrix(sizingMethod=\'auto expand\', M11=' +
+ costheta + ', M12=' + (-sintheta) + ', M21=' + sintheta + ', M22=' + costheta + ')';
+ }
+ },
+ getBounds: function() {
+ return this._bounds;
+ }
+});
+