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, ways)) {
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, ways) {
125 for (var i = 0; i < ways.length; i++) {
126 if (ways[i].nodes.indexOf(node) >= 0) {
136 for (var key in node.tags) {
137 if (this.options.uninterestingTags.indexOf(key) < 0) {
146 L.Util.extend(L.OSM, {
147 getNodes: function (xml) {
150 var nodes = xml.getElementsByTagName("node");
151 for (var i = 0; i < nodes.length; i++) {
152 var node = nodes[i], id = node.getAttribute("id");
156 latLng: L.latLng(node.getAttribute("lat"),
157 node.getAttribute("lon"),
159 tags: this.getTags(node)
166 getWays: function (xml, nodes) {
169 var ways = xml.getElementsByTagName("way");
170 for (var i = 0; i < ways.length; i++) {
171 var way = ways[i], nds = way.getElementsByTagName("nd");
174 id: way.getAttribute("id"),
176 nodes: new Array(nds.length),
177 tags: this.getTags(way)
180 for (var j = 0; j < nds.length; j++) {
181 way_object.nodes[j] = nodes[nds[j].getAttribute("ref")];
184 result.push(way_object);
190 getTags: function (xml) {
193 var tags = xml.getElementsByTagName("tag");
194 for (var j = 0; j < tags.length; j++) {
195 result[tags[j].getAttribute("k")] = tags[j].getAttribute("v");