mirror of
https://github.com/umap-project/umap.git
synced 2025-04-28 19:42:36 +02:00
Compare commits
2 commits
4f2f98bdb7
...
53072b6f5b
Author | SHA1 | Date | |
---|---|---|---|
![]() |
53072b6f5b | ||
![]() |
626b669d89 |
1 changed files with 46 additions and 0 deletions
46
umap/static/umap/js/modules/managers.js
Normal file
46
umap/static/umap/js/modules/managers.js
Normal file
|
@ -0,0 +1,46 @@
|
||||||
|
export class DataLayerManager extends Object {
|
||||||
|
add(datalayer) {
|
||||||
|
this[datalayer.id] = datalayer
|
||||||
|
}
|
||||||
|
active() {
|
||||||
|
return Object.values(this)
|
||||||
|
.filter((datalayer) => !datalayer.isDeleted)
|
||||||
|
.sort((a, b) => a.options.rank > b.options.rank)
|
||||||
|
}
|
||||||
|
reverse() {
|
||||||
|
return this.active().reverse()
|
||||||
|
}
|
||||||
|
count() {
|
||||||
|
return this.active().length
|
||||||
|
}
|
||||||
|
find(func) {
|
||||||
|
for (const datalayer of this.reverse()) {
|
||||||
|
if (func.call(datalayer, datalayer)) {
|
||||||
|
return datalayer
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
filter(func) {
|
||||||
|
return this.active().filter(func)
|
||||||
|
}
|
||||||
|
visible() {
|
||||||
|
return this.filter((datalayer) => datalayer.isVisible())
|
||||||
|
}
|
||||||
|
browsable() {
|
||||||
|
return this.reverse().filter((datalayer) => datalayer.allowBrowse())
|
||||||
|
}
|
||||||
|
prev(datalayer) {
|
||||||
|
const browsable = this.browsable()
|
||||||
|
const current = browsable.indexOf(datalayer)
|
||||||
|
const prev = browsable[current - 1] || browsable[browsable.length - 1]
|
||||||
|
if (!prev.canBrowse()) return this.prev(prev)
|
||||||
|
return prev
|
||||||
|
}
|
||||||
|
next(datalayer) {
|
||||||
|
const browsable = this.browsable()
|
||||||
|
const current = browsable.indexOf(datalayer)
|
||||||
|
const next = browsable[current + 1] || browsable[0]
|
||||||
|
if (!next.canBrowse()) return this.next(next)
|
||||||
|
return next
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in a new issue