Replace uses of var with let or const as appropriate
This commit is contained in:
parent
f83424aeb2
commit
c47cb299a8
36 changed files with 427 additions and 430 deletions
|
@ -1,6 +1,6 @@
|
|||
OSM.Changeset = function (map) {
|
||||
var page = {},
|
||||
content = $("#sidebar_content");
|
||||
const page = {},
|
||||
content = $("#sidebar_content");
|
||||
|
||||
page.pushstate = page.popstate = function (path) {
|
||||
OSM.loadSidebarContent(path, function () {
|
||||
|
@ -12,7 +12,7 @@ OSM.Changeset = function (map) {
|
|||
const changesetData = content.find("[data-changeset]").data("changeset");
|
||||
changesetData.type = "changeset";
|
||||
|
||||
var hashParams = OSM.parseHash(window.location.hash);
|
||||
const hashParams = OSM.parseHash(window.location.hash);
|
||||
initialize();
|
||||
map.addObject(changesetData, function (bounds) {
|
||||
if (!hashParams.center && bounds.isValid()) {
|
||||
|
@ -24,7 +24,7 @@ OSM.Changeset = function (map) {
|
|||
};
|
||||
|
||||
function updateChangeset(method, url, include_data) {
|
||||
var data;
|
||||
let data;
|
||||
|
||||
content.find("#comment-error").prop("hidden", true);
|
||||
content.find("button[data-method][data-url]").prop("disabled", true);
|
||||
|
@ -56,8 +56,8 @@ OSM.Changeset = function (map) {
|
|||
function initialize() {
|
||||
content.find("button[data-method][data-url]").on("click", function (e) {
|
||||
e.preventDefault();
|
||||
var data = $(e.target).data();
|
||||
var include_data = e.target.name === "comment";
|
||||
const data = $(e.target).data();
|
||||
const include_data = e.target.name === "comment";
|
||||
updateChangeset(data.method, data.url, include_data);
|
||||
});
|
||||
|
||||
|
|
|
@ -69,7 +69,7 @@ OSM.initializeContextMenu = function (map) {
|
|||
return $(input).val();
|
||||
}
|
||||
|
||||
var updateMenu = function updateMenu() {
|
||||
const updateMenu = function updateMenu() {
|
||||
map.contextmenu.setDisabled(2, map.getZoom() < 12);
|
||||
map.contextmenu.setDisabled(4, map.getZoom() < 14);
|
||||
};
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
OSM.DirectionsEndpoint = function Endpoint(map, input, iconUrl, dragCallback, changeCallback) {
|
||||
var endpoint = {};
|
||||
const endpoint = {};
|
||||
|
||||
endpoint.marker = L.marker([0, 0], {
|
||||
icon: L.icon({
|
||||
|
@ -52,7 +52,7 @@ OSM.DirectionsEndpoint = function Endpoint(map, input, iconUrl, dragCallback, ch
|
|||
|
||||
function inputChangeListener(e) {
|
||||
// make text the same in both text boxes
|
||||
var value = e.target.value;
|
||||
const value = e.target.value;
|
||||
endpoint.setValue(value);
|
||||
}
|
||||
|
||||
|
@ -61,8 +61,8 @@ OSM.DirectionsEndpoint = function Endpoint(map, input, iconUrl, dragCallback, ch
|
|||
delete endpoint.geocodeRequest;
|
||||
input.removeClass("is-invalid");
|
||||
|
||||
var coordinatesMatch = value.match(/^\s*([+-]?\d+(?:\.\d*)?)(?:\s+|\s*[/,]\s*)([+-]?\d+(?:\.\d*)?)\s*$/);
|
||||
var latlng = coordinatesMatch && L.latLng(coordinatesMatch[1], coordinatesMatch[2]);
|
||||
const coordinatesMatch = value.match(/^\s*([+-]?\d+(?:\.\d*)?)(?:\s+|\s*[/,]\s*)([+-]?\d+(?:\.\d*)?)\s*$/);
|
||||
const latlng = coordinatesMatch && L.latLng(coordinatesMatch[1], coordinatesMatch[2]);
|
||||
|
||||
if (latlng && endpoint.cachedReverseGeocode && endpoint.cachedReverseGeocode.latlng.equals(latlng)) {
|
||||
setLatLng(latlng);
|
||||
|
@ -92,8 +92,8 @@ OSM.DirectionsEndpoint = function Endpoint(map, input, iconUrl, dragCallback, ch
|
|||
};
|
||||
|
||||
endpoint.swapCachedReverseGeocodes = function (otherEndpoint) {
|
||||
var g0 = endpoint.cachedReverseGeocode;
|
||||
var g1 = otherEndpoint.cachedReverseGeocode;
|
||||
const g0 = endpoint.cachedReverseGeocode;
|
||||
const g1 = otherEndpoint.cachedReverseGeocode;
|
||||
delete endpoint.cachedReverseGeocode;
|
||||
delete otherEndpoint.cachedReverseGeocode;
|
||||
if (g0) otherEndpoint.cachedReverseGeocode = g0;
|
||||
|
|
|
@ -4,59 +4,59 @@
|
|||
|
||||
OSM.Directions = function (map) {
|
||||
let controller = null; // the AbortController for the current route request if a route request is in progress
|
||||
var chosenEngine;
|
||||
let chosenEngine;
|
||||
|
||||
var popup = L.popup({ autoPanPadding: [100, 100] });
|
||||
const popup = L.popup({ autoPanPadding: [100, 100] });
|
||||
|
||||
var polyline = L.polyline([], {
|
||||
const polyline = L.polyline([], {
|
||||
color: "#03f",
|
||||
opacity: 0.3,
|
||||
weight: 10
|
||||
});
|
||||
|
||||
var highlight = L.polyline([], {
|
||||
const highlight = L.polyline([], {
|
||||
color: "#ff0",
|
||||
opacity: 0.5,
|
||||
weight: 12
|
||||
});
|
||||
|
||||
var endpointDragCallback = function (dragging) {
|
||||
const endpointDragCallback = function (dragging) {
|
||||
if (!map.hasLayer(polyline)) return;
|
||||
if (dragging && !chosenEngine.draggable) return;
|
||||
if (dragging && controller) return;
|
||||
|
||||
getRoute(false, !dragging);
|
||||
};
|
||||
var endpointChangeCallback = function () {
|
||||
const endpointChangeCallback = function () {
|
||||
getRoute(true, true);
|
||||
};
|
||||
|
||||
var endpoints = [
|
||||
const endpoints = [
|
||||
OSM.DirectionsEndpoint(map, $("input[name='route_from']"), OSM.MARKER_GREEN, endpointDragCallback, endpointChangeCallback),
|
||||
OSM.DirectionsEndpoint(map, $("input[name='route_to']"), OSM.MARKER_RED, endpointDragCallback, endpointChangeCallback)
|
||||
];
|
||||
|
||||
var expiry = new Date();
|
||||
const expiry = new Date();
|
||||
expiry.setYear(expiry.getFullYear() + 10);
|
||||
|
||||
var engines = OSM.Directions.engines;
|
||||
const engines = OSM.Directions.engines;
|
||||
|
||||
engines.sort(function (a, b) {
|
||||
var localised_a = I18n.t("javascripts.directions.engines." + a.id),
|
||||
localised_b = I18n.t("javascripts.directions.engines." + b.id);
|
||||
const localised_a = I18n.t("javascripts.directions.engines." + a.id),
|
||||
localised_b = I18n.t("javascripts.directions.engines." + b.id);
|
||||
return localised_a.localeCompare(localised_b);
|
||||
});
|
||||
|
||||
var select = $("select.routing_engines");
|
||||
const select = $("select.routing_engines");
|
||||
|
||||
engines.forEach(function (engine, i) {
|
||||
select.append("<option value='" + i + "'>" + I18n.t("javascripts.directions.engines." + engine.id) + "</option>");
|
||||
});
|
||||
|
||||
$(".directions_form .reverse_directions").on("click", function () {
|
||||
var coordFrom = endpoints[0].latlng,
|
||||
coordTo = endpoints[1].latlng,
|
||||
routeFrom = "",
|
||||
const coordFrom = endpoints[0].latlng,
|
||||
coordTo = endpoints[1].latlng;
|
||||
let routeFrom = "",
|
||||
routeTo = "";
|
||||
if (coordFrom) {
|
||||
routeFrom = coordFrom.lat + "," + coordFrom.lng;
|
||||
|
@ -90,8 +90,8 @@ OSM.Directions = function (map) {
|
|||
}
|
||||
|
||||
function formatTime(s) {
|
||||
var m = Math.round(s / 60);
|
||||
var h = Math.floor(m / 60);
|
||||
let m = Math.round(s / 60);
|
||||
const h = Math.floor(m / 60);
|
||||
m -= h * 60;
|
||||
return h + ":" + (m < 10 ? "0" : "") + m;
|
||||
}
|
||||
|
@ -136,7 +136,7 @@ OSM.Directions = function (map) {
|
|||
map.fitBounds(polyline.getBounds().pad(0.05));
|
||||
}
|
||||
|
||||
var distanceText = $("<p>").append(
|
||||
const distanceText = $("<p>").append(
|
||||
I18n.t("javascripts.directions.distance") + ": " + formatDistance(route.distance) + ". " +
|
||||
I18n.t("javascripts.directions.time") + ": " + formatTime(route.time) + ".");
|
||||
if (typeof route.ascend !== "undefined" && typeof route.descend !== "undefined") {
|
||||
|
@ -146,9 +146,9 @@ OSM.Directions = function (map) {
|
|||
I18n.t("javascripts.directions.descend") + ": " + formatHeight(route.descend) + ".");
|
||||
}
|
||||
|
||||
var turnByTurnTable = $("<table class='table table-hover table-sm mb-3'>")
|
||||
const turnByTurnTable = $("<table class='table table-hover table-sm mb-3'>")
|
||||
.append($("<tbody>"));
|
||||
var directionsCloseButton = $("<button type='button' class='btn-close'>")
|
||||
const directionsCloseButton = $("<button type='button' class='btn-close'>")
|
||||
.attr("aria-label", I18n.t("javascripts.close"));
|
||||
|
||||
$("#sidebar_content")
|
||||
|
@ -166,7 +166,7 @@ OSM.Directions = function (map) {
|
|||
route.steps.forEach(function (step) {
|
||||
const [ll, direction, instruction, dist, lineseg] = step;
|
||||
|
||||
var row = $("<tr class='turn'/>");
|
||||
const row = $("<tr class='turn'/>");
|
||||
row.append("<td class='border-0'><div class='direction i" + direction + "'/></td> ");
|
||||
row.append("<td>" + instruction);
|
||||
row.append("<td class='distance text-body-secondary text-end'>" + getDistText(dist));
|
||||
|
@ -218,7 +218,7 @@ OSM.Directions = function (map) {
|
|||
}
|
||||
}
|
||||
|
||||
var chosenEngineIndex = findEngine("fossgis_osrm_car");
|
||||
let chosenEngineIndex = findEngine("fossgis_osrm_car");
|
||||
if (Cookies.get("_osm_directions_engine")) {
|
||||
chosenEngineIndex = findEngine(Cookies.get("_osm_directions_engine"));
|
||||
}
|
||||
|
@ -236,17 +236,17 @@ OSM.Directions = function (map) {
|
|||
});
|
||||
|
||||
$(".routing_marker_column img").on("dragstart", function (e) {
|
||||
var dt = e.originalEvent.dataTransfer;
|
||||
const dt = e.originalEvent.dataTransfer;
|
||||
dt.effectAllowed = "move";
|
||||
var dragData = { type: $(this).data("type") };
|
||||
const dragData = { type: $(this).data("type") };
|
||||
dt.setData("text", JSON.stringify(dragData));
|
||||
if (dt.setDragImage) {
|
||||
var img = $("<img>").attr("src", $(e.originalEvent.target).attr("src"));
|
||||
const img = $("<img>").attr("src", $(e.originalEvent.target).attr("src"));
|
||||
dt.setDragImage(img.get(0), 12, 21);
|
||||
}
|
||||
});
|
||||
|
||||
var page = {};
|
||||
const page = {};
|
||||
|
||||
page.pushstate = page.popstate = function () {
|
||||
$(".search_form").hide();
|
||||
|
@ -258,12 +258,12 @@ OSM.Directions = function (map) {
|
|||
|
||||
$("#map").on("drop", function (e) {
|
||||
e.preventDefault();
|
||||
var oe = e.originalEvent;
|
||||
var dragData = JSON.parse(oe.dataTransfer.getData("text"));
|
||||
var type = dragData.type;
|
||||
var pt = L.DomEvent.getMousePosition(oe, map.getContainer()); // co-ordinates of the mouse pointer at present
|
||||
const oe = e.originalEvent;
|
||||
const dragData = JSON.parse(oe.dataTransfer.getData("text"));
|
||||
const type = dragData.type;
|
||||
const pt = L.DomEvent.getMousePosition(oe, map.getContainer()); // co-ordinates of the mouse pointer at present
|
||||
pt.y += 20;
|
||||
var ll = map.containerPointToLatLng(pt);
|
||||
const ll = map.containerPointToLatLng(pt);
|
||||
const llWithPrecision = OSM.cropLocation(ll, map.getZoom());
|
||||
endpoints[type === "from" ? 0 : 1].setValue(llWithPrecision.join(", "));
|
||||
});
|
||||
|
@ -275,7 +275,7 @@ OSM.Directions = function (map) {
|
|||
route = (params.get("route") || "").split(";");
|
||||
|
||||
if (params.has("engine")) {
|
||||
var engineIndex = findEngine(params.get("engine"));
|
||||
const engineIndex = findEngine(params.get("engine"));
|
||||
|
||||
if (engineIndex >= 0) {
|
||||
setEngine(engineIndex);
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
OSM.Export = function (map) {
|
||||
var page = {};
|
||||
const page = {};
|
||||
|
||||
var locationFilter = new L.LocationFilter({
|
||||
const locationFilter = new L.LocationFilter({
|
||||
enableButton: false,
|
||||
adjustButton: false
|
||||
}).on("change", update);
|
||||
|
@ -13,7 +13,7 @@ OSM.Export = function (map) {
|
|||
}
|
||||
|
||||
function boundsChanged() {
|
||||
var bounds = getBounds();
|
||||
const bounds = getBounds();
|
||||
map.fitBounds(bounds);
|
||||
locationFilter.setBounds(bounds);
|
||||
locationFilter.enable();
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
//= require jquery-simulate/jquery.simulate
|
||||
|
||||
OSM.History = function (map) {
|
||||
var page = {};
|
||||
const page = {};
|
||||
|
||||
$("#sidebar_content")
|
||||
.on("click", ".changeset_more a", loadMore)
|
||||
|
@ -12,7 +12,7 @@ OSM.History = function (map) {
|
|||
unHighlightChangeset($(this).data("changeset").id);
|
||||
});
|
||||
|
||||
var group = L.featureGroup()
|
||||
const group = L.featureGroup()
|
||||
.on("mouseover", function (e) {
|
||||
highlightChangeset(e.layer.id);
|
||||
})
|
||||
|
@ -28,13 +28,13 @@ OSM.History = function (map) {
|
|||
};
|
||||
|
||||
function highlightChangeset(id) {
|
||||
var layer = group.getLayer(id);
|
||||
const layer = group.getLayer(id);
|
||||
if (layer) layer.setStyle({ fillOpacity: 0.3, color: "#FF6600", weight: 3 });
|
||||
$("#changeset_" + id).addClass("selected");
|
||||
}
|
||||
|
||||
function unHighlightChangeset(id) {
|
||||
var layer = group.getLayer(id);
|
||||
const layer = group.getLayer(id);
|
||||
if (layer) layer.setStyle({ fillOpacity: 0, color: "#FF9500", weight: 2 });
|
||||
$("#changeset_" + id).removeClass("selected");
|
||||
}
|
||||
|
@ -49,8 +49,8 @@ OSM.History = function (map) {
|
|||
|
||||
function displayMoreChangesets(html) {
|
||||
$("#sidebar_content .changeset_more").replaceWith(html);
|
||||
var oldList = $("#sidebar_content .changesets ol").first();
|
||||
var newList = oldList.next("ol");
|
||||
const oldList = $("#sidebar_content .changesets ol").first();
|
||||
const newList = oldList.next("ol");
|
||||
newList.children().appendTo(oldList);
|
||||
newList.remove();
|
||||
}
|
||||
|
@ -60,8 +60,8 @@ OSM.History = function (map) {
|
|||
|
||||
if (window.location.pathname === "/history") {
|
||||
data.set("bbox", map.getBounds().wrap().toBBoxString());
|
||||
var feedLink = $("link[type=\"application/atom+xml\"]"),
|
||||
feedHref = feedLink.attr("href").split("?")[0];
|
||||
const feedLink = $("link[type=\"application/atom+xml\"]"),
|
||||
feedHref = feedLink.attr("href").split("?")[0];
|
||||
feedLink.attr("href", feedHref + "?" + data);
|
||||
}
|
||||
|
||||
|
@ -79,7 +79,7 @@ OSM.History = function (map) {
|
|||
e.preventDefault();
|
||||
e.stopPropagation();
|
||||
|
||||
var div = $(this).parents(".changeset_more");
|
||||
const div = $(this).parents(".changeset_more");
|
||||
|
||||
$(this).hide();
|
||||
div.find(".loader").show();
|
||||
|
@ -90,17 +90,17 @@ OSM.History = function (map) {
|
|||
});
|
||||
}
|
||||
|
||||
var changesets = [];
|
||||
let changesets = [];
|
||||
|
||||
function updateBounds() {
|
||||
group.clearLayers();
|
||||
|
||||
for (const changeset of changesets) {
|
||||
var bottomLeft = map.project(L.latLng(changeset.bbox.minlat, changeset.bbox.minlon)),
|
||||
topRight = map.project(L.latLng(changeset.bbox.maxlat, changeset.bbox.maxlon)),
|
||||
width = topRight.x - bottomLeft.x,
|
||||
height = bottomLeft.y - topRight.y,
|
||||
minSize = 20; // Min width/height of changeset in pixels
|
||||
const bottomLeft = map.project(L.latLng(changeset.bbox.minlat, changeset.bbox.minlon)),
|
||||
topRight = map.project(L.latLng(changeset.bbox.maxlat, changeset.bbox.maxlon)),
|
||||
width = topRight.x - bottomLeft.x,
|
||||
height = bottomLeft.y - topRight.y,
|
||||
minSize = 20; // Min width/height of changeset in pixels
|
||||
|
||||
if (width < minSize) {
|
||||
bottomLeft.x -= ((minSize - width) / 2);
|
||||
|
@ -138,7 +138,7 @@ OSM.History = function (map) {
|
|||
updateBounds();
|
||||
|
||||
if (window.location.pathname !== "/history") {
|
||||
var bounds = group.getBounds();
|
||||
const bounds = group.getBounds();
|
||||
if (bounds.isValid()) map.fitBounds(bounds);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -40,7 +40,7 @@ OSM.initializeDataLayer = function (map) {
|
|||
});
|
||||
|
||||
function updateData() {
|
||||
var bounds = map.getBounds();
|
||||
const bounds = map.getBounds();
|
||||
if (!loadedBounds || !loadedBounds.contains(bounds)) {
|
||||
getData();
|
||||
}
|
||||
|
@ -78,8 +78,8 @@ OSM.initializeDataLayer = function (map) {
|
|||
}
|
||||
|
||||
function getData() {
|
||||
var bounds = map.getBounds();
|
||||
var url = "/api/" + OSM.API_VERSION + "/map.json?bbox=" + bounds.toBBoxString();
|
||||
const bounds = map.getBounds();
|
||||
const url = "/api/" + OSM.API_VERSION + "/map.json?bbox=" + bounds.toBBoxString();
|
||||
|
||||
/*
|
||||
* Modern browsers are quite happy showing far more than 100 features in
|
||||
|
@ -102,7 +102,7 @@ OSM.initializeDataLayer = function (map) {
|
|||
.then(function (data) {
|
||||
dataLayer.clearLayers();
|
||||
|
||||
var features = dataLayer.buildFeatures(data);
|
||||
const features = dataLayer.buildFeatures(data);
|
||||
|
||||
function addFeatures() {
|
||||
$("#browse_status").empty();
|
||||
|
|
|
@ -3,7 +3,7 @@ OSM.initializeNotesLayer = function (map) {
|
|||
const noteLayer = map.noteLayer;
|
||||
let notes = {};
|
||||
|
||||
var noteIcons = {
|
||||
const noteIcons = {
|
||||
"new": L.icon({
|
||||
iconUrl: OSM.NEW_NOTE_MARKER,
|
||||
iconSize: [25, 40],
|
||||
|
@ -39,7 +39,7 @@ OSM.initializeNotesLayer = function (map) {
|
|||
});
|
||||
|
||||
function updateMarker(old_marker, feature) {
|
||||
var marker = old_marker;
|
||||
let marker = old_marker;
|
||||
if (marker) {
|
||||
marker.setIcon(noteIcons[feature.properties.status]);
|
||||
} else {
|
||||
|
@ -67,11 +67,11 @@ OSM.initializeNotesLayer = function (map) {
|
|||
};
|
||||
|
||||
function loadNotes() {
|
||||
var bounds = map.getBounds();
|
||||
var size = bounds.getSize();
|
||||
const bounds = map.getBounds();
|
||||
const size = bounds.getSize();
|
||||
|
||||
if (size <= OSM.MAX_NOTE_REQUEST_AREA) {
|
||||
var url = "/api/" + OSM.API_VERSION + "/notes.json?bbox=" + bounds.toBBoxString();
|
||||
const url = "/api/" + OSM.API_VERSION + "/notes.json?bbox=" + bounds.toBBoxString();
|
||||
|
||||
if (noteLoader) noteLoader.abort();
|
||||
|
||||
|
@ -84,15 +84,15 @@ OSM.initializeNotesLayer = function (map) {
|
|||
}
|
||||
|
||||
function success(json) {
|
||||
var oldNotes = notes;
|
||||
const oldNotes = notes;
|
||||
notes = {};
|
||||
for (const feature of json.features) {
|
||||
var marker = oldNotes[feature.properties.id];
|
||||
const marker = oldNotes[feature.properties.id];
|
||||
delete oldNotes[feature.properties.id];
|
||||
notes[feature.properties.id] = updateMarker(marker, feature);
|
||||
}
|
||||
|
||||
for (var id in oldNotes) {
|
||||
for (const id in oldNotes) {
|
||||
noteLayer.removeLayer(oldNotes[id]);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,12 +1,12 @@
|
|||
OSM.NewNote = function (map) {
|
||||
var noteLayer = map.noteLayer,
|
||||
content = $("#sidebar_content"),
|
||||
page = {},
|
||||
addNoteButton = $(".control-note .control-button"),
|
||||
newNoteMarker,
|
||||
const noteLayer = map.noteLayer,
|
||||
content = $("#sidebar_content"),
|
||||
page = {},
|
||||
addNoteButton = $(".control-note .control-button");
|
||||
let newNoteMarker,
|
||||
halo;
|
||||
|
||||
var noteIcons = {
|
||||
const noteIcons = {
|
||||
"new": L.icon({
|
||||
iconUrl: OSM.NEW_NOTE_MARKER,
|
||||
iconSize: [25, 40],
|
||||
|
@ -48,7 +48,7 @@ OSM.NewNote = function (map) {
|
|||
}
|
||||
|
||||
function addCreatedNoteMarker(feature) {
|
||||
var marker = L.marker(feature.geometry.coordinates.reverse(), {
|
||||
const marker = L.marker(feature.geometry.coordinates.reverse(), {
|
||||
icon: noteIcons[feature.properties.status],
|
||||
opacity: 0.9,
|
||||
interactive: true
|
||||
|
@ -132,7 +132,7 @@ OSM.NewNote = function (map) {
|
|||
map.addLayer(noteLayer);
|
||||
|
||||
const params = new URLSearchParams(path.substring(path.indexOf("?")));
|
||||
var markerLatlng;
|
||||
let markerLatlng;
|
||||
|
||||
if (params.has("lat") && params.has("lon")) {
|
||||
markerLatlng = L.latLng(params.get("lat"), params.get("lon"));
|
||||
|
@ -161,7 +161,7 @@ OSM.NewNote = function (map) {
|
|||
|
||||
createNote(location, text, (feature) => {
|
||||
if (typeof OSM.user === "undefined") {
|
||||
var anonymousNotesCount = Number(Cookies.get("_osm_anonymous_notes_count")) || 0;
|
||||
const anonymousNotesCount = Number(Cookies.get("_osm_anonymous_notes_count")) || 0;
|
||||
Cookies.set("_osm_anonymous_notes_count", anonymousNotesCount + 1, { secure: true, expires: 30, path: "/", samesite: "lax" });
|
||||
}
|
||||
content.find("textarea").val("");
|
||||
|
|
|
@ -1,8 +1,8 @@
|
|||
OSM.Note = function (map) {
|
||||
var content = $("#sidebar_content"),
|
||||
page = {};
|
||||
const content = $("#sidebar_content"),
|
||||
page = {};
|
||||
|
||||
var noteIcons = {
|
||||
const noteIcons = {
|
||||
"new": L.icon({
|
||||
iconUrl: OSM.NEW_NOTE_MARKER,
|
||||
iconSize: [25, 40],
|
||||
|
@ -22,9 +22,9 @@ OSM.Note = function (map) {
|
|||
|
||||
page.pushstate = page.popstate = function (path, id) {
|
||||
OSM.loadSidebarContent(path, function () {
|
||||
var data = $(".details").data();
|
||||
const data = $(".details").data();
|
||||
if (!data) return;
|
||||
var latLng = L.latLng(data.coordinates.split(","));
|
||||
const latLng = L.latLng(data.coordinates.split(","));
|
||||
initialize(path, id, map.getBounds().contains(latLng));
|
||||
});
|
||||
};
|
||||
|
@ -36,9 +36,9 @@ OSM.Note = function (map) {
|
|||
function initialize(path, id, skipMoveToNote) {
|
||||
content.find("button[name]").on("click", function (e) {
|
||||
e.preventDefault();
|
||||
var data = $(e.target).data();
|
||||
var name = $(e.target).attr("name");
|
||||
var ajaxSettings = {
|
||||
const data = $(e.target).data();
|
||||
const name = $(e.target).attr("name");
|
||||
const ajaxSettings = {
|
||||
url: data.url,
|
||||
type: data.method,
|
||||
oauth: true,
|
||||
|
@ -70,10 +70,10 @@ OSM.Note = function (map) {
|
|||
|
||||
content.find("textarea").val("").trigger("input");
|
||||
|
||||
var data = $(".details").data();
|
||||
const data = $(".details").data();
|
||||
|
||||
if (data) {
|
||||
var hashParams = OSM.parseHash(window.location.hash);
|
||||
const hashParams = OSM.parseHash(window.location.hash);
|
||||
map.addObject({
|
||||
type: "note",
|
||||
id: parseInt(id, 10),
|
||||
|
@ -81,7 +81,7 @@ OSM.Note = function (map) {
|
|||
icon: noteIcons[data.status]
|
||||
}, function () {
|
||||
if (!hashParams.center && !skipMoveToNote) {
|
||||
var latLng = L.latLng(data.coordinates.split(","));
|
||||
const latLng = L.latLng(data.coordinates.split(","));
|
||||
OSM.router.withoutMoveListener(function () {
|
||||
map.setView(latLng, 15, { reset: true });
|
||||
});
|
||||
|
@ -91,8 +91,8 @@ OSM.Note = function (map) {
|
|||
}
|
||||
|
||||
function updateButtons() {
|
||||
var resolveButton = content.find("button[name='close']");
|
||||
var commentButton = content.find("button[name='comment']");
|
||||
const resolveButton = content.find("button[name='close']");
|
||||
const commentButton = content.find("button[name='comment']");
|
||||
|
||||
content.find("button[name]").prop("disabled", false);
|
||||
if (content.find("textarea").val() === "") {
|
||||
|
|
|
@ -1,11 +1,11 @@
|
|||
OSM.Query = function (map) {
|
||||
var url = OSM.OVERPASS_URL,
|
||||
credentials = OSM.OVERPASS_CREDENTIALS,
|
||||
queryButton = $(".control-query .control-button"),
|
||||
uninterestingTags = ["source", "source_ref", "source:ref", "history", "attribution", "created_by", "tiger:county", "tiger:tlid", "tiger:upload_uuid", "KSJ2:curve_id", "KSJ2:lat", "KSJ2:lon", "KSJ2:coordinate", "KSJ2:filename", "note:ja"],
|
||||
marker;
|
||||
const url = OSM.OVERPASS_URL,
|
||||
credentials = OSM.OVERPASS_CREDENTIALS,
|
||||
queryButton = $(".control-query .control-button"),
|
||||
uninterestingTags = ["source", "source_ref", "source:ref", "history", "attribution", "created_by", "tiger:county", "tiger:tlid", "tiger:upload_uuid", "KSJ2:curve_id", "KSJ2:lat", "KSJ2:lon", "KSJ2:coordinate", "KSJ2:filename", "note:ja"];
|
||||
let marker;
|
||||
|
||||
var featureStyle = {
|
||||
const featureStyle = {
|
||||
color: "#FF6200",
|
||||
weight: 4,
|
||||
opacity: 1,
|
||||
|
@ -37,13 +37,13 @@ OSM.Query = function (map) {
|
|||
});
|
||||
|
||||
function showResultGeometry() {
|
||||
var geometry = $(this).data("geometry");
|
||||
const geometry = $(this).data("geometry");
|
||||
if (geometry) map.addLayer(geometry);
|
||||
$(this).addClass("selected");
|
||||
}
|
||||
|
||||
function hideResultGeometry() {
|
||||
var geometry = $(this).data("geometry");
|
||||
const geometry = $(this).data("geometry");
|
||||
if (geometry) map.removeLayer(geometry);
|
||||
$(this).removeClass("selected");
|
||||
}
|
||||
|
@ -54,7 +54,7 @@ OSM.Query = function (map) {
|
|||
|
||||
function interestingFeature(feature) {
|
||||
if (feature.tags) {
|
||||
for (var key in feature.tags) {
|
||||
for (const key in feature.tags) {
|
||||
if (uninterestingTags.indexOf(key) < 0) {
|
||||
return true;
|
||||
}
|
||||
|
@ -65,19 +65,18 @@ OSM.Query = function (map) {
|
|||
}
|
||||
|
||||
function featurePrefix(feature) {
|
||||
var tags = feature.tags;
|
||||
var prefix = "";
|
||||
const tags = feature.tags;
|
||||
let prefix = "";
|
||||
|
||||
if (tags.boundary === "administrative" && tags.admin_level) {
|
||||
prefix = I18n.t("geocoder.search_osm_nominatim.admin_levels.level" + tags.admin_level, {
|
||||
defaultValue: I18n.t("geocoder.search_osm_nominatim.prefix.boundary.administrative")
|
||||
});
|
||||
} else {
|
||||
var prefixes = I18n.t("geocoder.search_osm_nominatim.prefix");
|
||||
var key, value;
|
||||
const prefixes = I18n.t("geocoder.search_osm_nominatim.prefix");
|
||||
|
||||
for (key in tags) {
|
||||
value = tags[key];
|
||||
for (const key in tags) {
|
||||
const value = tags[key];
|
||||
|
||||
if (prefixes[key]) {
|
||||
if (prefixes[key][value]) {
|
||||
|
@ -86,12 +85,12 @@ OSM.Query = function (map) {
|
|||
}
|
||||
}
|
||||
|
||||
for (key in tags) {
|
||||
value = tags[key];
|
||||
for (const key in tags) {
|
||||
const value = tags[key];
|
||||
|
||||
if (prefixes[key]) {
|
||||
var first = value.slice(0, 1).toUpperCase(),
|
||||
rest = value.slice(1).replace(/_/g, " ");
|
||||
const first = value.slice(0, 1).toUpperCase(),
|
||||
rest = value.slice(1).replace(/_/g, " ");
|
||||
|
||||
return first + rest;
|
||||
}
|
||||
|
@ -106,8 +105,8 @@ OSM.Query = function (map) {
|
|||
}
|
||||
|
||||
function featureName(feature) {
|
||||
var tags = feature.tags,
|
||||
locales = OSM.preferred_languages;
|
||||
const tags = feature.tags,
|
||||
locales = OSM.preferred_languages;
|
||||
|
||||
for (const locale of locales) {
|
||||
if (tags["name:" + locale]) {
|
||||
|
@ -128,7 +127,7 @@ OSM.Query = function (map) {
|
|||
}
|
||||
|
||||
function featureGeometry(feature) {
|
||||
var geometry;
|
||||
let geometry;
|
||||
|
||||
if (feature.type === "node" && feature.lat && feature.lon) {
|
||||
geometry = L.circleMarker([feature.lat, feature.lon], featureStyle);
|
||||
|
@ -148,7 +147,7 @@ OSM.Query = function (map) {
|
|||
}
|
||||
|
||||
function runQuery(latlng, radius, query, $section, merge, compare) {
|
||||
var $ul = $section.find("ul");
|
||||
const $ul = $section.find("ul");
|
||||
|
||||
$ul.empty();
|
||||
$section.show();
|
||||
|
@ -168,13 +167,13 @@ OSM.Query = function (map) {
|
|||
})
|
||||
.then(response => response.json())
|
||||
.then(function (results) {
|
||||
var elements;
|
||||
let elements;
|
||||
|
||||
$section.find(".loader").hide();
|
||||
|
||||
if (merge) {
|
||||
elements = results.elements.reduce(function (hash, element) {
|
||||
var key = element.type + element.id;
|
||||
const key = element.type + element.id;
|
||||
if ("geometry" in element) {
|
||||
delete element.bounds;
|
||||
}
|
||||
|
@ -196,7 +195,7 @@ OSM.Query = function (map) {
|
|||
for (const element of elements) {
|
||||
if (!interestingFeature(element)) continue;
|
||||
|
||||
var $li = $("<li>")
|
||||
const $li = $("<li>")
|
||||
.addClass("list-group-item list-group-item-action")
|
||||
.text(featurePrefix(element) + " ")
|
||||
.appendTo($ul);
|
||||
|
@ -236,12 +235,12 @@ OSM.Query = function (map) {
|
|||
}
|
||||
|
||||
function compareSize(feature1, feature2) {
|
||||
var width1 = feature1.bounds.maxlon - feature1.bounds.minlon,
|
||||
height1 = feature1.bounds.maxlat - feature1.bounds.minlat,
|
||||
area1 = width1 * height1,
|
||||
width2 = feature2.bounds.maxlat - feature2.bounds.minlat,
|
||||
height2 = feature2.bounds.maxlat - feature2.bounds.minlat,
|
||||
area2 = width2 * height2;
|
||||
const width1 = feature1.bounds.maxlon - feature1.bounds.minlon,
|
||||
height1 = feature1.bounds.maxlat - feature1.bounds.minlat,
|
||||
area1 = width1 * height1,
|
||||
width2 = feature2.bounds.maxlat - feature2.bounds.minlat,
|
||||
height2 = feature2.bounds.maxlat - feature2.bounds.minlat,
|
||||
area2 = width2 * height2;
|
||||
|
||||
return area1 - area2;
|
||||
}
|
||||
|
@ -267,20 +266,20 @@ OSM.Query = function (map) {
|
|||
* for each object.
|
||||
*/
|
||||
function queryOverpass(lat, lng) {
|
||||
var latlng = L.latLng(lat, lng).wrap(),
|
||||
bounds = map.getBounds().wrap(),
|
||||
zoom = map.getZoom(),
|
||||
bbox = [bounds.getSouthWest(), bounds.getNorthEast()]
|
||||
.map(c => OSM.cropLocation(c, zoom))
|
||||
.join(),
|
||||
geombbox = "geom(" + bbox + ");",
|
||||
radius = 10 * Math.pow(1.5, 19 - zoom),
|
||||
around = "(around:" + radius + "," + lat + "," + lng + ")",
|
||||
nodes = "node" + around,
|
||||
ways = "way" + around,
|
||||
relations = "relation" + around,
|
||||
nearby = "(" + nodes + ";" + ways + ";);out tags " + geombbox + relations + ";out " + geombbox,
|
||||
isin = "is_in(" + lat + "," + lng + ")->.a;way(pivot.a);out tags bb;out ids " + geombbox + "relation(pivot.a);out tags bb;";
|
||||
const latlng = L.latLng(lat, lng).wrap(),
|
||||
bounds = map.getBounds().wrap(),
|
||||
zoom = map.getZoom(),
|
||||
bbox = [bounds.getSouthWest(), bounds.getNorthEast()]
|
||||
.map(c => OSM.cropLocation(c, zoom))
|
||||
.join(),
|
||||
geombbox = "geom(" + bbox + ");",
|
||||
radius = 10 * Math.pow(1.5, 19 - zoom),
|
||||
around = "(around:" + radius + "," + lat + "," + lng + ")",
|
||||
nodes = "node" + around,
|
||||
ways = "way" + around,
|
||||
relations = "relation" + around,
|
||||
nearby = "(" + nodes + ";" + ways + ";);out tags " + geombbox + relations + ";out " + geombbox,
|
||||
isin = "is_in(" + lat + "," + lng + ")->.a;way(pivot.a);out tags bb;out ids " + geombbox + "relation(pivot.a);out tags bb;";
|
||||
|
||||
$("#sidebar_content .query-intro")
|
||||
.hide();
|
||||
|
@ -315,7 +314,7 @@ OSM.Query = function (map) {
|
|||
queryButton.removeClass("active");
|
||||
}
|
||||
|
||||
var page = {};
|
||||
const page = {};
|
||||
|
||||
page.pushstate = page.popstate = function (path) {
|
||||
OSM.loadSidebarContent(path, function () {
|
||||
|
|
|
@ -9,7 +9,7 @@ OSM.Search = function (map) {
|
|||
|
||||
$(".search_form a.btn.switch_link").on("click", function (e) {
|
||||
e.preventDefault();
|
||||
var query = $(this).closest("form").find("input[name=query]").val();
|
||||
const query = $(this).closest("form").find("input[name=query]").val();
|
||||
let search = "";
|
||||
if (query) search = "?" + new URLSearchParams({ from: query });
|
||||
OSM.router.route("/directions" + search + OSM.formatHash(map));
|
||||
|
@ -18,7 +18,7 @@ OSM.Search = function (map) {
|
|||
$(".search_form").on("submit", function (e) {
|
||||
e.preventDefault();
|
||||
$("header").addClass("closed");
|
||||
var query = $(this).find("input[name=query]").val();
|
||||
const query = $(this).find("input[name=query]").val();
|
||||
let search = "/";
|
||||
if (query) search = "/search?" + new URLSearchParams({ query });
|
||||
OSM.router.route(search + OSM.formatHash(map));
|
||||
|
@ -38,16 +38,16 @@ OSM.Search = function (map) {
|
|||
.on("mouseover", "li.search_results_entry:has(a.set_position)", showSearchResult)
|
||||
.on("mouseout", "li.search_results_entry:has(a.set_position)", hideSearchResult);
|
||||
|
||||
var markers = L.layerGroup().addTo(map);
|
||||
const markers = L.layerGroup().addTo(map);
|
||||
|
||||
function clickSearchMore(e) {
|
||||
e.preventDefault();
|
||||
e.stopPropagation();
|
||||
|
||||
var div = $(this).parents(".search_more"),
|
||||
csrf_param = $("meta[name=csrf-param]").attr("content"),
|
||||
csrf_token = $("meta[name=csrf-token]").attr("content"),
|
||||
params = new URLSearchParams();
|
||||
const div = $(this).parents(".search_more"),
|
||||
csrf_param = $("meta[name=csrf-param]").attr("content"),
|
||||
csrf_token = $("meta[name=csrf-token]").attr("content"),
|
||||
params = new URLSearchParams();
|
||||
|
||||
$(this).hide();
|
||||
div.find(".loader").show();
|
||||
|
@ -63,10 +63,10 @@ OSM.Search = function (map) {
|
|||
}
|
||||
|
||||
function showSearchResult() {
|
||||
var marker = $(this).data("marker");
|
||||
let marker = $(this).data("marker");
|
||||
|
||||
if (!marker) {
|
||||
var data = $(this).find("a.set_position").data();
|
||||
const data = $(this).find("a.set_position").data();
|
||||
|
||||
marker = L.marker([data.lat, data.lon], { icon: OSM.getUserIcon() });
|
||||
|
||||
|
@ -77,7 +77,7 @@ OSM.Search = function (map) {
|
|||
}
|
||||
|
||||
function hideSearchResult() {
|
||||
var marker = $(this).data("marker");
|
||||
const marker = $(this).data("marker");
|
||||
|
||||
if (marker) {
|
||||
markers.removeLayer(marker);
|
||||
|
@ -93,7 +93,7 @@ OSM.Search = function (map) {
|
|||
}
|
||||
|
||||
function clickSearchResult(e) {
|
||||
var data = $(this).data();
|
||||
const data = $(this).data();
|
||||
|
||||
panToSearchResult(data);
|
||||
|
||||
|
@ -104,7 +104,7 @@ OSM.Search = function (map) {
|
|||
e.stopPropagation();
|
||||
}
|
||||
|
||||
var page = {};
|
||||
const page = {};
|
||||
|
||||
page.pushstate = page.popstate = function (path) {
|
||||
const params = new URLSearchParams(path.substring(path.indexOf("?")));
|
||||
|
@ -120,16 +120,16 @@ OSM.Search = function (map) {
|
|||
|
||||
page.load = function () {
|
||||
$(".search_results_entry").each(function (index) {
|
||||
var entry = $(this),
|
||||
csrf_param = $("meta[name=csrf-param]").attr("content"),
|
||||
csrf_token = $("meta[name=csrf-token]").attr("content"),
|
||||
params = new URLSearchParams({
|
||||
zoom: map.getZoom(),
|
||||
minlon: map.getBounds().getWest(),
|
||||
minlat: map.getBounds().getSouth(),
|
||||
maxlon: map.getBounds().getEast(),
|
||||
maxlat: map.getBounds().getNorth()
|
||||
});
|
||||
const entry = $(this),
|
||||
csrf_param = $("meta[name=csrf-param]").attr("content"),
|
||||
csrf_token = $("meta[name=csrf-token]").attr("content"),
|
||||
params = new URLSearchParams({
|
||||
zoom: map.getZoom(),
|
||||
minlon: map.getBounds().getWest(),
|
||||
minlat: map.getBounds().getSouth(),
|
||||
maxlon: map.getBounds().getEast(),
|
||||
maxlat: map.getBounds().getNorth()
|
||||
});
|
||||
params.set(csrf_param, csrf_token);
|
||||
fetch(entry.data("href"), {
|
||||
method: "POST",
|
||||
|
@ -140,7 +140,7 @@ OSM.Search = function (map) {
|
|||
entry.html(html);
|
||||
// go to first result of first geocoder
|
||||
if (index === 0) {
|
||||
var firstResult = entry.find("*[data-lat][data-lon]:first").first();
|
||||
const firstResult = entry.find("*[data-lat][data-lon]:first").first();
|
||||
if (firstResult.length) {
|
||||
panToSearchResult(firstResult.data());
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue