forked from gee-community/geemap
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathvector_layer_editor.ts
More file actions
261 lines (238 loc) · 9.77 KB
/
vector_layer_editor.ts
File metadata and controls
261 lines (238 loc) · 9.77 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
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
import { css, html, LitElement, nothing, TemplateResult } from "lit";
import { property, query } from "lit/decorators.js";
import { ColorPicker } from "./color_picker";
import { legacyStyles } from "./ipywidgets_styles";
import { LegendCustomization } from "./legend_customization";
import { PaletteEditor } from "./palette_editor";
import { flexStyles } from "./styles";
import { renderSelect } from "./utils";
import "./palette_editor";
export class VectorLayerEditor extends LitElement {
static get componentName() {
return `vector-layer-editor`;
}
static override styles = [
flexStyles,
legacyStyles,
css`
.style-by-attribute-checkbox {
vertical-align: middle;
}
`,
];
static pointShapes: Array<string> = [
"circle",
"square",
"diamond",
"cross",
"plus",
"pentagram",
"hexagram",
"triangle",
"triangle_up",
"triangle_down",
"triangle_left",
"triangle_right",
"pentagon",
"hexagon",
"star5",
"star6",
];
static lineTypes: Array<string> = [
"solid",
"dotted",
"dashed",
];
@property({ type: Array }) colormaps: Array<string> = [];
@property({ type: String }) newLayerName: string = "";
@property({ type: Number }) opacity: number = 1.0;
@property({ type: Number }) pointSize: number = 3.0;
@property({ type: String }) pointShape: string = VectorLayerEditor.pointShapes[0];
@property({ type: Number }) lineWidth: number = 2.0;
@property({ type: String }) lineType: string = VectorLayerEditor.lineTypes[0];
@property({ type: Number }) fillOpacity: number = 1.0;
@property({ type: Boolean }) shouldStyleByAttribute: boolean = false;
@property({ type: Array }) fields: Array<string> = [];
@property({ type: String }) selectedField: string = "";
@property({ type: Array }) fieldValues: Array<string> = [];
@property({ type: String }) selectedFieldValue: string = "";
@query("palette-editor") paletteEditor?: PaletteEditor;
@query("legend-customization") legendCustomization?: LegendCustomization;
@query("#color-picker") colorPicker!: ColorPicker;
@query("#fill-color-picker") fillColorPicker!: ColorPicker;
getVisualizationOptions(): any {
let visParams = {
layerName: this.newLayerName,
color: this.colorPicker.value,
opacity: this.opacity,
pointSize: this.pointSize,
pointShape: this.pointShape,
lineWidth: this.lineWidth,
lineType: this.lineType,
fillColor: this.fillColorPicker.value,
fillOpacity: this.fillOpacity,
shouldStyleByAttribute: this.shouldStyleByAttribute,
} as any;
if (this.shouldStyleByAttribute) {
visParams.palette = this.paletteEditor?.paletteTokens ?? [];
visParams.field = this.selectedField;
}
if (this.legendCustomization) {
visParams.legend = this.legendCustomization.getLegendData();
}
return visParams;
}
override render() {
return html`
<div class="vertical-flex">
<div class="horizontal-flex">
<span class="legacy-text">New layer name:</span>
<input
type="text"
class="legacy-text-input"
id="new-layer-name"
name="new-layer-name"
.value="${this.newLayerName}"
@change="${this.onNewLayerNameChanged}"
/>
</div>
<div class="horizontal-flex">
<color-picker id="color-picker"></color-picker>
<span class="legacy-text">Opacity:</span>
<input
type="range"
class="legacy-slider"
id="opacity"
name="opacity"
min="0"
max="1.0"
step="0.01"
.value=${this.opacity}
@input=${this.onOpacityChanged}
/>
<span class="legacy-text">${this.opacity.toFixed(2)}</span>
</div>
<div class="horizontal-flex">
<span class="legacy-text">Point size:</span>
<input
type="number"
class="legacy-text-input"
id="point-size"
name="point-size"
min="1"
max="50"
.value="${this.pointSize}"
@change="${this.onPointSizeChanged}"
/>
<span class="legacy-text">Point shape:</span>
${renderSelect(VectorLayerEditor.pointShapes, this.pointShape, this.onPointShapeChanged)}
</div>
<div class="horizontal-flex">
<span class="legacy-text">Line width:</span>
<input
type="number"
class="legacy-text-input"
id="line-width"
name="line-width"
min="1"
max="50"
.value="${this.lineWidth}"
@change="${this.onLineWidthChanged}"
/>
<span class="legacy-text">Line type:</span>
${renderSelect(VectorLayerEditor.lineTypes, this.lineType, this.onLineTypeChanged)}
</div>
<div class="horizontal-flex">
<span class="legacy-text">Fill:</span>
<color-picker id="fill-color-picker"></color-picker>
<span class="legacy-text">Opacity:</span>
<input
type="range"
class="legacy-slider"
id="fill-opacity"
name="fill-opacity"
min="0"
max="1.0"
step="0.01"
.value=${this.fillOpacity}
@input=${this.onFillOpacityChanged}
/>
<span class="legacy-text">${this.fillOpacity.toFixed(2)}</span>
</div>
<div class="horizontal-flex">
<span>
<input
class="style-by-attribute-checkbox"
type="checkbox"
.checked="${this.shouldStyleByAttribute}"
@change="${this.onShouldStyleByAttributeChanged}"
/>
<span class="legacy-text all-layers-text"
>Style by attribute</span
>
</span>
</div>
${this.renderStyleByAttributeSettings()}
${this.renderLegendCustomization()}
</div>
`;
}
private renderStyleByAttributeSettings(): TemplateResult | typeof nothing {
if (!this.shouldStyleByAttribute) {
return nothing;
}
return html`
<div class="horizontal-flex">
<span class="legacy-text">Field:</span>
${renderSelect(this.fields, this.selectedField, this.onStyleAttributeChanged)}
<span class="legacy-text">Values:</span>
${renderSelect(this.fieldValues, this.selectedFieldValue, this.onValueChanged)}
</div>
<palette-editor .colormaps="${this.colormaps}">
<slot></slot>
</palette-editor>
`;
}
private renderLegendCustomization(): TemplateResult | typeof nothing {
if (this.shouldStyleByAttribute) {
return html`<legend-customization></legend-customization>`;
}
return nothing;
}
private onNewLayerNameChanged(event: Event): void {
this.newLayerName = (event.target as HTMLInputElement).value;
}
private onOpacityChanged(event: Event): void {
this.opacity = (event.target as HTMLInputElement).valueAsNumber;
}
private onPointSizeChanged(event: Event): void {
this.pointSize = (event.target as HTMLInputElement).valueAsNumber;
}
private onPointShapeChanged(event: Event): void {
this.pointShape = (event.target as HTMLInputElement).value;
}
private onLineWidthChanged(event: Event): void {
this.lineWidth = (event.target as HTMLInputElement).valueAsNumber;
}
private onLineTypeChanged(event: Event): void {
this.lineType = (event.target as HTMLInputElement).value;
}
private onFillOpacityChanged(event: Event): void {
this.fillOpacity = (event.target as HTMLInputElement).valueAsNumber;
}
private onShouldStyleByAttributeChanged(event: Event): void {
this.shouldStyleByAttribute = (event.target as HTMLInputElement).checked;
this.dispatchEvent(new CustomEvent("calculate-fields", {}));
}
private onStyleAttributeChanged(event: Event): void {
this.selectedField = (event.target as HTMLInputElement).value;
this.dispatchEvent(new CustomEvent("calculate-field-values", {}));
}
private onValueChanged(event: Event): void {
this.selectedFieldValue = (event.target as HTMLInputElement).value;
}
}
// Without this check, there's a component registry issue when developing locally.
if (!customElements.get(VectorLayerEditor.componentName)) {
customElements.define(VectorLayerEditor.componentName, VectorLayerEditor);
}