mirror of
https://github.com/umap-project/umap.git
synced 2025-05-05 06:01:48 +02:00
wip: use AutocompleteDatalist in rules too
This commit is contained in:
parent
4552dc0341
commit
4e73eade18
2 changed files with 25 additions and 1 deletions
|
@ -1,5 +1,6 @@
|
||||||
import { DomEvent, DomUtil, stamp } from '../../vendors/leaflet/leaflet-src.esm.js'
|
import { DomEvent, DomUtil, stamp } from '../../vendors/leaflet/leaflet-src.esm.js'
|
||||||
import { translate } from './i18n.js'
|
import { translate } from './i18n.js'
|
||||||
|
import { AutocompleteDatalist } from './autocomplete.js'
|
||||||
import * as Utils from './utils.js'
|
import * as Utils from './utils.js'
|
||||||
|
|
||||||
export class Rule {
|
export class Rule {
|
||||||
|
@ -89,7 +90,7 @@ class ConditionalRule extends Rule {
|
||||||
}
|
}
|
||||||
|
|
||||||
constructor(map, condition = '', options = {}) {
|
constructor(map, condition = '', options = {}) {
|
||||||
super()
|
super(condition)
|
||||||
this._isDirty = false
|
this._isDirty = false
|
||||||
this.map = map
|
this.map = map
|
||||||
this.active = true
|
this.active = true
|
||||||
|
@ -134,6 +135,18 @@ class ConditionalRule extends Rule {
|
||||||
const builder = new U.FormBuilder(this, options)
|
const builder = new U.FormBuilder(this, options)
|
||||||
const defaultShapeProperties = DomUtil.add('div', '', container)
|
const defaultShapeProperties = DomUtil.add('div', '', container)
|
||||||
defaultShapeProperties.appendChild(builder.build())
|
defaultShapeProperties.appendChild(builder.build())
|
||||||
|
const autocomplete = new AutocompleteDatalist(builder.helpers.condition.input)
|
||||||
|
const properties = this.map.allProperties()
|
||||||
|
autocomplete.suggestions = properties
|
||||||
|
autocomplete.input.addEventListener('input', (event) => {
|
||||||
|
const value = event.target.value
|
||||||
|
if (properties.includes(value)) {
|
||||||
|
autocomplete.suggestions = [`${value}=`, `${value}!=`, `${value}>`, `${value}<`]
|
||||||
|
} else if (value.endsWith('=')) {
|
||||||
|
const key = value.split('!')[0].split('=')[0]
|
||||||
|
autocomplete.suggestions = this.map.sortedValues(key).map((str) => `${value}${str || ''}`)
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
this.map.editPanel.open({ content: container })
|
this.map.editPanel.open({ content: container })
|
||||||
}
|
}
|
||||||
|
|
|
@ -262,6 +262,17 @@ U.Map = L.Map.extend({
|
||||||
this.onDataLayersChanged()
|
this.onDataLayersChanged()
|
||||||
},
|
},
|
||||||
|
|
||||||
|
allProperties: function () {
|
||||||
|
return [].concat(...this.datalayers_index.map((dl) => dl._propertiesIndex))
|
||||||
|
},
|
||||||
|
|
||||||
|
sortedValues: function (property) {
|
||||||
|
return []
|
||||||
|
.concat(...this.datalayers_index.map((dl) => dl.sortedValues(property)))
|
||||||
|
.filter((val, idx, arr) => arr.indexOf(val) === idx)
|
||||||
|
.sort(U.Utils.naturalSort)
|
||||||
|
},
|
||||||
|
|
||||||
redrawVisibleDataLayers: function () {
|
redrawVisibleDataLayers: function () {
|
||||||
this.eachVisibleDataLayer((datalayer) => {
|
this.eachVisibleDataLayer((datalayer) => {
|
||||||
datalayer.redraw()
|
datalayer.redraw()
|
||||||
|
|
Loading…
Reference in a new issue