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 (xml) {
59 var nodes = L.OSM.getNodes(xml),
60 ways = L.OSM.getWays(xml);
62 for (var i = 0; i < ways.length; i++) {
64 latLngs = new Array(way.nodes.length);
66 for (var j = 0; j < way.nodes.length; j++) {
67 latLngs[j] = nodes[way.nodes[j]].latLng;
72 if (this.isWayArea(way)) {
73 latLngs.pop(); // Remove last == first.
74 layer = L.polygon(latLngs, this.options.styles.area);
76 layer = L.polyline(latLngs, this.options.styles.way);
83 for (var node_id in nodes) {
84 var node = nodes[node_id];
85 if (this.interestingNode(node)) {
86 var layer = L.circleMarker(node.latLng, this.options.styles.node);
94 isWayArea: function (way) {
95 if (way.nodes[0] != way.nodes[way.nodes.length - 1]) {
99 for (var key in way.tags) {
100 if (~this.options.areaTags.indexOf(key)) {
108 interestingNode: function (node) {
109 for (var key in node.tags) {
110 if (!~this.options.uninterestingTags.indexOf(key)) {
119 L.Util.extend(L.OSM, {
120 getNodes: function (xml) {
123 var nodes = xml.getElementsByTagName("node");
124 for (var i = 0; i < nodes.length; i++) {
125 var node = nodes[i], id = node.getAttribute("id");
129 latLng: L.latLng(node.getAttribute("lat"),
130 node.getAttribute("lon"),
132 tags: this.getTags(node)
139 getWays: function (xml) {
142 var ways = xml.getElementsByTagName("way");
143 for (var i = 0; i < ways.length; i++) {
144 var way = ways[i], nds = way.getElementsByTagName("nd");
147 id: way.getAttribute("id"),
149 nodes: new Array(nds.length),
150 tags: this.getTags(way)
153 for (var j = 0; j < nds.length; j++) {
154 way_object.nodes[j] = nds[j].getAttribute("ref");
157 result.push(way_object);
163 getTags: function (xml) {
166 var tags = xml.getElementsByTagName("tag");
167 for (var j = 0; j < tags.length; j++) {
168 result[tags[j].getAttribute("k")] = tags[j].getAttribute("v");