Skip to content

Commit

Permalink
Update call to sortFunction in copied / locally modified LayerControl.
Browse files Browse the repository at this point in the history
_update function to use the options.sortFunction if present.  tbd:
if this should be offered via PR to upstream project.

Prettier formatting changes to pre-existing test file
  • Loading branch information
prushforth committed Apr 9, 2024
1 parent 86e68b6 commit 5ec1494
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 9 deletions.
12 changes: 5 additions & 7 deletions src/mapml/control/LayerControl.js
Original file line number Diff line number Diff line change
Expand Up @@ -98,10 +98,6 @@ export var LayerControl = L.Control.Layers.extend({
}
},

_withinZoomBounds: function (zoom, range) {
return range.min <= zoom && zoom <= range.max;
},

// imported from leaflet with slight modifications
// for layerControl ordering based on zIndex
_update: function () {
Expand All @@ -122,9 +118,11 @@ export var LayerControl = L.Control.Layers.extend({
// <----------- MODIFICATION from the default _update method
// sort the layercontrol layers object based on the zIndex
// provided by MapMLLayer
this._layers.sort(
(a, b) => a.layer.options.zIndex - b.layer.options.zIndex
);
if (this.options.sortLayers) {
this._layers.sort((a, b) =>
this.options.sortFunction(a.layer, b.layer, a.name, b.name)
);
}
// -------------------------------------------------->
for (i = 0; i < this._layers.length; i++) {
obj = this._layers[i];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,8 +83,8 @@ The imagery layer <map-extent> draws on top of the states layer.
return +e._extentLayer._container.style.zIndex;
});
expect(statesZIndex).toEqual(1);
// TO DO re-order them via the DOM (insertAdjacentHTML),
// ensure that
// TO DO re-order them via the DOM (insertAdjacentHTML),
// ensure that
// a) render order/z-index is correct
// b) render order is reflected in layer control order as well
// see https://github.com/Maps4HTML/Web-Map-Custom-Element/issues/956
Expand Down

0 comments on commit 5ec1494

Please sign in to comment.