Skip to content

Commit

Permalink
Use baselayerchange/overlaylayerchange instead of layeradd/layerremov…
Browse files Browse the repository at this point in the history
…e for speed up Map Data layer render
  • Loading branch information
deevroman committed Jan 10, 2025
1 parent a6c6f26 commit 5b37b54
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 12 deletions.
2 changes: 1 addition & 1 deletion 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 overlaylayerchange", function () {
updateLinks(
map.getCenter().wrap(),
map.getZoom(),
Expand Down
16 changes: 6 additions & 10 deletions app/assets/javascripts/index/layers/data.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,19 +25,15 @@ OSM.initializeDataLayer = function (map) {
onSelect(e.layer);
});

map.on("layeradd", function (e) {
if (e.layer === dataLayer) {
dataLayer.on("add", function (e) {
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 (e) {
map.off("moveend", updateData);
$("#browse_status").empty();
})

function updateData() {
var bounds = map.getBounds();
Expand Down
3 changes: 3 additions & 0 deletions app/assets/javascripts/leaflet.map.js
Original file line number Diff line number Diff line change
Expand Up @@ -295,6 +295,7 @@ L.OSM.Map = L.Map.extend({
}

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

if (callback) callback(map._objectLayer.getBounds());
map.fire("overlaylayerchange", { layer: map._objectLayer });
}
});
}
Expand All @@ -335,6 +337,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("overlaylayerchange", { 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 overlaylayerchange", update);

$ui
.on("show", shown)
Expand Down

0 comments on commit 5b37b54

Please sign in to comment.