update other libs

This commit is contained in:
Norbert Renner 2014-05-14 16:01:20 +02:00
parent e4ae9b5533
commit aa1e051cfd
31 changed files with 679 additions and 719 deletions

View file

@ -1,4 +1,4 @@
//#include "GPX.js"
//#include 'GPX.js'
(function() {
@ -6,7 +6,7 @@ function d2h(d) {
var hex = '0123456789ABCDEF';
var r = '';
d = Math.floor(d);
while (d != 0) {
while (d !== 0) {
r = hex[d % 16] + r;
d = Math.floor(d / 16);
}
@ -18,23 +18,23 @@ function gradient(color) {
// First arc (0, PI) in HSV colorspace
function f2h(d) { return d2h(256 * d); }
if (color < 0)
return "#FF0000";
return '#FF0000';
else if (color < 1.0/3)
return "#FF" + f2h(3 * color) + "00";
return '#FF' + f2h(3 * color) + '00';
else if (color < 2.0/3)
return "#" + f2h(2 - 3 * color) + "FF00";
return '#' + f2h(2 - 3 * color) + 'FF00';
else if (color < 1)
return "#00FF" + f2h(3 * color - 2);
return '#00FF' + f2h(3 * color - 2);
else
return "#00FFFF";
};
return '#00FFFF';
}
function gpx2time(s) {
// 2011-09-24T12:07:53Z
if (s.length != 10 + 1 + 8 + 1)
if (s.length !== 10 + 1 + 8 + 1)
return new Date();
return new Date(s);
};
}
L.GPX.include({
options: {
@ -68,11 +68,11 @@ L.GPX.include({
p = ll[i + chunk - 1];
t = (gpx2time(p.meta.time) - t) / (3600 * 1000);
var speed = 0.001 * d / t;
//console.info('Dist: ' + d + "; Speed: " + speed);
//console.info('Dist: ' + d + '; Speed: ' + speed);
var color = gradient(speed / this.options.maxSpeed);
var l = new L.Polyline(ll.slice(i, i+chunk+1), {color: color, weight: 2, opacity: 1});
l.bindPopup('Dist: ' + d.toFixed() + "m; Speed: " + speed.toFixed(2) + " km/h");
e.line.push(l);
var poly = new L.Polyline(ll.slice(i, i+chunk+1), {color: color, weight: 2, opacity: 1});
poly.bindPopup('Dist: ' + d.toFixed() + 'm; Speed: ' + speed.toFixed(2) + ' km/h');
e.line.push(poly);
}
}

View file

@ -1,5 +1,3 @@
/*global L: true */
L.GPX = L.FeatureGroup.extend({
initialize: function(gpx, options) {
L.Util.setOptions(this, options);
@ -12,8 +10,8 @@ L.GPX = L.FeatureGroup.extend({
},
loadXML: function(url, cb, options, async) {
if (async == undefined) async = this.options.async;
if (options == undefined) options = this.options;
if (async === undefined) async = this.options.async;
if (options === undefined) options = this.options;
var req = new window.XMLHttpRequest();
req.open('GET', url, async);
@ -21,17 +19,17 @@ L.GPX = L.FeatureGroup.extend({
req.overrideMimeType('text/xml'); // unsupported by IE
} catch(e) {}
req.onreadystatechange = function() {
if (req.readyState != 4) return;
if(req.status == 200) cb(req.responseXML, options);
if (req.readyState !== 4) return;
if(req.status === 200) cb(req.responseXML, options);
};
req.send(null);
},
_humanLen: function(l) {
if (l < 2000)
return l.toFixed(0) + " m";
return l.toFixed(0) + ' m';
else
return (l/1000).toFixed(1) + " km";
return (l/1000).toFixed(1) + ' km';
},
_polylineLen: function(line)//line is a L.Polyline()
@ -49,7 +47,7 @@ L.GPX = L.FeatureGroup.extend({
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);
},
@ -57,7 +55,7 @@ L.GPX = L.FeatureGroup.extend({
var layers = this.parseGPX(gpx, options);
if (!layers) return;
this.addLayer(layers);
this.fire("loaded");
this.fire('loaded');
},
parseGPX: function(xml, options) {
@ -76,12 +74,12 @@ L.GPX = L.FeatureGroup.extend({
}
el = xml.getElementsByTagName('wpt');
if (options.display_wpt != false) {
if (options.display_wpt !== false) {
for (i = 0; i < el.length; i++) {
var l = this.parse_wpt(el[i], xml, options);
if (!l) continue;
if (this.parse_name(el[i], l)) named = true;
layers.push(l);
var marker = this.parse_wpt(el[i], xml, options);
if (!marker) continue;
if (this.parse_name(el[i], marker)) named = true;
layers.push(marker);
}
}
@ -94,7 +92,7 @@ L.GPX = L.FeatureGroup.extend({
},
parse_name: function(xml, layer) {
var i, el, txt="", name, descr="", len=0;
var i, el, txt='', name, descr='', len=0;
el = xml.getElementsByTagName('name');
if (el.length)
name = el[0].childNodes[0].nodeValue;
@ -107,8 +105,8 @@ L.GPX = L.FeatureGroup.extend({
if(layer instanceof L.Path)
len = this._polylineLen(layer);
if (name) txt += "<h2>" + name + "</h2>" + descr;
if (len) txt += "<p>" + this._humanLen(len) + "</p>";
if (name) txt += '<h2>' + name + '</h2>' + descr;
if (len) txt += '<p>' + this._humanLen(len) + '</p>';
if (layer && layer._popup === undefined) layer.bindPopup(txt);
return txt;
@ -130,7 +128,7 @@ L.GPX = L.FeatureGroup.extend({
coords.push(ll);
}
var l = [new L.Polyline(coords, options)];
this.fire('addline', {line:l})
this.fire('addline', {line:l});
return l;
},

View file

@ -1,5 +1,3 @@
/*global L: true */
L.KML = L.FeatureGroup.extend({
options: {
async: true
@ -16,8 +14,8 @@ L.KML = L.FeatureGroup.extend({
},
loadXML: function(url, cb, options, async) {
if (async == undefined) async = this.options.async;
if (options == undefined) options = this.options;
if (async === undefined) async = this.options.async;
if (options === undefined) options = this.options;
var req = new window.XMLHttpRequest();
req.open('GET', url, async);
@ -25,30 +23,29 @@ L.KML = L.FeatureGroup.extend({
req.overrideMimeType('text/xml'); // unsupported by IE
} catch(e) {}
req.onreadystatechange = function() {
if (req.readyState != 4) return;
if(req.status == 200) cb(req.responseXML, options);
if (req.readyState !== 4) return;
if (req.status === 200) cb(req.responseXML, options);
};
req.send(null);
},
addKML: function(url, options, async) {
var _this = this;
var cb = function(gpx, options) { _this._addKML(gpx, options) };
var cb = function(gpx, options) { _this._addKML(gpx, options); };
this.loadXML(url, cb, options, async);
},
_addKML: function(xml, options) {
var layers = L.KML.parseKML(xml);
if (!layers || !layers.length) return;
for (var i = 0; i < layers.length; i++)
{
for (var i = 0; i < layers.length; i++) {
this.fire('addlayer', {
layer: layers[i]
});
this.addLayer(layers[i]);
}
this.latLngs = L.KML.getLatLngs(xml);
this.fire("loaded");
this.fire('loaded');
},
latLngs: []
@ -59,7 +56,7 @@ L.Util.extend(L.KML, {
parseKML: function (xml) {
var style = this.parseStyle(xml);
this.parseStyleMap(xml, style);
var el = xml.getElementsByTagName("Folder");
var el = xml.getElementsByTagName('Folder');
var layers = [], l;
for (var i = 0; i < el.length; i++) {
if (!this._check_folder(el[i])) { continue; }
@ -79,7 +76,7 @@ L.Util.extend(L.KML, {
// - returns true if no parent Folders
_check_folder: function (e, folder) {
e = e.parentElement;
while (e && e.tagName !== "Folder")
while (e && e.tagName !== 'Folder')
{
e = e.parentElement;
}
@ -88,7 +85,7 @@ L.Util.extend(L.KML, {
parseStyle: function (xml) {
var style = {};
var sl = xml.getElementsByTagName("Style");
var sl = xml.getElementsByTagName('Style');
//for (var i = 0; i < sl.length; i++) {
var attributes = {color: true, width: true, Icon: true, href: true,
@ -109,7 +106,7 @@ L.Util.extend(L.KML, {
var value = e.childNodes[0].nodeValue;
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);
options.color = '#' + value.substring(6, 8) + value.substring(4, 6) + value.substring(2, 4);
} else if (key === 'width') {
options.weight = value;
} else if (key === 'Icon') {
@ -126,13 +123,13 @@ L.Util.extend(L.KML, {
for (var i = 0; i < sl.length; i++) {
var e = sl[i], el;
var options = {}, poptions = {}, ioptions = {};
el = e.getElementsByTagName("LineStyle");
el = e.getElementsByTagName('LineStyle');
if (el && el[0]) { options = _parse(el[0]); }
el = e.getElementsByTagName("PolyStyle");
el = e.getElementsByTagName('PolyStyle');
if (el && el[0]) { poptions = _parse(el[0]); }
if (poptions.color) { options.fillColor = poptions.color; }
if (poptions.opacity) { options.fillOpacity = poptions.opacity; }
el = e.getElementsByTagName("IconStyle");
el = e.getElementsByTagName('IconStyle');
if (el && el[0]) { ioptions = _parse(el[0]); }
if (ioptions.href) {
// save anchor info until the image is loaded
@ -149,18 +146,18 @@ L.Util.extend(L.KML, {
},
parseStyleMap: function (xml, existingStyles) {
var sl = xml.getElementsByTagName("StyleMap");
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");
el = e.getElementsByTagName('key');
if (el && el[0]) { smKey = el[0].textContent; }
el = e.getElementsByTagName("styleUrl");
el = e.getElementsByTagName('styleUrl');
if (el && el[0]) { smStyleUrl = el[0].textContent; }
if (smKey=='normal')
if (smKey === 'normal')
{
existingStyles['#' + e.getAttribute('id')] = existingStyles[smStyleUrl];
}
@ -212,7 +209,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](el[i], xml, options);
var l = this['parse' + tag](el[i], xml, options);
if (l) { layers.push(l); }
}
}
@ -226,7 +223,7 @@ L.Util.extend(L.KML, {
layer = new L.FeatureGroup(layers);
}
var name, descr = "";
var name, descr = '';
el = place.getElementsByTagName('name');
if (el.length && el[0].childNodes.length) {
name = el[0].childNodes[0].nodeValue;
@ -239,7 +236,7 @@ L.Util.extend(L.KML, {
}
if (name) {
layer.bindPopup("<h2>" + name + "</h2>" + descr);
layer.bindPopup('<h2>' + name + '</h2>' + descr);
}
return layer;
@ -304,7 +301,7 @@ L.Util.extend(L.KML, {
},
_read_coords: function (el) {
var text = "", coords = [], i;
var text = '', coords = [], i;
for (i = 0; i < el.childNodes.length; i++) {
text = text + el.childNodes[i].nodeValue;
}
@ -326,8 +323,7 @@ L.KMLIcon = L.Icon.extend({
createIcon: function () {
var img = this._createIcon('icon');
img.onload = function () {
var i = new Image();
i.src = this.src;
var i = img;
this.style.width = i.width + 'px';
this.style.height = i.height + 'px';
@ -337,13 +333,13 @@ L.KMLIcon = L.Icon.extend({
if (this.anchorType.y === 'UNITS_FRACTION' || this.anchorType.x === 'fraction') {
img.style.marginTop = (-(1 - this.anchor.y) * i.height) + 'px';
}
this.style.display = "";
this.style.display = '';
};
return img;
},
_setIconStyles: function (img, name) {
L.Icon.prototype._setIconStyles.apply(this, [img, name])
L.Icon.prototype._setIconStyles.apply(this, [img, name]);
// save anchor information to the image
img.anchor = this.options.iconAnchorRef;
img.anchorType = this.options.iconAnchorType;

View file

@ -1,4 +1,4 @@
/*global L: true */
/* global console: true */
L.OSM = L.FeatureGroup.extend({
options: {
@ -17,22 +17,22 @@ L.OSM = L.FeatureGroup.extend({
},
loadXML: function(url, cb, options, async) {
if (async == undefined) async = this.options.async;
if (options == undefined) options = this.options;
if (async === undefined) async = this.options.async;
if (options === undefined) options = this.options;
var req = new window.XMLHttpRequest();
req.open('GET', url, async);
req.overrideMimeType('text/xml');
req.onreadystatechange = function() {
if (req.readyState != 4) return;
if(req.status == 200) cb(req.responseXML, options);
if (req.readyState !== 4) return;
if (req.status === 200) cb(req.responseXML, options);
};
req.send(null);
},
addXML: function(url, options, async) {
var _this = this;
var cb = function(xml, options) { _this._addXML(xml, options) };
var cb = function(xml, options) { _this._addXML(xml, options); };
this.loadXML(url, cb, options, async);
},
@ -40,7 +40,7 @@ L.OSM = L.FeatureGroup.extend({
var layers = this.parseOSM(xml, options);
if (!layers) return;
this.addLayer(layers);
this.fire("loaded");
this.fire('loaded');
},
parseOSM: function(xml, options) {
@ -52,34 +52,34 @@ L.OSM = L.FeatureGroup.extend({
el = xml.getElementsByTagName('node');
for (i = 0; i < el.length; i++) {
var l = this.parse_node(el[i], xml, options);
if (l == undefined) continue;
if (l === undefined) continue;
nodes[l.osmid] = l;
if (!this.options.forceAll && !l.tags.length) continue;
var m = this.named_node(l, options);
if (!ll) ll = m.getLatLng();
if (this.parse_name(m, l, "Node")) named = true;
if (this.parse_name(m, l, 'Node')) named = true;
layers.push(m);
}
el = xml.getElementsByTagName('way');
for (i = 0; i < el.length; i++) {
if (i > 10) break;
var l = this.parse_way(el[i], nodes, options);
if (!l) continue;
if (!ll) ll = l.getLatLngs()[0];
if (this.parse_name(l, l, "Way")) named = true;
layers.push(l);
ways[l.osmid] = l;
var way = this.parse_way(el[i], nodes, options);
if (!way) continue;
if (!ll) ll = way.getLatLngs()[0];
if (this.parse_name(way, way, 'Way')) named = true;
layers.push(way);
ways[way.osmid] = way;
}
el = xml.getElementsByTagName('relation');
for (i = 0; i < el.length; i++) {
if (i > 10) break;
var l = this.parse_relation(el[i], ways, options);
if (!l) continue;
if (!ll) ll = l.getLatLngs()[0];
if (this.parse_name(l, l, "Relation")) named = true;
layers.push(l);
var relation = this.parse_relation(el[i], ways, options);
if (!relation) continue;
if (!ll) ll = relation.getLatLngs()[0];
if (this.parse_name(relation, relation, 'Relation')) named = true;
layers.push(relation);
}
if (!layers.length) return;
@ -92,17 +92,17 @@ L.OSM = L.FeatureGroup.extend({
},
parse_name: function(layer, obj, obj_name) {
console.info("parse name");
console.info('parse name');
console.info(this.options);
if (!this.options.forceAll)
if (!obj.tags || !obj.tags.length) return;
var i, txt = "<table>";
var i, txt = '<table>';
for (i = 0; i < obj.tags.length; i++) {
var t = obj.tags[i];
txt += "<tr><td>" + t.k + "</td><td>=</td><td>" + t.v + "</td></tr>";
txt += '<tr><td>' + t.k + '</td><td>=</td><td>' + t.v + '</td></tr>';
}
txt += "</table>"
txt = "<h2>" + obj_name + " " + obj.osmid + "</h2>" + txt;
txt += '</table>';
txt = '<h2>' + obj_name + ' ' + obj.osmid + '</h2>' + txt;
if (layer) layer.bindPopup(txt);
return txt;
},
@ -110,15 +110,15 @@ L.OSM = L.FeatureGroup.extend({
parse_tags: function(line) {
var tags = [], el = line.getElementsByTagName('tag');
for (var i = 0; i < el.length; i++)
tags.push({k: el[i].getAttribute('k'), v: el[i].getAttribute('v')})
tags.push({k: el[i].getAttribute('k'), v: el[i].getAttribute('v')});
return tags;
},
parse_node: function(e) {
var n = { osmid: e.getAttribute('id')
, lat:e.getAttribute('lat')
, lon:e.getAttribute('lon')
}
var n = { osmid: e.getAttribute('id'),
lat:e.getAttribute('lat'),
lon:e.getAttribute('lon')
};
n.ll = new L.LatLng(n.lat, n.lon);
n.tags = this.parse_tags(e);
return n;
@ -135,7 +135,7 @@ L.OSM = L.FeatureGroup.extend({
}
var layer = new L.Polyline(coords, options);
layer.tags = this.parse_tags(line);
layer.osmid = line.getAttribute('id')
layer.osmid = line.getAttribute('id');
return layer;
},
@ -143,25 +143,26 @@ L.OSM = L.FeatureGroup.extend({
var el = line.getElementsByTagName('member');
if (!el.length) return;
var rt, coords = [], tags = this.parse_tags(line);
for (var i = 0; i < tags.length; i++)
if (tags[i].k == "type") rt = tags[i].v;
var i;
for (i = 0; i < tags.length; i++)
if (tags[i].k === 'type') rt = tags[i].v;
if (rt != "multipolygon" && rt != "boundary" && rt != "waterway")
if (rt !== 'multipolygon' && rt !== 'boundary' && rt !== 'waterway')
return;
for (var i = 0; i < el.length; i++) {
var mt = el[i].getAttribute("type"), ref = el[i].getAttribute("ref");
if (mt != "way") continue;
for (i = 0; i < el.length; i++) {
var mt = el[i].getAttribute('type'), ref = el[i].getAttribute('ref');
if (mt !== 'way') continue;
var w = ways[ref];
console.info("Way: " + ref + " " + w);
console.info('Way: ' + ref + ' ' + w);
if (!w) return;
coords.push(w);
}
console.info("Coords: " + coords.length);
console.info('Coords: ' + coords.length);
if (!coords.length) return;
var layer = new L.MultiPolyline(coords, options);
layer.tags = this.parse_tags(line);
layer.osmid = line.getAttribute('id')
layer.osmid = line.getAttribute('id');
return layer;
},