")
.attr("class", "share-image p-3")
.appendTo($ui);
@@ -201,44 +201,34 @@ L.OSM.share = function (options) {
.attr("class", "form-check-input")
.bind("change", toggleFilter))));
- ["minlon", "minlat", "maxlon", "maxlat", "lat", "lon"].forEach(function (name) {
+ const mapnikNames = ["minlon", "minlat", "maxlon", "maxlat", "lat", "lon"];
+
+ for (const name of mapnikNames) {
$("
")
.attr("id", "mapnik_" + name)
.attr("name", name)
.attr("type", "hidden")
.appendTo($form);
- });
-
- $("
")
- .attr("id", "map_format")
- .attr("name", "format")
- .attr("value", "mapnik")
- .attr("type", "hidden")
- .appendTo($form);
-
- $("
")
- .attr("id", "map_zoom")
- .attr("name", "zoom")
- .attr("value", map.getZoom())
- .attr("type", "hidden")
- .appendTo($form);
+ }
- $("
")
- .attr("id", "map_width")
- .attr("name", "width")
- .attr("value", 0)
- .attr("type", "hidden")
- .appendTo($form);
+ const hiddenExportDefaults = {
+ format: "mapnik",
+ zoom: map.getZoom(),
+ width: 0,
+ height: 0
+ };
- $("
")
- .attr("id", "map_height")
- .attr("name", "height")
- .attr("value", 0)
- .attr("type", "hidden")
- .appendTo($form);
+ for (const name in hiddenExportDefaults) {
+ $("
")
+ .attr("id", "map_" + name)
+ .attr("name", name)
+ .attr("value", hiddenExportDefaults[name])
+ .attr("type", "hidden")
+ .appendTo($form);
+ }
- var csrf_param = $("meta[name=csrf-param]").attr("content"),
- csrf_token = $("meta[name=csrf-token]").attr("content");
+ const csrf_param = $("meta[name=csrf-param]").attr("content"),
+ csrf_token = $("meta[name=csrf-token]").attr("content");
$("
")
.attr("name", csrf_param)
@@ -246,7 +236,7 @@ L.OSM.share = function (options) {
.attr("type", "hidden")
.appendTo($form);
- var args = {
+ const args = {
layer: "
",
width: "
",
height: "
"
@@ -269,7 +259,7 @@ L.OSM.share = function (options) {
marker.on("dragend", movedMarker);
map.on("move", movedMap);
- map.on("moveend layeradd layerremove", update);
+ map.on("moveend baselayerchange overlayadd overlayremove", update);
$ui
.on("show", shown)
@@ -329,7 +319,7 @@ L.OSM.share = function (options) {
}
function escapeHTML(string) {
- var htmlEscapes = {
+ const htmlEscapes = {
"&": "&",
"<": "<",
">": ">",
@@ -343,8 +333,8 @@ L.OSM.share = function (options) {
function update() {
const layer = map.getMapBaseLayer();
- var canEmbed = Boolean(layer && layer.options.canEmbed);
- var bounds = map.getBounds();
+ const canEmbed = Boolean(layer && layer.options.canEmbed);
+ let bounds = map.getBounds();
$("#link_marker")
.prop("checked", map.hasLayer(marker));
@@ -359,14 +349,14 @@ L.OSM.share = function (options) {
$("#short_link").attr("href", map.getShortUrl(marker));
$("#long_link").attr("href", map.getUrl(marker));
- var params = {
+ const params = new URLSearchParams({
bbox: bounds.toBBoxString(),
layer: map.getMapBaseLayerId()
- };
+ });
if (map.hasLayer(marker)) {
- var latLng = marker.getLatLng().wrap();
- params.marker = latLng.lat + "," + latLng.lng;
+ const latLng = marker.getLatLng().wrap();
+ params.set("marker", latLng.lat + "," + latLng.lng);
}
$("#embed_link")
@@ -379,7 +369,7 @@ L.OSM.share = function (options) {
$("#embed_html").val(
"
" +
"
" +
escapeHTML(I18n.t("javascripts.share.view_larger_map")) + "");
@@ -396,10 +386,10 @@ L.OSM.share = function (options) {
bounds = locationFilter.getBounds();
}
- var scale = $("#mapnik_scale").val(),
- size = L.bounds(L.CRS.EPSG3857.project(bounds.getSouthWest()),
- L.CRS.EPSG3857.project(bounds.getNorthEast())).getSize(),
- maxScale = Math.floor(Math.sqrt(size.x * size.y / 0.3136));
+ let scale = $("#mapnik_scale").val();
+ const size = L.bounds(L.CRS.EPSG3857.project(bounds.getSouthWest()),
+ L.CRS.EPSG3857.project(bounds.getNorthEast())).getSize(),
+ maxScale = Math.floor(Math.sqrt(size.x * size.y / 0.3136));
$("#mapnik_minlon").val(bounds.getWest());
$("#mapnik_minlat").val(bounds.getSouth());
@@ -437,17 +427,17 @@ L.OSM.share = function (options) {
}
function getScale() {
- var bounds = map.getBounds(),
- centerLat = bounds.getCenter().lat,
- halfWorldMeters = 6378137 * Math.PI * Math.cos(centerLat * Math.PI / 180),
- meters = halfWorldMeters * (bounds.getEast() - bounds.getWest()) / 180,
- pixelsPerMeter = map.getSize().x / meters,
- metersPerPixel = 1 / (92 * 39.3701);
+ const bounds = map.getBounds(),
+ centerLat = bounds.getCenter().lat,
+ halfWorldMeters = 6378137 * Math.PI * Math.cos(centerLat * Math.PI / 180),
+ meters = halfWorldMeters * (bounds.getEast() - bounds.getWest()) / 180,
+ pixelsPerMeter = map.getSize().x / meters,
+ metersPerPixel = 1 / (92 * 39.3701);
return Math.round(1 / (pixelsPerMeter * metersPerPixel));
}
function roundScale(scale) {
- var precision = 5 * Math.pow(10, Math.floor(Math.LOG10E * Math.log(scale)) - 2);
+ const precision = 5 * Math.pow(10, Math.floor(Math.LOG10E * Math.log(scale)) - 2);
return precision * Math.ceil(scale / precision);
}
};