3 L.OSM.TileLayer = L.TileLayer.extend({
5 url: 'http://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png',
6 attribution: '© <a target="_parent" href="http://www.openstreetmap.org">OpenStreetMap</a> and contributors, under an <a target="_parent" href="http://www.openstreetmap.org/copyright">open license</a>'
9 initialize: function (options) {
10 options = L.Util.setOptions(this, options);
11 L.TileLayer.prototype.initialize.call(this, options.url);
15 L.OSM.Mapnik = L.OSM.TileLayer.extend({
17 url: 'http://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png'
21 L.OSM.CycleMap = L.OSM.TileLayer.extend({
23 url: 'http://{s}.tile.opencyclemap.org/cycle/{z}/{x}/{y}.png'
27 L.OSM.TransportMap = L.OSM.TileLayer.extend({
29 url: 'http://{s}.tile2.opencyclemap.org/transport/{z}/{x}/{y}.png'
33 L.OSM.MapQuestOpen = L.OSM.TileLayer.extend({
35 url: 'http://otile{s}.mqcdn.com/tiles/1.0.0/osm/{z}/{x}/{y}.png',
37 attribution: "Tiles courtesy of <a href='http://www.mapquest.com/' target='_blank'>MapQuest</a> <img src='http://developer.mapquest.com/content/osm/mq_logo.png'>"
41 L.OSM.DataLayer = L.FeatureGroup.extend({
43 areaTags: ['area', 'building', 'leisure', 'tourism', 'ruins', 'historic', 'landuse', 'military', 'natural', 'sport'],
44 uninterestingTags: ['source', 'source_ref', 'source:ref', 'history', 'attribution', 'created_by', 'tiger:county', 'tiger:tlid', 'tiger:upload_uuid'],
48 initialize: function (xml, options) {
49 L.Util.setOptions(this, options);
51 L.FeatureGroup.prototype.initialize.call(this);
58 addData: function (features) {
59 if (!(features instanceof Array)) {
60 features = this.buildFeatures(features);
63 for (var i = 0; i < features.length; i++) {
64 var feature = features[i], layer;
66 if (feature.type === "node") {
67 layer = L.circleMarker(feature.latLng, this.options.styles.node);
69 var latLngs = new Array(feature.nodes.length);
71 for (var j = 0; j < feature.nodes.length; j++) {
72 latLngs[j] = feature.nodes[j].latLng;
75 if (this.isWayArea(feature)) {
76 latLngs.pop(); // Remove last == first.
77 layer = L.polygon(latLngs, this.options.styles.area);
79 layer = L.polyline(latLngs, this.options.styles.way);
84 layer.feature = feature;
88 buildFeatures: function (xml) {
90 nodes = L.OSM.getNodes(xml),
91 ways = L.OSM.getWays(xml, nodes);
93 for (var node_id in nodes) {
94 var node = nodes[node_id];
95 if (this.interestingNode(node)) {
100 for (var i = 0; i < ways.length; i++) {
108 isWayArea: function (way) {
109 if (way.nodes[0] != way.nodes[way.nodes.length - 1]) {
113 for (var key in way.tags) {
114 if (~this.options.areaTags.indexOf(key)) {
122 interestingNode: function (node) {
123 for (var key in node.tags) {
124 if (!~this.options.uninterestingTags.indexOf(key)) {
133 L.Util.extend(L.OSM, {
134 getNodes: function (xml) {
137 var nodes = xml.getElementsByTagName("node");
138 for (var i = 0; i < nodes.length; i++) {
139 var node = nodes[i], id = node.getAttribute("id");
143 latLng: L.latLng(node.getAttribute("lat"),
144 node.getAttribute("lon"),
146 tags: this.getTags(node)
153 getWays: function (xml, nodes) {
156 var ways = xml.getElementsByTagName("way");
157 for (var i = 0; i < ways.length; i++) {
158 var way = ways[i], nds = way.getElementsByTagName("nd");
161 id: way.getAttribute("id"),
163 nodes: new Array(nds.length),
164 tags: this.getTags(way)
167 for (var j = 0; j < nds.length; j++) {
168 way_object.nodes[j] = nodes[nds[j].getAttribute("ref")];
171 result.push(way_object);
177 getTags: function (xml) {
180 var tags = xml.getElementsByTagName("tag");
181 for (var j = 0; j < tags.length; j++) {
182 result[tags[j].getAttribute("k")] = tags[j].getAttribute("v");