1 L.OSM = L.FeatureGroup.extend({
3 areaTags: ['area', 'building', 'leisure', 'tourism', 'ruins', 'historic', 'landuse', 'military', 'natural', 'sport'],
4 uninterestingTags: ['source', 'source_ref', 'source:ref', 'history', 'attribution', 'created_by', 'tiger:county', 'tiger:tlid', 'tiger:upload_uuid'],
8 initialize: function (xml, options) {
9 L.Util.setOptions(this, options);
11 L.FeatureGroup.prototype.initialize.call(this);
18 addData: function (xml) {
19 var nodes = L.OSM.getNodes(xml),
20 ways = L.OSM.getWays(xml);
22 for (var i = 0; i < ways.length; i++) {
24 latLngs = new Array(way.nodes.length);
26 for (var j = 0; j < way.nodes.length; j++) {
27 latLngs[j] = nodes[way.nodes[j]].latLng;
32 if (this.isWayArea(way)) {
33 latLngs.pop(); // Remove last == first.
34 layer = L.polygon(latLngs, this.options.styles.area);
36 layer = L.polyline(latLngs, this.options.styles.way);
43 for (var node_id in nodes) {
44 var node = nodes[node_id];
45 if (this.interestingNode(node)) {
46 var layer = L.circleMarker(node.latLng, this.options.styles.node);
54 isWayArea: function (way) {
55 if (way.nodes[0] != way.nodes[way.nodes.length - 1]) {
59 for (var key in way.tags) {
60 if (~this.options.areaTags.indexOf(key)) {
68 interestingNode: function (node) {
69 for (var key in node.tags) {
70 if (!~this.options.uninterestingTags.indexOf(key)) {
79 L.Util.extend(L.OSM, {
80 getNodes: function (xml) {
83 var nodes = xml.getElementsByTagName("node");
84 for (var i = 0; i < nodes.length; i++) {
85 var node = nodes[i], id = node.getAttribute("id");
89 latLng: L.latLng(node.getAttribute("lat"),
90 node.getAttribute("lon"),
92 tags: this.getTags(node)
99 getWays: function (xml) {
102 var ways = xml.getElementsByTagName("way");
103 for (var i = 0; i < ways.length; i++) {
104 var way = ways[i], nds = way.getElementsByTagName("nd");
107 id: way.getAttribute("id"),
109 nodes: new Array(nds.length),
110 tags: this.getTags(way)
113 for (var j = 0; j < nds.length; j++) {
114 way_object.nodes[j] = nds[j].getAttribute("ref");
117 result.push(way_object);
123 getTags: function (xml) {
126 var tags = xml.getElementsByTagName("tag");
127 for (var j = 0; j < tags.length; j++) {
128 result[tags[j].getAttribute("k")] = tags[j].getAttribute("v");