-
Notifications
You must be signed in to change notification settings - Fork 419
Expand file tree
/
Copy pathAnnotationController.js
More file actions
364 lines (326 loc) · 12.8 KB
/
Copy pathAnnotationController.js
File metadata and controls
364 lines (326 loc) · 12.8 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
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
/*
* Copyright 2003-2006, 2009, 2017, 2020 United States Government, as represented
* by the Administrator of the National Aeronautics and Space Administration.
* All rights reserved.
*
* The NASAWorldWind/WebWorldWind platform is licensed under the Apache License,
* Version 2.0 (the "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License
* at http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software distributed
* under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
* CONDITIONS OF ANY KIND, either express or implied. See the License for the
* specific language governing permissions and limitations under the License.
*
* NASAWorldWind/WebWorldWind also contains the following 3rd party Open Source
* software:
*
* ES6-Promise – under MIT License
* libtess.js – SGI Free Software License B
* Proj4 – under MIT License
* JSZip – under MIT License
*
* A complete listing of 3rd Party software notices and licenses included in
* WebWorldWind can be found in the WebWorldWind 3rd-party notices and licenses
* PDF found in code directory.
*/
define(function () {
"use strict";
/**
* Constructs an annotation controller for a specified {@link WorldWindow}.
* @alias AnnotationController
* @constructor
* @classdesc Provides an annotation controller to interactively update DOM elements corresponding to a
* specific annotation
* @param {WorldWindow} worldWindow The WorldWindow to associate this annotation controller with. Used
* mainly for redrawing the wwd globe after changing settings.
*/
var AnnotationController = function (worldWindow) {
var self = this;
/**
* The WorldWindow associated with this annotation controller.
* @type {WorldWindow}
*/
this.worldWindow = worldWindow;
// Store the loaded annotation so we may read/modify
// its settings
this.currentAnnotation = null;
// Store DOM slider elements
this.opacitySlider = $("#opacitySlider");
this.scaleSlider = $("#scaleSlider");
this.cornerSlider = $("#cornerSlider");
this.leadWidthSlider = $("#leadWidthSlider");
this.leadHeightSlider = $("#leadHeightSlider");
this.backgroundR = $("#bgR");
this.backgroundG = $("#bgG");
this.backgroundB = $("#bgB");
this.textR = $("#textR");
this.textG = $("#textG");
this.textB = $("#textB");
// Store DOM spinner elements for the insets
this.spinnerLeft = $("#spinnerLeft");
this.spinnerRight = $("#spinnerRight");
this.spinnerTop = $("#spinnerTop");
this.spinnerBottom = $("#spinnerBottom");
// Store DOM input elements
this.text = $("#annotationText");
// Store DOM label elements
this.bgColorLabel = $("#bgColor");
this.textColorLabel = $("#textColor");
this.opacityLabel = $("#opacity");
this.scaleLabel = $("#scale");
this.cornerRadiusLabel = $("#cornerRadius");
this.leaderGapLabel = $("#leadSize");
// Create an event for the textbox so that we may update the
// annotation's label as the textbox contents change
this.text.on('input', function (e) {
self.currentAnnotation.text = this.value;
self.worldWindow.redraw();
});
this.opacitySlider.slider({
value: 0,
min: 0,
max: 1,
step: 0.1,
animate: true,
slide: function (event, ui) {
$("#opacity").html(ui.value);
self.currentAnnotation.attributes.opacity = ui.value;
}
});
this.scaleSlider.slider({
value: 1,
min: 0.70,
max: 2,
step: 0.1,
animate: true,
slide: function (event, ui) {
$("#scale").html(ui.value);
self.currentAnnotation.attributes.scale = ui.value;
}
});
this.cornerSlider.slider({
value: 1,
min: 0,
max: 30,
step: 1,
animate: true,
slide: function (event, ui) {
$("#cornerRadius").html(ui.value);
self.currentAnnotation.attributes.cornerRadius = ui.value;
}
});
// Width value of the lead (arrow)
this.leadWidthSlider.slider({
//value: 40,
min: 0,
max: 70,
step: 1,
animate: true,
slide: function (event, ui) {
self.changeLeadSize(
self.leadWidthSlider.slider('value'),
self.leadHeightSlider.slider('value'));
}
});
// Length value of the lead (arrow)
this.leadHeightSlider.slider({
//value: 30,
min: 0,
max: 100,
animate: true,
slide: function (event, ui) {
self.changeLeadSize(
self.leadWidthSlider.slider('value'),
self.leadHeightSlider.slider('value'));
}
});
// Red value of the background color
this.backgroundR.slider({
value: 0,
min: 0,
max: 255,
step: 1,
animate: true,
slide: function (event, ui) {
self.changeBackgroundColor(
self.backgroundR.slider('value'),
self.backgroundG.slider('value'),
self.backgroundB.slider('value'));
}
});
// Green value of the background color
this.backgroundG.slider({
value: 0,
min: 0,
max: 255,
animate: true,
slide: function (event, ui) {
self.changeBackgroundColor(
self.backgroundR.slider('value'),
self.backgroundG.slider('value'),
self.backgroundB.slider('value'));
}
});
// Blue value of the background color
this.backgroundB.slider({
value: 0,
min: 0,
max: 255,
animate: true,
slide: function (event, ui) {
self.changeBackgroundColor(
self.backgroundR.slider('value'),
self.backgroundG.slider('value'),
self.backgroundB.slider('value'));
}
});
// Red value of the text color
this.textR.slider({
value: 0,
min: 0,
max: 255,
animate: true,
slide: function (event, ui) {
self.changeTextColor(
self.textR.slider('value'),
self.textG.slider('value'),
self.textB.slider('value'));
}
});
// Green value of the text color
this.textG.slider({
value: 0,
min: 0,
max: 255,
animate: true,
slide: function (event, ui) {
self.changeTextColor(
self.textR.slider('value'),
self.textG.slider('value'),
self.textB.slider('value'));
}
});
// Blue value of the text color
this.textB.slider({
value: 0,
min: 0,
max: 255,
animate: true,
slide: function (event, ui) {
self.changeTextColor(
self.textR.slider('value'),
self.textG.slider('value'),
self.textB.slider('value'));
}
});
// Left inset spinner
this.spinnerLeft.spinner({
min: 0,
max: 100,
spin: function (event, ui) {
var insets = self.currentAnnotation.attributes.insets.clone();
insets.left = ui.value;
self.currentAnnotation.attributes.insets = insets;
self.worldWindow.redraw();
}
});
// Right inset spinner
this.spinnerRight.spinner({
min: 0,
max: 100,
spin: function (event, ui) {
var insets = self.currentAnnotation.attributes.insets.clone();
insets.right = ui.value;
self.currentAnnotation.attributes.insets = insets;
self.worldWindow.redraw();
}
});
// Top inset spinner
this.spinnerTop.spinner({
min: 0,
max: 100,
spin: function (event, ui) {
var insets = self.currentAnnotation.attributes.insets.clone();
insets.top = ui.value;
self.currentAnnotation.attributes.insets = insets;
self.worldWindow.redraw();
}
});
// Bottom inset spinner
this.spinnerBottom.spinner({
min: 0,
max: 100,
spin: function (event, ui) {
var insets = self.currentAnnotation.attributes.insets.clone();
insets.bottom = ui.value;
self.currentAnnotation.attributes.insets = insets;
self.worldWindow.redraw();
}
});
};
// Internal
AnnotationController.prototype.changeTextColor = function(r, g, b) {
this.textColorLabel.html("RGB(" + r + "," + g + "," + b + ")");
this.currentAnnotation.attributes.textAttributes.color = WorldWind.Color.colorFromBytes(r, g, b, 255);
this.worldWindow.redraw();
};
// Internal
AnnotationController.prototype.changeBackgroundColor = function(r, g, b) {
this.bgColorLabel.html("RGB(" + r + "," + g + "," + b + ")");
this.currentAnnotation.attributes.backgroundColor = WorldWind.Color.colorFromBytes(r, g, b, 255);
this.worldWindow.redraw();
};
// Internal
AnnotationController.prototype.changeLeadSize = function(width, height){
this.leaderGapLabel.html("width: " + width + " height: " + height);
this.currentAnnotation.attributes.leaderGapWidth = width;
this.currentAnnotation.attributes.leaderGapHeight = height;
this.worldWindow.redraw();
};
/**
* Loads an annotations and adjusts ui controls based on it's settings
* @param annotation
*/
AnnotationController.prototype.load = function (annotation) {
this.currentAnnotation = annotation;
var bgRed = annotation.attributes.backgroundColor.red * 255,
bgGreen = annotation.attributes.backgroundColor.green * 255,
bgBlue = annotation.attributes.backgroundColor.blue * 255,
textRed = annotation.attributes.textAttributes.color.red * 255,
textGreen = annotation.attributes.textAttributes.color.green * 255,
textBlue = annotation.attributes.textAttributes.color.blue * 255,
leadWidth = annotation.attributes.leaderGapWidth,
leadHeight = annotation.attributes.leaderGapHeight;
// Load background RGB sliders and format label based on values
this.backgroundR.slider('value', bgRed);
this.backgroundG.slider('value', bgGreen);
this.backgroundB.slider('value', bgBlue);
this.bgColorLabel.html("RGB(" + bgRed + "," + bgGreen + "," + bgBlue + ")");
// Load text RGB sliders and format label based on values
this.textR.slider('value', textRed);
this.textG.slider('value', textGreen);
this.textB.slider('value', textBlue);
this.textColorLabel.html("RGB(" + textRed + "," + textGreen + "," + textBlue + ")");
// Load leader size sliders and format label based on values
this.leadWidthSlider.slider('value', leadWidth);
this.leadHeightSlider.slider('value', leadHeight);
this.leaderGapLabel.html("width: " + leadWidth + " height: " + leadHeight);
// Load sliders settings and adjusts labels with their values
this.opacitySlider.slider('value', annotation.attributes.opacity);
this.scaleSlider.slider('value', annotation.attributes.scale);
this.cornerSlider.slider('value', annotation.attributes.cornerRadius);
this.opacityLabel.html(annotation.attributes.opacity);
this.scaleLabel.html(annotation.attributes.scale);
this.cornerRadiusLabel.html(annotation.attributes.cornerRadius);
// Load insets values into the spinners
this.spinnerBottom.val(annotation.attributes.insets.bottom);
this.spinnerTop.val(annotation.attributes.insets.top);
this.spinnerLeft.val(annotation.attributes.insets.left);
this.spinnerRight.val(annotation.attributes.insets.right);
//Load and display the text
this.text.val(annotation.text);
};
return AnnotationController;
});