update other libs
This commit is contained in:
parent
e4ae9b5533
commit
aa1e051cfd
31 changed files with 679 additions and 719 deletions
|
|
@ -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;
|
||||
},
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue