mirror of
https://github.com/umap-project/umap.git
synced 2025-05-05 22:11:50 +02:00
Merge 73e4817e3d
into 31ea8d1a83
This commit is contained in:
commit
8fa644be52
5 changed files with 77 additions and 16 deletions
|
@ -514,12 +514,45 @@ L.U.DataLayersControl = L.Control.extend({
|
||||||
update: function () {
|
update: function () {
|
||||||
if (this._datalayers_container && this._map) {
|
if (this._datalayers_container && this._map) {
|
||||||
this._datalayers_container.innerHTML = ''
|
this._datalayers_container.innerHTML = ''
|
||||||
this._map.eachDataLayerReverse(function (datalayer) {
|
const hasGroups = !!Object.keys(this._map.groups_index).length
|
||||||
this.addDataLayer(this._datalayers_container, datalayer)
|
L.DomUtil.classIf(this._datalayers_container, 'grouped', hasGroups)
|
||||||
}, this)
|
if (hasGroups) this.renderGroupedList()
|
||||||
|
else this.renderFlatList()
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
|
renderFlatList: function () {
|
||||||
|
this._map.eachDataLayerReverse(function (datalayer) {
|
||||||
|
this.addDataLayer(this._datalayers_container, datalayer)
|
||||||
|
}, this)
|
||||||
|
},
|
||||||
|
|
||||||
|
renderGroupedList: function () {
|
||||||
|
const groups = Object.keys(this._map.groups_index).sort(L.Util.naturalSort)
|
||||||
|
for (let group of groups) {
|
||||||
|
let ids = this._map.groups_index[group]
|
||||||
|
this.addGroupHeader(group, ids)
|
||||||
|
for (let id of ids) {
|
||||||
|
this.addDataLayer(this._datalayers_container, this._map.datalayers[id])
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
|
||||||
|
addGroupHeader: function (group, ids) {
|
||||||
|
const header = L.DomUtil.add('h4', 'layer-group', this._datalayers_container, group)
|
||||||
|
const toggle = L.DomUtil.create('i', 'group-toggle', header)
|
||||||
|
L.DomEvent.on(toggle, 'click', () => {
|
||||||
|
let show, datalayer
|
||||||
|
for (let id of ids) {
|
||||||
|
datalayer = this._map.datalayers[id]
|
||||||
|
// Show/hide all according to first datalayer
|
||||||
|
if (typeof(show) === 'undefined') show = !datalayer.isVisible()
|
||||||
|
if (show) datalayer.show()
|
||||||
|
else datalayer.hide()
|
||||||
|
}
|
||||||
|
})
|
||||||
|
},
|
||||||
|
|
||||||
expand: function () {
|
expand: function () {
|
||||||
L.DomUtil.addClass(this._container, 'expanded')
|
L.DomUtil.addClass(this._container, 'expanded')
|
||||||
},
|
},
|
||||||
|
@ -676,7 +709,6 @@ L.U.DataLayer.addInitHook(function () {
|
||||||
})
|
})
|
||||||
|
|
||||||
L.U.Map.include({
|
L.U.Map.include({
|
||||||
|
|
||||||
_openFacet: function () {
|
_openFacet: function () {
|
||||||
const container = L.DomUtil.create('div', 'umap-facet-search'),
|
const container = L.DomUtil.create('div', 'umap-facet-search'),
|
||||||
title = L.DomUtil.add('h3', 'umap-filter-title', container, L._('Facet search')),
|
title = L.DomUtil.add('h3', 'umap-filter-title', container, L._('Facet search')),
|
||||||
|
|
|
@ -198,6 +198,16 @@ L.Util.greedyTemplate = (str, data, ignore) => {
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
L.Util.naturalSort = (a, b) => {
|
||||||
|
return a
|
||||||
|
.toString()
|
||||||
|
.toLowerCase()
|
||||||
|
.localeCompare(b.toString().toLowerCase(), L.lang || 'en', {
|
||||||
|
sensitivity: 'base',
|
||||||
|
numeric: true,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
L.Util.sortFeatures = (features, sortKey) => {
|
L.Util.sortFeatures = (features, sortKey) => {
|
||||||
const sortKeys = (sortKey || 'name').split(',')
|
const sortKeys = (sortKey || 'name').split(',')
|
||||||
|
|
||||||
|
@ -216,13 +226,7 @@ L.Util.sortFeatures = (features, sortKey) => {
|
||||||
} else if (!valB) {
|
} else if (!valB) {
|
||||||
score = 1
|
score = 1
|
||||||
} else {
|
} else {
|
||||||
score = valA
|
score = L.Util.naturalSort(valA, valB)
|
||||||
.toString()
|
|
||||||
.toLowerCase()
|
|
||||||
.localeCompare(valB.toString().toLowerCase(), L.lang || 'en', {
|
|
||||||
sensitivity: 'base',
|
|
||||||
numeric: true,
|
|
||||||
})
|
|
||||||
}
|
}
|
||||||
if (score === 0 && sortKeys[i + 1]) return sort(a, b, i + 1)
|
if (score === 0 && sortKeys[i + 1]) return sort(a, b, i + 1)
|
||||||
return score * reverse
|
return score * reverse
|
||||||
|
|
|
@ -158,6 +158,7 @@ L.U.Map.include({
|
||||||
// Global storage for retrieving datalayers and features
|
// Global storage for retrieving datalayers and features
|
||||||
this.datalayers = {}
|
this.datalayers = {}
|
||||||
this.datalayers_index = []
|
this.datalayers_index = []
|
||||||
|
this.groups_index = {}
|
||||||
this.dirty_datalayers = []
|
this.dirty_datalayers = []
|
||||||
this.features_index = {}
|
this.features_index = {}
|
||||||
this.facets = {}
|
this.facets = {}
|
||||||
|
@ -438,16 +439,29 @@ L.U.Map.include({
|
||||||
|
|
||||||
indexDatalayers: function () {
|
indexDatalayers: function () {
|
||||||
const panes = this.getPane('overlayPane')
|
const panes = this.getPane('overlayPane')
|
||||||
let pane
|
|
||||||
this.datalayers_index = []
|
this.datalayers_index = []
|
||||||
for (let i = 0; i < panes.children.length; i++) {
|
for (let i = 0, pane, datalayer; i < panes.children.length; i++) {
|
||||||
pane = panes.children[i]
|
pane = panes.children[i]
|
||||||
if (!pane.dataset || !pane.dataset.id) continue
|
if (!pane.dataset || !pane.dataset.id) continue
|
||||||
this.datalayers_index.push(this.datalayers[pane.dataset.id])
|
datalayer = this.datalayers[pane.dataset.id]
|
||||||
|
this.datalayers_index.push(datalayer)
|
||||||
}
|
}
|
||||||
|
this.indexGroups()
|
||||||
this.updateDatalayersControl()
|
this.updateDatalayersControl()
|
||||||
},
|
},
|
||||||
|
|
||||||
|
indexGroups: function () {
|
||||||
|
this.groups_index = {}
|
||||||
|
this.eachDataLayer(this.indexGroup)
|
||||||
|
},
|
||||||
|
|
||||||
|
indexGroup: function (datalayer) {
|
||||||
|
const group = datalayer.options.group
|
||||||
|
if (!group) return
|
||||||
|
this.groups_index[group] = this.groups_index[group] || []
|
||||||
|
this.groups_index[group].push(L.stamp(datalayer))
|
||||||
|
},
|
||||||
|
|
||||||
ensurePanesOrder: function () {
|
ensurePanesOrder: function () {
|
||||||
this.eachDataLayer((datalayer) => {
|
this.eachDataLayer((datalayer) => {
|
||||||
datalayer.bringToTop()
|
datalayer.bringToTop()
|
||||||
|
@ -1014,14 +1028,14 @@ L.U.Map.include({
|
||||||
|
|
||||||
eachDataLayer: function (method, context) {
|
eachDataLayer: function (method, context) {
|
||||||
for (let i = 0; i < this.datalayers_index.length; i++) {
|
for (let i = 0; i < this.datalayers_index.length; i++) {
|
||||||
method.call(context, this.datalayers_index[i])
|
method.call(context || this, this.datalayers_index[i])
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
eachDataLayerReverse: function (method, context, filter) {
|
eachDataLayerReverse: function (method, context, filter) {
|
||||||
for (let i = this.datalayers_index.length - 1; i >= 0; i--) {
|
for (let i = this.datalayers_index.length - 1; i >= 0; i--) {
|
||||||
if (filter && !filter.call(context, this.datalayers_index[i])) continue
|
if (filter && !filter.call(context, this.datalayers_index[i])) continue
|
||||||
method.call(context, this.datalayers_index[i])
|
method.call(context || this, this.datalayers_index[i])
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
|
|
|
@ -488,6 +488,7 @@ L.U.DataLayer = L.Evented.extend({
|
||||||
this.map.datalayers[id] = this
|
this.map.datalayers[id] = this
|
||||||
if (L.Util.indexOf(this.map.datalayers_index, this) === -1)
|
if (L.Util.indexOf(this.map.datalayers_index, this) === -1)
|
||||||
this.map.datalayers_index.push(this)
|
this.map.datalayers_index.push(this)
|
||||||
|
this.map.indexGroup(this)
|
||||||
}
|
}
|
||||||
this.map.updateDatalayersControl()
|
this.map.updateDatalayersControl()
|
||||||
},
|
},
|
||||||
|
@ -854,6 +855,7 @@ L.U.DataLayer = L.Evented.extend({
|
||||||
metadataFields = [
|
metadataFields = [
|
||||||
'options.name',
|
'options.name',
|
||||||
'options.description',
|
'options.description',
|
||||||
|
['options.group', { handler: 'BlurInput', label: L._('Layer group'), datalist: Object.keys(this.map.groups_index)}],
|
||||||
['options.type', { handler: 'LayerTypeChooser', label: L._('Type of layer') }],
|
['options.type', { handler: 'LayerTypeChooser', label: L._('Type of layer') }],
|
||||||
['options.displayOnLoad', { label: L._('Display on load'), handler: 'Switch' }],
|
['options.displayOnLoad', { label: L._('Display on load'), handler: 'Switch' }],
|
||||||
[
|
[
|
||||||
|
@ -875,6 +877,7 @@ L.U.DataLayer = L.Evented.extend({
|
||||||
const title = L.DomUtil.add('h3', '', container, L._('Layer properties'))
|
const title = L.DomUtil.add('h3', '', container, L._('Layer properties'))
|
||||||
let builder = new L.U.FormBuilder(this, metadataFields, {
|
let builder = new L.U.FormBuilder(this, metadataFields, {
|
||||||
callback: function (e) {
|
callback: function (e) {
|
||||||
|
this.map.indexGroups()
|
||||||
this.map.updateDatalayersControl()
|
this.map.updateDatalayersControl()
|
||||||
if (e.helper.field === 'options.type') {
|
if (e.helper.field === 'options.type') {
|
||||||
this.resetLayer()
|
this.resetLayer()
|
||||||
|
|
|
@ -694,6 +694,7 @@ a.map-name:after {
|
||||||
max-height: 15em;
|
max-height: 15em;
|
||||||
overflow-y: auto;
|
overflow-y: auto;
|
||||||
}
|
}
|
||||||
|
.layer-group i,
|
||||||
.search-result-tools i,
|
.search-result-tools i,
|
||||||
.leaflet-inplace-toolbar a,
|
.leaflet-inplace-toolbar a,
|
||||||
.umap-browse-features i,
|
.umap-browse-features i,
|
||||||
|
@ -717,6 +718,12 @@ a.map-name:after {
|
||||||
margin-right: 5px;
|
margin-right: 5px;
|
||||||
cursor: move;
|
cursor: move;
|
||||||
}
|
}
|
||||||
|
.umap-browse-datalayers.grouped li {
|
||||||
|
padding-left: 10px;
|
||||||
|
}
|
||||||
|
.umap-browse-datalayers.grouped h4 {
|
||||||
|
margin-bottom: 0;
|
||||||
|
}
|
||||||
.leaflet-inplace-toolbar a {
|
.leaflet-inplace-toolbar a {
|
||||||
background-image: url('./img/16-white.svg');
|
background-image: url('./img/16-white.svg');
|
||||||
background-color: #323737!important;
|
background-color: #323737!important;
|
||||||
|
@ -730,6 +737,7 @@ a.map-name:after {
|
||||||
.leaflet-control-browse .umap-browse-datalayers .off i {
|
.leaflet-control-browse .umap-browse-datalayers .off i {
|
||||||
cursor: inherit;
|
cursor: inherit;
|
||||||
}
|
}
|
||||||
|
.group-toggle,
|
||||||
.layer-toggle {
|
.layer-toggle {
|
||||||
background-position: -49px -31px;
|
background-position: -49px -31px;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue