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.CyclOSM = L.OSM.TileLayer.extend({
 
  24     url: 'https://{s}.tile-cyclosm.openstreetmap.fr/cyclosm/{z}/{x}/{y}.png',
 
  27     attribution: '© <a href="https://www.openstreetmap.org/copyright" target="_blank">OpenStreetMap</a> contributors. Tiles courtesy of <a href="https://www.openstreetmap.fr" target="_blank">OpenStreetMap France</a>'
 
  31 L.OSM.CycleMap = L.OSM.TileLayer.extend({
 
  33     url: 'https://{s}.tile.thunderforest.com/cycle/{z}/{x}/{y}{r}.png?apikey={apikey}',
 
  35     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>'
 
  39 L.OSM.TransportMap = L.OSM.TileLayer.extend({
 
  41     url: 'https://{s}.tile.thunderforest.com/transport/{z}/{x}/{y}{r}.png?apikey={apikey}',
 
  43     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>'
 
  47 L.OSM.TransportDarkMap = L.OSM.TileLayer.extend({
 
  49     url: 'https://{s}.tile.thunderforest.com/transport-dark/{z}/{x}/{y}{r}.png?apikey={apikey}',
 
  51     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>'
 
  55 L.OSM.OPNVKarte = L.OSM.TileLayer.extend({
 
  57     url: 'https://tileserver.memomaps.de/tilegen/{z}/{x}/{y}.png',
 
  59     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>'
 
  63 L.OSM.HOT = L.OSM.TileLayer.extend({
 
  65     url: 'https://tile-{s}.openstreetmap.fr/hot/{z}/{x}/{y}.png',
 
  68     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>'
 
  72 L.OSM.TracestrackTopo = L.OSM.TileLayer.extend({
 
  74     url: 'https://tile.tracestrack.com/topo__/{z}/{x}/{y}.png?key={apikey}',
 
  76     attribution: '© <a href="https://www.openstreetmap.org/copyright" target="_blank">OpenStreetMap</a> contributors. Tiles courtesy of <a href="https://www.tracestrack.com/" target="_blank">Tracestrack Maps</a>'
 
  80 L.OSM.GPS = L.OSM.TileLayer.extend({
 
  82     url: 'https://gps.tile.openstreetmap.org/lines/{z}/{x}/{y}.png',
 
  89 L.OSM.DataLayer = L.FeatureGroup.extend({
 
  91     areaTags: ['area', 'building', 'leisure', 'tourism', 'ruins', 'historic', 'landuse', 'military', 'natural', 'sport'],
 
  92     uninterestingTags: ['source', 'source_ref', 'source:ref', 'history', 'attribution', 'created_by', 'tiger:county', 'tiger:tlid', 'tiger:upload_uuid'],
 
  97   initialize: function (xml, options) {
 
  98     L.Util.setOptions(this, options);
 
 100     L.FeatureGroup.prototype.initialize.call(this);
 
 107   addData: function (features) {
 
 108     if (!(features instanceof Array)) {
 
 109       features = this.buildFeatures(features);
 
 112     for (var i = 0; i < features.length; i++) {
 
 113       let feature = features[i], layer;
 
 115       if (feature.type === "changeset") {
 
 116         layer = L.rectangle(feature.latLngBounds, this.options.styles.changeset);
 
 117       } else if (feature.type === "node") {
 
 118         layer = L.circleMarker(feature.latLng, this.options.styles.node);
 
 120         var latLngs = new Array(feature.nodes.length);
 
 122         for (var j = 0; j < feature.nodes.length; j++) {
 
 123           latLngs[j] = feature.nodes[j].latLng;
 
 126         if (this.isWayArea(feature)) {
 
 127           latLngs.pop(); // Remove last == first.
 
 128           layer = L.polygon(latLngs, this.options.styles.area);
 
 130           layer = L.polyline(latLngs, this.options.styles.way);
 
 134       if (this.options.asynchronous) {
 
 135         setTimeout(() => layer.addTo(this));
 
 140       layer.feature = feature;
 
 144   buildFeatures: function (xml) {
 
 145     var features = L.OSM.getChangesets(xml),
 
 146       nodes = L.OSM.getNodes(xml),
 
 147       ways = L.OSM.getWays(xml, nodes),
 
 148       relations = L.OSM.getRelations(xml, nodes, ways);
 
 150     for (var node_id in nodes) {
 
 151       var node = nodes[node_id];
 
 152       if (this.interestingNode(node, ways, relations)) {
 
 157     for (var i = 0; i < ways.length; i++) {
 
 165   isWayArea: function (way) {
 
 166     if (way.nodes[0] != way.nodes[way.nodes.length - 1]) {
 
 170     for (var key in way.tags) {
 
 171       if (~this.options.areaTags.indexOf(key)) {
 
 179   interestingNode: function (node, ways, relations) {
 
 182     for (var i = 0; i < ways.length; i++) {
 
 183       if (ways[i].nodes.indexOf(node) >= 0) {
 
 193     for (var i = 0; i < relations.length; i++) {
 
 194       if (relations[i].members.indexOf(node) >= 0)
 
 198     for (var key in node.tags) {
 
 199       if (this.options.uninterestingTags.indexOf(key) < 0) {
 
 207   onRemove: function(map) {
 
 208     this.eachLayer(map.removeLayer, map, this.options.asynchronous);
 
 211   onAdd: function(map) {
 
 212     this.eachLayer(map.addLayer, map, this.options.asynchronous);
 
 215   eachLayer: function (method, context, asynchronous = false) {
 
 216     for (let i in this._layers) {
 
 219           method.call(context, this._layers[i]);
 
 222         method.call(context, this._layers[i]);
 
 229 L.Util.extend(L.OSM, {
 
 230   getChangesets: function (xml) {
 
 233     var nodes = xml.getElementsByTagName("changeset");
 
 234     for (var i = 0; i < nodes.length; i++) {
 
 235       var node = nodes[i], id = node.getAttribute("id");
 
 239         latLngBounds: L.latLngBounds(
 
 240           [node.getAttribute("min_lat"), node.getAttribute("min_lon")],
 
 241           [node.getAttribute("max_lat"), node.getAttribute("max_lon")]),
 
 242         tags: this.getTags(node)
 
 249   getNodes: function (xml) {
 
 252     var nodes = xml.getElementsByTagName("node");
 
 253     for (var i = 0; i < nodes.length; i++) {
 
 254       var node = nodes[i], id = node.getAttribute("id");
 
 258         latLng: L.latLng(node.getAttribute("lat"),
 
 259                          node.getAttribute("lon"),
 
 261         tags: this.getTags(node)
 
 268   getWays: function (xml, nodes) {
 
 271     var ways = xml.getElementsByTagName("way");
 
 272     for (var i = 0; i < ways.length; i++) {
 
 273       var way = ways[i], nds = way.getElementsByTagName("nd");
 
 276         id: way.getAttribute("id"),
 
 278         nodes: new Array(nds.length),
 
 279         tags: this.getTags(way)
 
 282       for (var j = 0; j < nds.length; j++) {
 
 283         way_object.nodes[j] = nodes[nds[j].getAttribute("ref")];
 
 286       result.push(way_object);
 
 292   getRelations: function (xml, nodes, ways) {
 
 295     var rels = xml.getElementsByTagName("relation");
 
 296     for (var i = 0; i < rels.length; i++) {
 
 297       var rel = rels[i], members = rel.getElementsByTagName("member");
 
 300         id: rel.getAttribute("id"),
 
 302         members: new Array(members.length),
 
 303         tags: this.getTags(rel)
 
 306       for (var j = 0; j < members.length; j++) {
 
 307         if (members[j].getAttribute("type") === "node")
 
 308           rel_object.members[j] = nodes[members[j].getAttribute("ref")];
 
 309         else // relation-way and relation-relation membership not implemented
 
 310           rel_object.members[j] = null;
 
 313       result.push(rel_object);
 
 319   getTags: function (xml) {
 
 322     var tags = xml.getElementsByTagName("tag");
 
 323     for (var j = 0; j < tags.length; j++) {
 
 324       result[tags[j].getAttribute("k")] = tags[j].getAttribute("v");