3 L.OSM.TileLayer = L.TileLayer.extend({
 
   5     url: 'https://tile.openstreetmap.org/{z}/{x}/{y}.png',
 
   6     attribution: '© <a href="https://www.openstreetmap.org/copyright" target="_blank">OpenStreetMap</a> contributors'
 
   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: 'https://tile.openstreetmap.org/{z}/{x}/{y}.png',
 
  22 L.OSM.CycleMap = L.OSM.TileLayer.extend({
 
  24     url: 'https://{s}.tile.thunderforest.com/cycle/{z}/{x}/{y}{r}.png?apikey={apikey}',
 
  26     attribution: '© <a href="https://www.openstreetmap.org/copyright" target="_blank">OpenStreetMap</a> contributors. Tiles courtesy of <a href="http://www.thunderforest.com/" target="_blank">Andy Allan</a>'
 
  30 L.OSM.TransportMap = L.OSM.TileLayer.extend({
 
  32     url: 'https://{s}.tile.thunderforest.com/transport/{z}/{x}/{y}{r}.png?apikey={apikey}',
 
  34     attribution: '© <a href="https://www.openstreetmap.org/copyright" target="_blank">OpenStreetMap</a> contributors. Tiles courtesy of <a href="http://www.thunderforest.com/" target="_blank">Andy Allan</a>'
 
  38 L.OSM.OPNVKarte = L.OSM.TileLayer.extend({
 
  40     url: 'https://tileserver.memomaps.de/tilegen/{z}/{x}/{y}.png',
 
  42     attribution: '© <a href="https://www.openstreetmap.org/copyright" target="_blank">OpenStreetMap</a> contributors. Tiles courtesy of <a href="http://memomaps.de/" target="_blank">MeMoMaps</a>'
 
  46 L.OSM.HOT = L.OSM.TileLayer.extend({
 
  48     url: 'https://tile-{s}.openstreetmap.fr/hot/{z}/{x}/{y}.png',
 
  51     attribution: '© <a href="https://www.openstreetmap.org/copyright" target="_blank">OpenStreetMap</a> contributors. Tiles courtesy of <a href="http://hot.openstreetmap.org/" target="_blank">Humanitarian OpenStreetMap Team</a>'
 
  55 L.OSM.GPS = L.OSM.TileLayer.extend({
 
  57     url: 'https://gps.tile.openstreetmap.org/lines/{z}/{x}/{y}.png',
 
  64 L.OSM.DataLayer = L.FeatureGroup.extend({
 
  66     areaTags: ['area', 'building', 'leisure', 'tourism', 'ruins', 'historic', 'landuse', 'military', 'natural', 'sport'],
 
  67     uninterestingTags: ['source', 'source_ref', 'source:ref', 'history', 'attribution', 'created_by', 'tiger:county', 'tiger:tlid', 'tiger:upload_uuid'],
 
  71   initialize: function (xml, options) {
 
  72     L.Util.setOptions(this, options);
 
  74     L.FeatureGroup.prototype.initialize.call(this);
 
  81   addData: function (features) {
 
  82     if (!(features instanceof Array)) {
 
  83       features = this.buildFeatures(features);
 
  86     for (var i = 0; i < features.length; i++) {
 
  87       var feature = features[i], layer;
 
  89       if (feature.type === "changeset") {
 
  90         layer = L.rectangle(feature.latLngBounds, this.options.styles.changeset);
 
  91       } else if (feature.type === "node") {
 
  92         layer = L.circleMarker(feature.latLng, this.options.styles.node);
 
  94         var latLngs = new Array(feature.nodes.length);
 
  96         for (var j = 0; j < feature.nodes.length; j++) {
 
  97           latLngs[j] = feature.nodes[j].latLng;
 
 100         if (this.isWayArea(feature)) {
 
 101           latLngs.pop(); // Remove last == first.
 
 102           layer = L.polygon(latLngs, this.options.styles.area);
 
 104           layer = L.polyline(latLngs, this.options.styles.way);
 
 109       layer.feature = feature;
 
 113   buildFeatures: function (xml) {
 
 114     var features = L.OSM.getChangesets(xml),
 
 115       nodes = L.OSM.getNodes(xml),
 
 116       ways = L.OSM.getWays(xml, nodes),
 
 117       relations = L.OSM.getRelations(xml, nodes, ways);
 
 119     for (var node_id in nodes) {
 
 120       var node = nodes[node_id];
 
 121       if (this.interestingNode(node, ways, relations)) {
 
 126     for (var i = 0; i < ways.length; i++) {
 
 134   isWayArea: function (way) {
 
 135     if (way.nodes[0] != way.nodes[way.nodes.length - 1]) {
 
 139     for (var key in way.tags) {
 
 140       if (~this.options.areaTags.indexOf(key)) {
 
 148   interestingNode: function (node, ways, relations) {
 
 151     for (var i = 0; i < ways.length; i++) {
 
 152       if (ways[i].nodes.indexOf(node) >= 0) {
 
 162     for (var i = 0; i < relations.length; i++) {
 
 163       if (relations[i].members.indexOf(node) >= 0)
 
 167     for (var key in node.tags) {
 
 168       if (this.options.uninterestingTags.indexOf(key) < 0) {
 
 177 L.Util.extend(L.OSM, {
 
 178   getChangesets: function (xml) {
 
 181     var nodes = xml.getElementsByTagName("changeset");
 
 182     for (var i = 0; i < nodes.length; i++) {
 
 183       var node = nodes[i], id = node.getAttribute("id");
 
 187         latLngBounds: L.latLngBounds(
 
 188           [node.getAttribute("min_lat"), node.getAttribute("min_lon")],
 
 189           [node.getAttribute("max_lat"), node.getAttribute("max_lon")]),
 
 190         tags: this.getTags(node)
 
 197   getNodes: function (xml) {
 
 200     var nodes = xml.getElementsByTagName("node");
 
 201     for (var i = 0; i < nodes.length; i++) {
 
 202       var node = nodes[i], id = node.getAttribute("id");
 
 206         latLng: L.latLng(node.getAttribute("lat"),
 
 207                          node.getAttribute("lon"),
 
 209         tags: this.getTags(node)
 
 216   getWays: function (xml, nodes) {
 
 219     var ways = xml.getElementsByTagName("way");
 
 220     for (var i = 0; i < ways.length; i++) {
 
 221       var way = ways[i], nds = way.getElementsByTagName("nd");
 
 224         id: way.getAttribute("id"),
 
 226         nodes: new Array(nds.length),
 
 227         tags: this.getTags(way)
 
 230       for (var j = 0; j < nds.length; j++) {
 
 231         way_object.nodes[j] = nodes[nds[j].getAttribute("ref")];
 
 234       result.push(way_object);
 
 240   getRelations: function (xml, nodes, ways) {
 
 243     var rels = xml.getElementsByTagName("relation");
 
 244     for (var i = 0; i < rels.length; i++) {
 
 245       var rel = rels[i], members = rel.getElementsByTagName("member");
 
 248         id: rel.getAttribute("id"),
 
 250         members: new Array(members.length),
 
 251         tags: this.getTags(rel)
 
 254       for (var j = 0; j < members.length; j++) {
 
 255         if (members[j].getAttribute("type") === "node")
 
 256           rel_object.members[j] = nodes[members[j].getAttribute("ref")];
 
 257         else // relation-way and relation-relation membership not implemented
 
 258           rel_object.members[j] = null;
 
 261       result.push(rel_object);
 
 267   getTags: function (xml) {
 
 270     var tags = xml.getElementsByTagName("tag");
 
 271     for (var j = 0; j < tags.length; j++) {
 
 272       result[tags[j].getAttribute("k")] = tags[j].getAttribute("v");