3 L.OSM.TileLayer = L.TileLayer.extend({
 
   5     url: document.location.protocol === 'https:' ?
 
   6       'https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png' :
 
   7       'http://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png',
 
   8     attribution: '© <a href="http://www.openstreetmap.org/copyright" target="_blank">OpenStreetMap</a> contributors'
 
  11   initialize: function (options) {
 
  12     options = L.Util.setOptions(this, options);
 
  13     L.TileLayer.prototype.initialize.call(this, options.url);
 
  17 L.OSM.Mapnik = L.OSM.TileLayer.extend({
 
  19     url: document.location.protocol === 'https:' ?
 
  20       'https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png' :
 
  21       'http://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png',
 
  26 L.OSM.CycleMap = L.OSM.TileLayer.extend({
 
  28     url: document.location.protocol === 'https:' ?
 
  29       'https://{s}.tile.thunderforest.com/cycle/{z}/{x}/{y}.png' :
 
  30       'http://{s}.tile.thunderforest.com/cycle/{z}/{x}/{y}.png',
 
  31     attribution: '© <a href="http://www.openstreetmap.org/copyright" target="_blank">OpenStreetMap</a> contributors. Tiles courtesy of <a href="http://www.thunderforest.com/" target="_blank">Andy Allan</a>'
 
  35 L.OSM.TransportMap = L.OSM.TileLayer.extend({
 
  37     url:  document.location.protocol === 'https:' ?
 
  38       'https://{s}.tile.thunderforest.com/transport/{z}/{x}/{y}.png' :
 
  39       'http://{s}.tile.thunderforest.com/transport/{z}/{x}/{y}.png',
 
  40     attribution: '© <a href="http://www.openstreetmap.org/copyright" target="_blank">OpenStreetMap</a> contributors. Tiles courtesy of <a href="http://www.thunderforest.com/" target="_blank">Andy Allan</a>'
 
  44 L.OSM.MapQuestOpen = L.OSM.TileLayer.extend({
 
  46     url: document.location.protocol === 'https:' ?
 
  47       'https://otile{s}-s.mqcdn.com/tiles/1.0.0/osm/{z}/{x}/{y}.png' :
 
  48       'http://otile{s}.mqcdn.com/tiles/1.0.0/osm/{z}/{x}/{y}.png',
 
  50     attribution: '© <a href="http://www.openstreetmap.org/copyright" target="_blank">OpenStreetMap</a> contributors. ' + document.location.protocol === 'https:' ?
 
  51       'Tiles courtesy of <a href="http://www.mapquest.com/" target="_blank">MapQuest</a> <img src="https://developer.mapquest.com/content/osm/mq_logo.png">' :
 
  52       'Tiles courtesy of <a href="http://www.mapquest.com/" target="_blank">MapQuest</a> <img src="http://developer.mapquest.com/content/osm/mq_logo.png">'
 
  56 L.OSM.HOT = L.OSM.TileLayer.extend({
 
  58     url: document.location.protocol === 'https:' ?
 
  59       'https://tile-{s}.openstreetmap.fr/hot/{z}/{x}/{y}.png' :
 
  60       'http://tile-{s}.openstreetmap.fr/hot/{z}/{x}/{y}.png',
 
  63     attribution: '© <a href="http://www.openstreetmap.org/copyright" target="_blank">OpenStreetMap</a> contributors. Tiles courtesy of <a href="http://hot.openstreetmap.org/" target="_blank">Humanitarian OpenStreetMap Team</a>'
 
  67 L.OSM.DataLayer = L.FeatureGroup.extend({
 
  69     areaTags: ['area', 'building', 'leisure', 'tourism', 'ruins', 'historic', 'landuse', 'military', 'natural', 'sport'],
 
  70     uninterestingTags: ['source', 'source_ref', 'source:ref', 'history', 'attribution', 'created_by', 'tiger:county', 'tiger:tlid', 'tiger:upload_uuid'],
 
  74   initialize: function (xml, options) {
 
  75     L.Util.setOptions(this, options);
 
  77     L.FeatureGroup.prototype.initialize.call(this);
 
  84   addData: function (features) {
 
  85     if (!(features instanceof Array)) {
 
  86       features = this.buildFeatures(features);
 
  89     for (var i = 0; i < features.length; i++) {
 
  90       var feature = features[i], layer;
 
  92       if (feature.type === "changeset") {
 
  93         layer = L.rectangle(feature.latLngBounds, this.options.styles.changeset);
 
  94       } else if (feature.type === "node") {
 
  95         layer = L.circleMarker(feature.latLng, this.options.styles.node);
 
  97         var latLngs = new Array(feature.nodes.length);
 
  99         for (var j = 0; j < feature.nodes.length; j++) {
 
 100           latLngs[j] = feature.nodes[j].latLng;
 
 103         if (this.isWayArea(feature)) {
 
 104           latLngs.pop(); // Remove last == first.
 
 105           layer = L.polygon(latLngs, this.options.styles.area);
 
 107           layer = L.polyline(latLngs, this.options.styles.way);
 
 112       layer.feature = feature;
 
 116   buildFeatures: function (xml) {
 
 117     var features = L.OSM.getChangesets(xml),
 
 118       nodes = L.OSM.getNodes(xml),
 
 119       ways = L.OSM.getWays(xml, nodes),
 
 120       relations = L.OSM.getRelations(xml, nodes, ways);
 
 122     for (var node_id in nodes) {
 
 123       var node = nodes[node_id];
 
 124       if (this.interestingNode(node, ways, relations)) {
 
 129     for (var i = 0; i < ways.length; i++) {
 
 137   isWayArea: function (way) {
 
 138     if (way.nodes[0] != way.nodes[way.nodes.length - 1]) {
 
 142     for (var key in way.tags) {
 
 143       if (~this.options.areaTags.indexOf(key)) {
 
 151   interestingNode: function (node, ways, relations) {
 
 154     for (var i = 0; i < ways.length; i++) {
 
 155       if (ways[i].nodes.indexOf(node) >= 0) {
 
 165     for (var i = 0; i < relations.length; i++) {
 
 166       if (relations[i].members.indexOf(node) >= 0)
 
 170     for (var key in node.tags) {
 
 171       if (this.options.uninterestingTags.indexOf(key) < 0) {
 
 180 L.Util.extend(L.OSM, {
 
 181   getChangesets: function (xml) {
 
 184     var nodes = xml.getElementsByTagName("changeset");
 
 185     for (var i = 0; i < nodes.length; i++) {
 
 186       var node = nodes[i], id = node.getAttribute("id");
 
 190         latLngBounds: L.latLngBounds(
 
 191           [node.getAttribute("min_lat"), node.getAttribute("min_lon")],
 
 192           [node.getAttribute("max_lat"), node.getAttribute("max_lon")]),
 
 193         tags: this.getTags(node)
 
 200   getNodes: function (xml) {
 
 203     var nodes = xml.getElementsByTagName("node");
 
 204     for (var i = 0; i < nodes.length; i++) {
 
 205       var node = nodes[i], id = node.getAttribute("id");
 
 209         latLng: L.latLng(node.getAttribute("lat"),
 
 210                          node.getAttribute("lon"),
 
 212         tags: this.getTags(node)
 
 219   getWays: function (xml, nodes) {
 
 222     var ways = xml.getElementsByTagName("way");
 
 223     for (var i = 0; i < ways.length; i++) {
 
 224       var way = ways[i], nds = way.getElementsByTagName("nd");
 
 227         id: way.getAttribute("id"),
 
 229         nodes: new Array(nds.length),
 
 230         tags: this.getTags(way)
 
 233       for (var j = 0; j < nds.length; j++) {
 
 234         way_object.nodes[j] = nodes[nds[j].getAttribute("ref")];
 
 237       result.push(way_object);
 
 243   getRelations: function (xml, nodes, ways) {
 
 246     var rels = xml.getElementsByTagName("relation");
 
 247     for (var i = 0; i < rels.length; i++) {
 
 248       var rel = rels[i], members = rel.getElementsByTagName("member");
 
 251         id: rel.getAttribute("id"),
 
 253         members: new Array(members.length),
 
 254         tags: this.getTags(rel)
 
 257       for (var j = 0; j < members.length; j++) {
 
 258         if (members[j].getAttribute("type") === "node")
 
 259           rel_object.members[j] = nodes[members[j].getAttribute("ref")];
 
 260         else // relation-way and relation-relation membership not implemented
 
 261           rel_object.members[j] = null;
 
 264       result.push(rel_object);
 
 270   getTags: function (xml) {
 
 273     var tags = xml.getElementsByTagName("tag");
 
 274     for (var j = 0; j < tags.length; j++) {
 
 275       result[tags[j].getAttribute("k")] = tags[j].getAttribute("v");