3 L.extend(L.LatLngBounds.prototype, {
 
   5     return (this._northEast.lat - this._southWest.lat) *
 
   6            (this._northEast.lng - this._southWest.lng);
 
  10     return new L.LatLngBounds(this._southWest.wrap(), this._northEast.wrap());
 
  14 L.OSM.Map = L.Map.extend({
 
  15   initialize: function (id, options) {
 
  16     L.Map.prototype.initialize.call(this, id, options);
 
  18     var copyright = I18n.t("javascripts.map.copyright", { copyright_url: "/copyright" });
 
  19     var donate = I18n.t("javascripts.map.donate_link_text", { donate_url: "https://donate.openstreetmap.org" });
 
  20     var terms = I18n.t("javascripts.map.terms", { terms_url: "https://wiki.osmfoundation.org/wiki/Terms_of_Use" });
 
  21     var cyclosm = I18n.t("javascripts.map.cyclosm", { cyclosm_url: "https://www.cyclosm.org", osmfrance_url: "https://openstreetmap.fr/" });
 
  22     var thunderforest = I18n.t("javascripts.map.thunderforest", { thunderforest_url: "https://www.thunderforest.com/" });
 
  23     var memomaps = I18n.t("javascripts.map.opnvkarte", { memomaps_url: "https://memomaps.de/" });
 
  24     var hotosm = I18n.t("javascripts.map.hotosm", { hotosm_url: "https://www.hotosm.org/", osmfrance_url: "https://openstreetmap.fr/" });
 
  28     this.baseLayers.push(new L.OSM.Mapnik({
 
  29       attribution: copyright + " ♥ " + donate + ". " + terms,
 
  32       name: I18n.t("javascripts.map.base.standard")
 
  35     this.baseLayers.push(new L.OSM.CyclOSM({
 
  36       attribution: copyright + ". " + cyclosm + ". " + terms,
 
  39       name: I18n.t("javascripts.map.base.cyclosm")
 
  42     if (OSM.THUNDERFOREST_KEY) {
 
  43       this.baseLayers.push(new L.OSM.CycleMap({
 
  44         attribution: copyright + ". " + thunderforest + ". " + terms,
 
  45         apikey: OSM.THUNDERFOREST_KEY,
 
  48         name: I18n.t("javascripts.map.base.cycle_map")
 
  51       this.baseLayers.push(new L.OSM.TransportMap({
 
  52         attribution: copyright + ". " + thunderforest + ". " + terms,
 
  53         apikey: OSM.THUNDERFOREST_KEY,
 
  55         keyid: "transportmap",
 
  56         name: I18n.t("javascripts.map.base.transport_map")
 
  60     this.baseLayers.push(new L.OSM.OPNVKarte({
 
  61       attribution: copyright + ". " + memomaps + ". " + terms,
 
  64       name: I18n.t("javascripts.map.base.opnvkarte")
 
  67     this.baseLayers.push(new L.OSM.HOT({
 
  68       attribution: copyright + ". " + hotosm + ". " + terms,
 
  71       name: I18n.t("javascripts.map.base.hot")
 
  74     this.noteLayer = new L.FeatureGroup();
 
  75     this.noteLayer.options = { code: "N" };
 
  77     this.dataLayer = new L.OSM.DataLayer(null);
 
  78     this.dataLayer.options.code = "D";
 
  80     this.gpsLayer = new L.OSM.GPS({
 
  83       name: I18n.t("javascripts.map.base.gps")
 
  86     this.on("layeradd", function (event) {
 
  87       if (this.baseLayers.indexOf(event.layer) >= 0) {
 
  88         this.setMaxZoom(event.layer.options.maxZoom);
 
  93   updateLayers: function (layerParam) {
 
  94     var layers = layerParam || "M",
 
  97     for (var i = this.baseLayers.length - 1; i >= 0; i--) {
 
  98       if (layers.indexOf(this.baseLayers[i].options.code) >= 0) {
 
  99         this.addLayer(this.baseLayers[i]);
 
 100         layersAdded = layersAdded + this.baseLayers[i].options.code;
 
 101       } else if (i === 0 && layersAdded === "") {
 
 102         this.addLayer(this.baseLayers[i]);
 
 104         this.removeLayer(this.baseLayers[i]);
 
 109   getLayersCode: function () {
 
 110     var layerConfig = "";
 
 111     this.eachLayer(function (layer) {
 
 112       if (layer.options && layer.options.code) {
 
 113         layerConfig += layer.options.code;
 
 119   getMapBaseLayerId: function () {
 
 121     this.eachLayer(function (layer) {
 
 122       if (layer.options && layer.options.keyid) baseLayerId = layer.options.keyid;
 
 127   getUrl: function (marker) {
 
 128     var precision = OSM.zoomPrecision(this.getZoom()),
 
 131     if (marker && this.hasLayer(marker)) {
 
 132       var latLng = marker.getLatLng().wrap();
 
 133       params.mlat = latLng.lat.toFixed(precision);
 
 134       params.mlon = latLng.lng.toFixed(precision);
 
 137     var url = window.location.protocol + "//" + OSM.SERVER_URL + "/",
 
 138         query = Qs.stringify(params),
 
 139         hash = OSM.formatHash(this);
 
 141     if (query) url += "?" + query;
 
 142     if (hash) url += hash;
 
 147   getShortUrl: function (marker) {
 
 148     var zoom = this.getZoom(),
 
 149         latLng = marker && this.hasLayer(marker) ? marker.getLatLng().wrap() : this.getCenter().wrap(),
 
 150         str = window.location.hostname.match(/^www\.openstreetmap\.org/i) ?
 
 151           window.location.protocol + "//osm.org/go/" :
 
 152           window.location.protocol + "//" + window.location.hostname + "/go/",
 
 153         char_array = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789_~",
 
 154         x = Math.round((latLng.lng + 180.0) * ((1 << 30) / 90.0)),
 
 155         y = Math.round((latLng.lat + 90.0) * ((1 << 30) / 45.0)),
 
 156         // JavaScript only has to keep 32 bits of bitwise operators, so this has to be
 
 157         // done in two parts. each of the parts c1/c2 has 30 bits of the total in it
 
 158         // and drops the last 4 bits of the full 64 bit Morton code.
 
 159         c1 = interlace(x >>> 17, y >>> 17), c2 = interlace((x >>> 2) & 0x7fff, (y >>> 2) & 0x7fff),
 
 163     for (i = 0; i < Math.ceil((zoom + 8) / 3.0) && i < 5; ++i) {
 
 164       digit = (c1 >> (24 - (6 * i))) & 0x3f;
 
 165       str += char_array.charAt(digit);
 
 167     for (i = 5; i < Math.ceil((zoom + 8) / 3.0); ++i) {
 
 168       digit = (c2 >> (24 - (6 * (i - 5)))) & 0x3f;
 
 169       str += char_array.charAt(digit);
 
 171     for (i = 0; i < ((zoom + 8) % 3); ++i) str += "-";
 
 173     // Called to interlace the bits in x and y, making a Morton code.
 
 174     function interlace(x, y) {
 
 175       var interlaced_x = x,
 
 177       interlaced_x = (interlaced_x | (interlaced_x << 8)) & 0x00ff00ff;
 
 178       interlaced_x = (interlaced_x | (interlaced_x << 4)) & 0x0f0f0f0f;
 
 179       interlaced_x = (interlaced_x | (interlaced_x << 2)) & 0x33333333;
 
 180       interlaced_x = (interlaced_x | (interlaced_x << 1)) & 0x55555555;
 
 181       interlaced_y = (interlaced_y | (interlaced_y << 8)) & 0x00ff00ff;
 
 182       interlaced_y = (interlaced_y | (interlaced_y << 4)) & 0x0f0f0f0f;
 
 183       interlaced_y = (interlaced_y | (interlaced_y << 2)) & 0x33333333;
 
 184       interlaced_y = (interlaced_y | (interlaced_y << 1)) & 0x55555555;
 
 185       return (interlaced_x << 1) | interlaced_y;
 
 189     var layers = this.getLayersCode().replace("M", "");
 
 192       params.layers = layers;
 
 195     if (marker && this.hasLayer(marker)) {
 
 200       params[this._object.type] = this._object.id;
 
 203     var query = Qs.stringify(params);
 
 211   getGeoUri: function (marker) {
 
 212     var precision = OSM.zoomPrecision(this.getZoom()),
 
 216     if (marker && this.hasLayer(marker)) {
 
 217       latLng = marker.getLatLng().wrap();
 
 219       latLng = this.getCenter();
 
 222     params.lat = latLng.lat.toFixed(precision);
 
 223     params.lon = latLng.lng.toFixed(precision);
 
 224     params.zoom = this.getZoom();
 
 226     return "geo:" + params.lat + "," + params.lon + "?z=" + params.zoom;
 
 229   addObject: function (object, callback) {
 
 237     var changesetStyle = {
 
 248     this._objectLoader = $.ajax({
 
 249       url: OSM.apiUrl(object),
 
 251       success: function (xml) {
 
 252         map._object = object;
 
 254         map._objectLayer = new L.OSM.DataLayer(null, {
 
 259             changeset: changesetStyle
 
 263         map._objectLayer.interestingNode = function (node, ways, relations) {
 
 264           if (object.type === "node") {
 
 266           } else if (object.type === "relation") {
 
 267             for (var i = 0; i < relations.length; i++) {
 
 268               if (relations[i].members.indexOf(node) !== -1) return true;
 
 275         map._objectLayer.addData(xml);
 
 276         map._objectLayer.addTo(map);
 
 278         if (callback) callback(map._objectLayer.getBounds());
 
 283   removeObject: function () {
 
 285     if (this._objectLoader) this._objectLoader.abort();
 
 286     if (this._objectLayer) this.removeLayer(this._objectLayer);
 
 289   getState: function () {
 
 291       center: this.getCenter().wrap(),
 
 292       zoom: this.getZoom(),
 
 293       layers: this.getLayersCode()
 
 297   setState: function (state, options) {
 
 298     if (state.center) this.setView(state.center, state.zoom, options);
 
 299     if (state.layers) this.updateLayers(state.layers);
 
 302   setSidebarOverlaid: function (overlaid) {
 
 303     if (overlaid && !$("#content").hasClass("overlay-sidebar")) {
 
 304       $("#content").addClass("overlay-sidebar");
 
 305       this.invalidateSize({ pan: false })
 
 306         .panBy([-350, 0], { animate: false });
 
 307     } else if (!overlaid && $("#content").hasClass("overlay-sidebar")) {
 
 308       this.panBy([350, 0], { animate: false });
 
 309       $("#content").removeClass("overlay-sidebar");
 
 310       this.invalidateSize({ pan: false });
 
 316 L.Icon.Default.imagePath = "/images/";
 
 318 L.Icon.Default.imageUrls = {
 
 319   "/images/marker-icon.png": OSM.MARKER_ICON,
 
 320   "/images/marker-icon-2x.png": OSM.MARKER_ICON_2X,
 
 321   "/images/marker-shadow.png": OSM.MARKER_SHADOW
 
 324 L.extend(L.Icon.Default.prototype, {
 
 325   _oldGetIconUrl: L.Icon.Default.prototype._getIconUrl,
 
 327   _getIconUrl: function (name) {
 
 328     var url = this._oldGetIconUrl(name);
 
 329     return L.Icon.Default.imageUrls[url];
 
 333 OSM.getUserIcon = function (url) {
 
 335     iconUrl: url || OSM.MARKER_RED,
 
 337     iconAnchor: [12, 41],
 
 338     popupAnchor: [1, -34],
 
 339     shadowUrl: OSM.MARKER_SHADOW,