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',
 
  22 L.OSM.CycleMap = L.OSM.TileLayer.extend({
 
  24     url: 'http://{s}.tile.opencyclemap.org/cycle/{z}/{x}/{y}.png'
 
  28 L.OSM.TransportMap = L.OSM.TileLayer.extend({
 
  30     url: 'http://{s}.tile2.opencyclemap.org/transport/{z}/{x}/{y}.png'
 
  34 L.OSM.MapQuestOpen = L.OSM.TileLayer.extend({
 
  36     url: 'http://otile{s}.mqcdn.com/tiles/1.0.0/osm/{z}/{x}/{y}.png',
 
  38     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'>"
 
  42 L.OSM.HOT = L.OSM.TileLayer.extend({
 
  44     url: 'http://{s}.tile.openstreetmap.fr/hot/{z}/{x}/{y}.png',
 
  47     attribution: "Tiles courtesy of <a href='http://hot.openstreetmap.org/' target='_blank'>Humanitarian OpenStreetMap Team</a>"
 
  51 L.OSM.DataLayer = L.FeatureGroup.extend({
 
  53     areaTags: ['area', 'building', 'leisure', 'tourism', 'ruins', 'historic', 'landuse', 'military', 'natural', 'sport'],
 
  54     uninterestingTags: ['source', 'source_ref', 'source:ref', 'history', 'attribution', 'created_by', 'tiger:county', 'tiger:tlid', 'tiger:upload_uuid'],
 
  58   initialize: function (xml, options) {
 
  59     L.Util.setOptions(this, options);
 
  61     L.FeatureGroup.prototype.initialize.call(this);
 
  68   addData: function (features) {
 
  69     if (!(features instanceof Array)) {
 
  70       features = this.buildFeatures(features);
 
  73     for (var i = 0; i < features.length; i++) {
 
  74       var feature = features[i], layer;
 
  76       if (feature.type === "changeset") {
 
  77         layer = L.rectangle(feature.latLngBounds, this.options.styles.changeset);
 
  78       } else if (feature.type === "node") {
 
  79         layer = L.circleMarker(feature.latLng, this.options.styles.node);
 
  81         var latLngs = new Array(feature.nodes.length);
 
  83         for (var j = 0; j < feature.nodes.length; j++) {
 
  84           latLngs[j] = feature.nodes[j].latLng;
 
  87         if (this.isWayArea(feature)) {
 
  88           latLngs.pop(); // Remove last == first.
 
  89           layer = L.polygon(latLngs, this.options.styles.area);
 
  91           layer = L.polyline(latLngs, this.options.styles.way);
 
  96       layer.feature = feature;
 
 100   buildFeatures: function (xml) {
 
 101     var features = L.OSM.getChangesets(xml),
 
 102       nodes = L.OSM.getNodes(xml),
 
 103       ways = L.OSM.getWays(xml, nodes),
 
 104       relations = L.OSM.getRelations(xml, nodes, ways);
 
 106     for (var node_id in nodes) {
 
 107       var node = nodes[node_id];
 
 108       if (this.interestingNode(node, ways, relations)) {
 
 113     for (var i = 0; i < ways.length; i++) {
 
 121   isWayArea: function (way) {
 
 122     if (way.nodes[0] != way.nodes[way.nodes.length - 1]) {
 
 126     for (var key in way.tags) {
 
 127       if (~this.options.areaTags.indexOf(key)) {
 
 135   interestingNode: function (node, ways, relations) {
 
 138     for (var i = 0; i < ways.length; i++) {
 
 139       if (ways[i].nodes.indexOf(node) >= 0) {
 
 149     for (var i = 0; i < relations.length; i++) {
 
 150       if (relations[i].members.indexOf(node) >= 0)
 
 154     for (var key in node.tags) {
 
 155       if (this.options.uninterestingTags.indexOf(key) < 0) {
 
 164 L.Util.extend(L.OSM, {
 
 165   getChangesets: function (xml) {
 
 168     var nodes = xml.getElementsByTagName("changeset");
 
 169     for (var i = 0; i < nodes.length; i++) {
 
 170       var node = nodes[i], id = node.getAttribute("id");
 
 174         latLngBounds: L.latLngBounds(
 
 175           [node.getAttribute("min_lat"), node.getAttribute("min_lon")],
 
 176           [node.getAttribute("max_lat"), node.getAttribute("max_lon")]),
 
 177         tags: this.getTags(node)
 
 184   getNodes: function (xml) {
 
 187     var nodes = xml.getElementsByTagName("node");
 
 188     for (var i = 0; i < nodes.length; i++) {
 
 189       var node = nodes[i], id = node.getAttribute("id");
 
 193         latLng: L.latLng(node.getAttribute("lat"),
 
 194                          node.getAttribute("lon"),
 
 196         tags: this.getTags(node)
 
 203   getWays: function (xml, nodes) {
 
 206     var ways = xml.getElementsByTagName("way");
 
 207     for (var i = 0; i < ways.length; i++) {
 
 208       var way = ways[i], nds = way.getElementsByTagName("nd");
 
 211         id: way.getAttribute("id"),
 
 213         nodes: new Array(nds.length),
 
 214         tags: this.getTags(way)
 
 217       for (var j = 0; j < nds.length; j++) {
 
 218         way_object.nodes[j] = nodes[nds[j].getAttribute("ref")];
 
 221       result.push(way_object);
 
 227   getRelations: function (xml, nodes, ways) {
 
 230     var rels = xml.getElementsByTagName("relation");
 
 231     for (var i = 0; i < rels.length; i++) {
 
 232       var rel = rels[i], members = rel.getElementsByTagName("member");
 
 235         id: rel.getAttribute("id"),
 
 237         members: new Array(members.length),
 
 238         tags: this.getTags(rel)
 
 241       for (var j = 0; j < members.length; j++) {
 
 242         if (members[j].getAttribute("type") === "node")
 
 243           rel_object.members[j] = nodes[members[j].getAttribute("ref")];
 
 244         else // relation-way and relation-relation membership not implemented
 
 245           rel_object.members[j] = null;
 
 248       result.push(rel_object);
 
 254   getTags: function (xml) {
 
 257     var tags = xml.getElementsByTagName("tag");
 
 258     for (var j = 0; j < tags.length; j++) {
 
 259       result[tags[j].getAttribute("k")] = tags[j].getAttribute("v");