Reevaluate iteration methods
This commit is contained in:
parent
c4c7f68f17
commit
550e5d336f
7 changed files with 46 additions and 65 deletions
|
@ -97,9 +97,7 @@ $(document).ready(function () {
|
|||
var position = $("html").attr("dir") === "rtl" ? "topleft" : "topright";
|
||||
|
||||
function addControlGroup(controls) {
|
||||
controls.forEach(function (control) {
|
||||
control.addTo(map);
|
||||
});
|
||||
for (const control of controls) control.addTo(map);
|
||||
|
||||
var firstContainer = controls[0].getContainer();
|
||||
$(firstContainer).find(".control-button").first()
|
||||
|
|
|
@ -96,7 +96,7 @@ OSM.History = function (map) {
|
|||
function updateBounds() {
|
||||
group.clearLayers();
|
||||
|
||||
changesets.forEach(function (changeset) {
|
||||
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,
|
||||
|
@ -115,16 +115,15 @@ OSM.History = function (map) {
|
|||
|
||||
changeset.bounds = L.latLngBounds(map.unproject(bottomLeft),
|
||||
map.unproject(topRight));
|
||||
});
|
||||
}
|
||||
|
||||
changesets.sort(function (a, b) {
|
||||
return b.bounds.getSize() - a.bounds.getSize();
|
||||
});
|
||||
|
||||
for (var i = 0; i < changesets.length; ++i) {
|
||||
var changeset = changesets[i],
|
||||
rect = L.rectangle(changeset.bounds,
|
||||
{ weight: 2, color: "#FF9500", opacity: 1, fillColor: "#FFFFAF", fillOpacity: 0 });
|
||||
for (const changeset of changesets) {
|
||||
const rect = L.rectangle(changeset.bounds,
|
||||
{ weight: 2, color: "#FF9500", opacity: 1, fillColor: "#FFFFAF", fillOpacity: 0 });
|
||||
rect.id = changeset.id;
|
||||
rect.addTo(group);
|
||||
}
|
||||
|
|
|
@ -84,9 +84,7 @@ OSM.initializeNotesLayer = function (map) {
|
|||
function success(json) {
|
||||
var oldNotes = notes;
|
||||
notes = {};
|
||||
json.features.forEach(updateMarkers);
|
||||
|
||||
function updateMarkers(feature) {
|
||||
for (const feature of json.features) {
|
||||
var marker = oldNotes[feature.properties.id];
|
||||
delete oldNotes[feature.properties.id];
|
||||
notes[feature.properties.id] = updateMarker(marker, feature);
|
||||
|
|
|
@ -109,9 +109,9 @@ OSM.Query = function (map) {
|
|||
var tags = feature.tags,
|
||||
locales = OSM.preferred_languages;
|
||||
|
||||
for (var i = 0; i < locales.length; i++) {
|
||||
if (tags["name:" + locales[i]]) {
|
||||
return tags["name:" + locales[i]];
|
||||
for (const locale of locales) {
|
||||
if (tags["name:" + locale]) {
|
||||
return tags["name:" + locale];
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -193,22 +193,20 @@ OSM.Query = function (map) {
|
|||
elements = elements.sort(compare);
|
||||
}
|
||||
|
||||
for (var i = 0; i < elements.length; i++) {
|
||||
var element = elements[i];
|
||||
for (const element of elements) {
|
||||
if (!interestingFeature(element)) continue;
|
||||
|
||||
if (interestingFeature(element)) {
|
||||
var $li = $("<li>")
|
||||
.addClass("list-group-item list-group-item-action")
|
||||
.text(featurePrefix(element) + " ")
|
||||
.appendTo($ul);
|
||||
var $li = $("<li>")
|
||||
.addClass("list-group-item list-group-item-action")
|
||||
.text(featurePrefix(element) + " ")
|
||||
.appendTo($ul);
|
||||
|
||||
$("<a>")
|
||||
.addClass("stretched-link")
|
||||
.attr("href", "/" + element.type + "/" + element.id)
|
||||
.data("geometry", featureGeometry(element))
|
||||
.text(featureName(element))
|
||||
.appendTo($li);
|
||||
}
|
||||
$("<a>")
|
||||
.addClass("stretched-link")
|
||||
.attr("href", "/" + element.type + "/" + element.id)
|
||||
.data("geometry", featureGeometry(element))
|
||||
.text(featureName(element))
|
||||
.appendTo($li);
|
||||
}
|
||||
|
||||
if (results.remark) {
|
||||
|
|
|
@ -60,11 +60,11 @@ L.OSM.layers = function (options) {
|
|||
});
|
||||
|
||||
input.on("click", function () {
|
||||
layers.forEach(function (other) {
|
||||
for (const other of layers) {
|
||||
if (other !== layer) {
|
||||
map.removeLayer(other);
|
||||
}
|
||||
});
|
||||
}
|
||||
map.addLayer(layer);
|
||||
});
|
||||
|
||||
|
|
|
@ -201,41 +201,31 @@ 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) {
|
||||
$("<input>")
|
||||
.attr("id", "mapnik_" + name)
|
||||
.attr("name", name)
|
||||
.attr("type", "hidden")
|
||||
.appendTo($form);
|
||||
});
|
||||
}
|
||||
|
||||
$("<input>")
|
||||
.attr("id", "map_format")
|
||||
.attr("name", "format")
|
||||
.attr("value", "mapnik")
|
||||
.attr("type", "hidden")
|
||||
.appendTo($form);
|
||||
const hiddenExportDefaults = {
|
||||
format: "mapnik",
|
||||
zoom: map.getZoom(),
|
||||
width: 0,
|
||||
height: 0
|
||||
};
|
||||
|
||||
$("<input>")
|
||||
.attr("id", "map_zoom")
|
||||
.attr("name", "zoom")
|
||||
.attr("value", map.getZoom())
|
||||
.attr("type", "hidden")
|
||||
.appendTo($form);
|
||||
|
||||
$("<input>")
|
||||
.attr("id", "map_width")
|
||||
.attr("name", "width")
|
||||
.attr("value", 0)
|
||||
.attr("type", "hidden")
|
||||
.appendTo($form);
|
||||
|
||||
$("<input>")
|
||||
.attr("id", "map_height")
|
||||
.attr("name", "height")
|
||||
.attr("value", 0)
|
||||
.attr("type", "hidden")
|
||||
.appendTo($form);
|
||||
for (const name in hiddenExportDefaults) {
|
||||
$("<input>")
|
||||
.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");
|
||||
|
|
|
@ -84,14 +84,12 @@ OSM.Router = function (map, rts) {
|
|||
return route;
|
||||
}
|
||||
|
||||
var routes = [];
|
||||
for (var r in rts) {
|
||||
routes.push(new Route(r, rts[r]));
|
||||
}
|
||||
const routes = Object.entries(rts)
|
||||
.map(([r, t]) => new Route(r, t));
|
||||
|
||||
routes.recognize = function (path) {
|
||||
for (var i = 0; i < this.length; i++) {
|
||||
if (this[i].match(path)) return this[i];
|
||||
for (const route of this) {
|
||||
if (route.match(path)) return route;
|
||||
}
|
||||
};
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue