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 thunderforest = I18n.t("javascripts.map.thunderforest", { thunderforest_url: "https://www.thunderforest.com/" });
 
  22     var memomaps = I18n.t("javascripts.map.opnvkarte", { memomaps_url: "https://memomaps.de/" });
 
  23     var hotosm = I18n.t("javascripts.map.hotosm", { hotosm_url: "https://www.hotosm.org/", osmfrance_url: "https://openstreetmap.fr/" });
 
  27     this.baseLayers.push(new L.OSM.Mapnik({
 
  28       attribution: copyright + " ♥ " + donate + ". " + terms,
 
  31       name: I18n.t("javascripts.map.base.standard")
 
  34     if (OSM.THUNDERFOREST_KEY) {
 
  35       this.baseLayers.push(new L.OSM.CycleMap({
 
  36         attribution: copyright + ". " + thunderforest + ". " + terms,
 
  37         apikey: OSM.THUNDERFOREST_KEY,
 
  40         name: I18n.t("javascripts.map.base.cycle_map")
 
  43       this.baseLayers.push(new L.OSM.TransportMap({
 
  44         attribution: copyright + ". " + thunderforest + ". " + terms,
 
  45         apikey: OSM.THUNDERFOREST_KEY,
 
  47         keyid: "transportmap",
 
  48         name: I18n.t("javascripts.map.base.transport_map")
 
  52     this.baseLayers.push(new L.OSM.OPNVKarte({
 
  53       attribution: copyright + ". " + memomaps + ". " + terms,
 
  56       name: I18n.t("javascripts.map.base.opnvkarte")
 
  59     this.baseLayers.push(new L.OSM.HOT({
 
  60       attribution: copyright + ". " + hotosm + ". " + terms,
 
  63       name: I18n.t("javascripts.map.base.hot")
 
  66     this.noteLayer = new L.FeatureGroup();
 
  67     this.noteLayer.options = { code: "N" };
 
  69     this.dataLayer = new L.OSM.DataLayer(null);
 
  70     this.dataLayer.options.code = "D";
 
  72     this.gpsLayer = new L.OSM.GPS({
 
  75       name: I18n.t("javascripts.map.base.gps")
 
  78     this.on("layeradd", function (event) {
 
  79       if (this.baseLayers.indexOf(event.layer) >= 0) {
 
  80         this.setMaxZoom(event.layer.options.maxZoom);
 
  85   updateLayers: function (layerParam) {
 
  86     var layers = layerParam || "M",
 
  89     for (var i = this.baseLayers.length - 1; i >= 0; i--) {
 
  90       if (layers.indexOf(this.baseLayers[i].options.code) >= 0) {
 
  91         this.addLayer(this.baseLayers[i]);
 
  92         layersAdded = layersAdded + this.baseLayers[i].options.code;
 
  93       } else if (i === 0 && layersAdded === "") {
 
  94         this.addLayer(this.baseLayers[i]);
 
  96         this.removeLayer(this.baseLayers[i]);
 
 101   getLayersCode: function () {
 
 102     var layerConfig = "";
 
 103     this.eachLayer(function (layer) {
 
 104       if (layer.options && layer.options.code) {
 
 105         layerConfig += layer.options.code;
 
 111   getMapBaseLayerId: function () {
 
 113     this.eachLayer(function (layer) {
 
 114       if (layer.options && layer.options.keyid) baseLayerId = layer.options.keyid;
 
 119   getUrl: function (marker) {
 
 120     var precision = OSM.zoomPrecision(this.getZoom()),
 
 123     if (marker && this.hasLayer(marker)) {
 
 124       var latLng = marker.getLatLng().wrap();
 
 125       params.mlat = latLng.lat.toFixed(precision);
 
 126       params.mlon = latLng.lng.toFixed(precision);
 
 129     var url = window.location.protocol + "//" + OSM.SERVER_URL + "/",
 
 130         query = Qs.stringify(params),
 
 131         hash = OSM.formatHash(this);
 
 133     if (query) url += "?" + query;
 
 134     if (hash) url += hash;
 
 139   getShortUrl: function (marker) {
 
 140     var zoom = this.getZoom(),
 
 141         latLng = marker && this.hasLayer(marker) ? marker.getLatLng().wrap() : this.getCenter().wrap(),
 
 142         str = window.location.hostname.match(/^www\.openstreetmap\.org/i) ?
 
 143           window.location.protocol + "//osm.org/go/" :
 
 144           window.location.protocol + "//" + window.location.hostname + "/go/",
 
 145         char_array = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789_~",
 
 146         x = Math.round((latLng.lng + 180.0) * ((1 << 30) / 90.0)),
 
 147         y = Math.round((latLng.lat + 90.0) * ((1 << 30) / 45.0)),
 
 148         // JavaScript only has to keep 32 bits of bitwise operators, so this has to be
 
 149         // done in two parts. each of the parts c1/c2 has 30 bits of the total in it
 
 150         // and drops the last 4 bits of the full 64 bit Morton code.
 
 151         c1 = interlace(x >>> 17, y >>> 17), c2 = interlace((x >>> 2) & 0x7fff, (y >>> 2) & 0x7fff),
 
 155     for (i = 0; i < Math.ceil((zoom + 8) / 3.0) && i < 5; ++i) {
 
 156       digit = (c1 >> (24 - (6 * i))) & 0x3f;
 
 157       str += char_array.charAt(digit);
 
 159     for (i = 5; i < Math.ceil((zoom + 8) / 3.0); ++i) {
 
 160       digit = (c2 >> (24 - (6 * (i - 5)))) & 0x3f;
 
 161       str += char_array.charAt(digit);
 
 163     for (i = 0; i < ((zoom + 8) % 3); ++i) str += "-";
 
 165     // Called to interlace the bits in x and y, making a Morton code.
 
 166     function interlace(x, y) {
 
 167       var interlaced_x = x,
 
 169       interlaced_x = (interlaced_x | (interlaced_x << 8)) & 0x00ff00ff;
 
 170       interlaced_x = (interlaced_x | (interlaced_x << 4)) & 0x0f0f0f0f;
 
 171       interlaced_x = (interlaced_x | (interlaced_x << 2)) & 0x33333333;
 
 172       interlaced_x = (interlaced_x | (interlaced_x << 1)) & 0x55555555;
 
 173       interlaced_y = (interlaced_y | (interlaced_y << 8)) & 0x00ff00ff;
 
 174       interlaced_y = (interlaced_y | (interlaced_y << 4)) & 0x0f0f0f0f;
 
 175       interlaced_y = (interlaced_y | (interlaced_y << 2)) & 0x33333333;
 
 176       interlaced_y = (interlaced_y | (interlaced_y << 1)) & 0x55555555;
 
 177       return (interlaced_x << 1) | interlaced_y;
 
 181     var layers = this.getLayersCode().replace("M", "");
 
 184       params.layers = layers;
 
 187     if (marker && this.hasLayer(marker)) {
 
 192       params[this._object.type] = this._object.id;
 
 195     var query = Qs.stringify(params);
 
 203   getGeoUri: function (marker) {
 
 204     var precision = OSM.zoomPrecision(this.getZoom()),
 
 208     if (marker && this.hasLayer(marker)) {
 
 209       latLng = marker.getLatLng().wrap();
 
 211       latLng = this.getCenter();
 
 214     params.lat = latLng.lat.toFixed(precision);
 
 215     params.lon = latLng.lng.toFixed(precision);
 
 216     params.zoom = this.getZoom();
 
 218     return "geo:" + params.lat + "," + params.lon + "?z=" + params.zoom;
 
 221   addObject: function (object, callback) {
 
 229     var changesetStyle = {
 
 240     this._objectLoader = $.ajax({
 
 241       url: OSM.apiUrl(object),
 
 243       success: function (xml) {
 
 244         map._object = object;
 
 246         map._objectLayer = new L.OSM.DataLayer(null, {
 
 251             changeset: changesetStyle
 
 255         map._objectLayer.interestingNode = function (node, ways, relations) {
 
 256           if (object.type === "node") {
 
 258           } else if (object.type === "relation") {
 
 259             for (var i = 0; i < relations.length; i++) {
 
 260               if (relations[i].members.indexOf(node) !== -1) return true;
 
 267         map._objectLayer.addData(xml);
 
 268         map._objectLayer.addTo(map);
 
 270         if (callback) callback(map._objectLayer.getBounds());
 
 275   removeObject: function () {
 
 277     if (this._objectLoader) this._objectLoader.abort();
 
 278     if (this._objectLayer) this.removeLayer(this._objectLayer);
 
 281   getState: function () {
 
 283       center: this.getCenter().wrap(),
 
 284       zoom: this.getZoom(),
 
 285       layers: this.getLayersCode()
 
 289   setState: function (state, options) {
 
 290     if (state.center) this.setView(state.center, state.zoom, options);
 
 291     if (state.layers) this.updateLayers(state.layers);
 
 294   setSidebarOverlaid: function (overlaid) {
 
 295     if (overlaid && !$("#content").hasClass("overlay-sidebar")) {
 
 296       $("#content").addClass("overlay-sidebar");
 
 297       this.invalidateSize({ pan: false })
 
 298         .panBy([-350, 0], { animate: false });
 
 299     } else if (!overlaid && $("#content").hasClass("overlay-sidebar")) {
 
 300       this.panBy([350, 0], { animate: false });
 
 301       $("#content").removeClass("overlay-sidebar");
 
 302       this.invalidateSize({ pan: false });
 
 308 L.Icon.Default.imagePath = "/images/";
 
 310 L.Icon.Default.imageUrls = {
 
 311   "/images/marker-icon.png": OSM.MARKER_ICON,
 
 312   "/images/marker-icon-2x.png": OSM.MARKER_ICON_2X,
 
 313   "/images/marker-shadow.png": OSM.MARKER_SHADOW
 
 316 L.extend(L.Icon.Default.prototype, {
 
 317   _oldGetIconUrl: L.Icon.Default.prototype._getIconUrl,
 
 319   _getIconUrl: function (name) {
 
 320     var url = this._oldGetIconUrl(name);
 
 321     return L.Icon.Default.imageUrls[url];
 
 325 OSM.getUserIcon = function (url) {
 
 327     iconUrl: url || OSM.MARKER_RED,
 
 329     iconAnchor: [12, 41],
 
 330     popupAnchor: [1, -34],
 
 331     shadowUrl: OSM.MARKER_SHADOW,