-//= require qs/dist/qs
-
L.extend(L.LatLngBounds.prototype, {
getSize: function () {
return (this._northEast.lat - this._southWest.lat) *
link.attr("target", "_blank");
}
return link.prop("outerHTML");
- } else {
- return text;
}
+ return text;
}
},
updateLayers: function (layerParam) {
- var layers = layerParam || "M";
+ const oldBaseLayer = this.getMapBaseLayer();
+ let newBaseLayer;
- for (let i = this.baseLayers.length - 1; i >= 0; i--) {
- if (layers.indexOf(this.baseLayers[i].options.code) === -1) {
- this.removeLayer(this.baseLayers[i]);
+ for (const layer of this.baseLayers) {
+ if (!newBaseLayer || layerParam.includes(layer.options.code)) {
+ newBaseLayer = layer;
}
}
- for (let i = this.baseLayers.length - 1; i >= 0; i--) {
- if (layers.indexOf(this.baseLayers[i].options.code) >= 0 || i === 0) {
- this.addLayer(this.baseLayers[i]);
- return;
- }
+ if (newBaseLayer !== oldBaseLayer) {
+ if (oldBaseLayer) this.removeLayer(oldBaseLayer);
+ if (newBaseLayer) this.addLayer(newBaseLayer);
}
},
},
getUrl: function (marker) {
- var precision = OSM.zoomPrecision(this.getZoom()),
- params = {};
+ const params = {};
if (marker && this.hasLayer(marker)) {
- var latLng = marker.getLatLng().wrap();
- params.mlat = latLng.lat.toFixed(precision);
- params.mlon = latLng.lng.toFixed(precision);
+ [params.mlat, params.mlon] = OSM.cropLocation(marker.getLatLng(), this.getZoom());
}
var url = window.location.protocol + "//" + OSM.SERVER_URL + "/",
- query = Qs.stringify(params),
+ query = new URLSearchParams(params),
hash = OSM.formatHash(this);
if (query) url += "?" + query;
getShortUrl: function (marker) {
var zoom = this.getZoom(),
latLng = marker && this.hasLayer(marker) ? marker.getLatLng().wrap() : this.getCenter().wrap(),
- str = window.location.hostname.match(/^www\.openstreetmap\.org/i) ?
- window.location.protocol + "//osm.org/go/" :
- window.location.protocol + "//" + window.location.hostname + "/go/",
+ str = window.location.protocol + "//" + window.location.hostname.replace(/^www\.openstreetmap\.org/i, "osm.org") + "/go/",
char_array = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789_~",
x = Math.round((latLng.lng + 180.0) * ((1 << 30) / 90.0)),
y = Math.round((latLng.lat + 90.0) * ((1 << 30) / 45.0)),
// JavaScript only has to keep 32 bits of bitwise operators, so this has to be
// done in two parts. each of the parts c1/c2 has 30 bits of the total in it
// and drops the last 4 bits of the full 64 bit Morton code.
- c1 = interlace(x >>> 17, y >>> 17), c2 = interlace((x >>> 2) & 0x7fff, (y >>> 2) & 0x7fff),
+ c1 = interlace(x >>> 17, y >>> 17),
+ c2 = interlace((x >>> 2) & 0x7fff, (y >>> 2) & 0x7fff),
digit,
i;
return (interlaced_x << 1) | interlaced_y;
}
- var params = {};
+ const params = new URLSearchParams();
var layers = this.getLayersCode().replace("M", "");
if (layers) {
- params.layers = layers;
+ params.set("layers", layers);
}
if (marker && this.hasLayer(marker)) {
- params.m = "";
+ params.set("m", "");
}
if (this._object) {
- params[this._object.type] = this._object.id;
+ params.set(this._object.type, this._object.id);
}
- var query = Qs.stringify(params);
+ const query = params.toString();
if (query) {
str += "?" + query;
}
},
getGeoUri: function (marker) {
- var precision = OSM.zoomPrecision(this.getZoom()),
- latLng,
- params = {};
+ let latLng = this.getCenter();
+ const zoom = this.getZoom();
if (marker && this.hasLayer(marker)) {
- latLng = marker.getLatLng().wrap();
- } else {
- latLng = this.getCenter();
+ latLng = marker.getLatLng();
}
- params.lat = latLng.lat.toFixed(precision);
- params.lon = latLng.lng.toFixed(precision);
- params.zoom = this.getZoom();
-
- return "geo:" + params.lat + "," + params.lon + "?z=" + params.zoom;
+ return `geo:${OSM.cropLocation(latLng, zoom).join(",")}?z=${zoom}`;
},
addObject: function (object, callback) {
var map = this;
this._objectLoader = $.ajax({
url: OSM.apiUrl(object),
- dataType: "xml",
- success: function (xml) {
+ dataType: "json",
+ success: function (data) {
map._object = object;
map._objectLayer = new L.OSM.DataLayer(null, {
});
map._objectLayer.interestingNode = function (node, wayNodes, relationNodes) {
- if (object.type === "node") {
- return true;
- } else if (object.type === "relation") {
- return Boolean(relationNodes[node.id]);
- } else {
- return false;
- }
+ return object.type === "node" ||
+ (object.type === "relation" && Boolean(relationNodes[node.id]));
};
- map._objectLayer.addData(xml);
+ map._objectLayer.addData(data);
map._objectLayer.addTo(map);
if (callback) callback(map._objectLayer.getBounds());