-
Notifications
You must be signed in to change notification settings - Fork 46
Expand file tree
/
Copy pathFormElement.js
More file actions
91 lines (75 loc) · 2.74 KB
/
FormElement.js
File metadata and controls
91 lines (75 loc) · 2.74 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
import 'leaflet'
/** FormElements are part of a Form for a specific styling option (i.e. color) */
export default function setupFormElement () {
L.StyleEditor.formElements.FormElement = L.Class.extend({
/** set options and title */
initialize: function (options) {
if (options) {
L.setOptions(this, options)
}
// if no title is given use styling option
if (!this.options.title && !!this.options.styleOption) {
this.options.title = this.options.styleOption.charAt(0).toUpperCase() + this.options.styleOption.slice(1)
}
},
/** create uiElement and content */
create: function (parentUiElement) {
this.options.uiElement =
L.DomUtil.create('div', 'leaflet-styleeditor-uiElement', parentUiElement)
this.createTitle()
this.createContent()
},
/** create title */
createTitle: function () {
let title = L.DomUtil.create('label', 'leaflet-styleeditor-label', this.options.uiElement)
title.innerHTML = this.options.title + ':'
},
/** create content (where the actual modification takes place) */
createContent: function () {
},
/** style the FormElement and show it */
show: function () {
this.style()
this.showForm()
},
/** show the FormElement */
showForm: function () {
this.options.styleEditorOptions.util.showElement(this.options.uiElement)
},
/** hide the FormElement */
hide: function () {
this.options.styleEditorOptions.util.hideElement(this.options.uiElement)
},
/** style the FormElement */
style: function () {
},
/** what to do when lost focus */
lostFocus: function () {
},
/** set style - used when the FormElement wants to change the styling option */
setStyle: function (value) {
let currentElement = this.options.styleEditorOptions.util.getCurrentElement()
// check whether a layer is part of a layerGroup
let layers = [currentElement]
if (currentElement instanceof L.LayerGroup) {
layers = Object.values(currentElement._layers)
}
// update layer (or all layers of a layerGroup)
for (let i = 0; i < layers.length; i++) {
let layer = layers[i]
if (layer instanceof L.Marker) {
this.options.styleEditorOptions.markerType.setStyle(this.options.styleOption, value)
} else {
let newStyle = {}
newStyle[this.options.styleOption] = value
layer.setStyle(newStyle)
layer.options[this.options.styleOption] = value
}
// fire event for changed layer
this.options.styleEditorOptions.util.fireChangeEvent(layer)
}
// notify form styling value has changed
this.options.parentForm.style()
}
})
}