Skip to content

Commit

Permalink
Merge branch 'pull/5474'
Browse files Browse the repository at this point in the history
  • Loading branch information
AntonKhorev committed Jan 27, 2025
2 parents d76b7a5 + dae7a00 commit c7adb87
Show file tree
Hide file tree
Showing 7 changed files with 38 additions and 25 deletions.
4 changes: 2 additions & 2 deletions app/assets/javascripts/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,7 @@ $(document).ready(function () {
var expiry = new Date();
expiry.setYear(expiry.getFullYear() + 10);

map.on("moveend layeradd layerremove", function () {
map.on("moveend baselayerchange overlayadd overlayremove", function () {
updateLinks(
map.getCenter().wrap(),
map.getZoom(),
Expand Down Expand Up @@ -205,7 +205,7 @@ $(document).ready(function () {
});

if (OSM.MATOMO) {
map.on("layeradd", function (e) {
map.on("baselayerchange overlayadd", function (e) {
if (e.layer.options) {
var goal = OSM.MATOMO.goals[e.layer.options.layerId];

Expand Down
18 changes: 8 additions & 10 deletions app/assets/javascripts/index/layers/data.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,18 +25,16 @@ OSM.initializeDataLayer = function (map) {
onSelect(e.layer);
});

map.on("layeradd", function (e) {
if (e.layer === dataLayer) {
map.on("moveend", updateData);
updateData();
}
dataLayer.on("add", function () {
map.fire("overlayadd", { layer: this });
map.on("moveend", updateData);
updateData();
});

map.on("layerremove", function (e) {
if (e.layer === dataLayer) {
map.off("moveend", updateData);
$("#browse_status").empty();
}
dataLayer.on("remove", function () {
map.off("moveend", updateData);
$("#browse_status").empty();
map.fire("overlayremove", { layer: this });
});

function updateData() {
Expand Down
2 changes: 2 additions & 0 deletions app/assets/javascripts/index/layers/notes.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,12 @@ OSM.initializeNotesLayer = function (map) {
noteLayer.on("add", () => {
loadNotes();
map.on("moveend", loadNotes);
map.fire("overlayadd", { layer: noteLayer });
}).on("remove", () => {
map.off("moveend", loadNotes);
noteLayer.clearLayers();
notes = {};
map.fire("overlayremove", { layer: noteLayer });
}).on("click", function (e) {
if (e.layer.id) {
OSM.router.route("/note/" + e.layer.id);
Expand Down
11 changes: 4 additions & 7 deletions app/assets/javascripts/leaflet.layers.js
Original file line number Diff line number Diff line change
Expand Up @@ -61,18 +61,16 @@ L.OSM.layers = function (options) {

input.on("click", function () {
layers.forEach(function (other) {
if (other === layer) {
map.addLayer(other);
} else {
if (other !== layer) {
map.removeLayer(other);
}
});
map.fire("baselayerchange", { layer: layer });
map.addLayer(layer);
});

item.on("dblclick", toggle);

map.on("layeradd layerremove", function () {
map.on("baselayerchange", function () {
input.prop("checked", map.hasLayer(layer));
});
});
Expand Down Expand Up @@ -121,10 +119,9 @@ L.OSM.layers = function (options) {
} else {
map.removeLayer(layer);
}
map.fire("overlaylayerchange", { layer: layer });
});

map.on("layeradd layerremove", function () {
map.on("overlayadd overlayremove", function () {
input.prop("checked", map.hasLayer(layer));
});

Expand Down
24 changes: 20 additions & 4 deletions app/assets/javascripts/leaflet.map.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,9 @@ L.OSM.Map = L.Map.extend({
}

const layer = new layerConstructor(layerOptions);
layer.on("add", () => {
this.fire("baselayerchange", { layer: layer });
});
this.baseLayers.push(layer);
}

Expand All @@ -53,8 +56,14 @@ L.OSM.Map = L.Map.extend({
pane: "overlayPane",
code: "G"
});
this.gpsLayer.on("add", () => {
this.fire("overlayadd", { layer: this.gpsLayer });
}).on("remove", () => {
this.fire("overlayremove", { layer: this.gpsLayer });
});


this.on("layeradd", function (event) {
this.on("baselayerchange", function (event) {
if (this.baseLayers.indexOf(event.layer) >= 0) {
this.setMaxZoom(event.layer.options.maxZoom);
}
Expand Down Expand Up @@ -109,14 +118,18 @@ L.OSM.Map = L.Map.extend({
var layers = layerParam || "M",
layersAdded = "";

for (var i = this.baseLayers.length - 1; i >= 0; i--) {
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 (let i = this.baseLayers.length - 1; i >= 0; i--) {
if (layers.indexOf(this.baseLayers[i].options.code) >= 0) {
this.addLayer(this.baseLayers[i]);
layersAdded = layersAdded + this.baseLayers[i].options.code;
} else if (i === 0 && layersAdded === "") {
this.addLayer(this.baseLayers[i]);
} else {
this.removeLayer(this.baseLayers[i]);
}
}
},
Expand Down Expand Up @@ -297,6 +310,7 @@ L.OSM.Map = L.Map.extend({
}

if (callback) callback(this._objectLayer.getBounds());
this.fire("overlayadd", { layer: this._objectLayer });
} else { // element handled by L.OSM.DataLayer
var map = this;
this._objectLoader = $.ajax({
Expand Down Expand Up @@ -328,6 +342,7 @@ L.OSM.Map = L.Map.extend({
map._objectLayer.addTo(map);

if (callback) callback(map._objectLayer.getBounds());
map.fire("overlayadd", { layer: map._objectLayer });
}
});
}
Expand All @@ -337,6 +352,7 @@ L.OSM.Map = L.Map.extend({
this._object = null;
if (this._objectLoader) this._objectLoader.abort();
if (this._objectLayer) this.removeLayer(this._objectLayer);
this.fire("overlayremove", { layer: this._objectLayer });
},

getState: function () {
Expand Down
2 changes: 1 addition & 1 deletion app/assets/javascripts/leaflet.share.js
Original file line number Diff line number Diff line change
Expand Up @@ -269,7 +269,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)
Expand Down
2 changes: 1 addition & 1 deletion app/assets/javascripts/router.js
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,7 @@ OSM.Router = function (map, rts) {
currentRoute = routes.recognize(currentPath);
};

map.on("moveend baselayerchange overlaylayerchange", router.updateHash);
map.on("moveend baselayerchange overlayadd overlayremove", router.updateHash);
$(window).on("hashchange", router.hashUpdated);

return router;
Expand Down

0 comments on commit c7adb87

Please sign in to comment.