| 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
365
366 | 1
1
1
1
1
1
1
1
1
1
1
230
230
230
230
230
230
230
230
230
230
230
1
1
133
1
133
1
135
1
126
126
126
126
126
126
126
126
126
126
126
1
1
1
128
1
130
1
130
1
132
1
133
1
1
159
1
9
1
9
1
11
1
1
1
6
1
6
1
10
1
9
1
18
| goog.provide('ol.layer.Base');
goog.provide('ol.layer.LayerProperty');
goog.provide('ol.layer.LayerState');
goog.require('goog.events');
goog.require('goog.math');
goog.require('goog.object');
goog.require('ol.Object');
goog.require('ol.source.State');
/**
* @enum {string}
*/
ol.layer.LayerProperty = {
BRIGHTNESS: 'brightness',
CONTRAST: 'contrast',
HUE: 'hue',
OPACITY: 'opacity',
SATURATION: 'saturation',
VISIBLE: 'visible',
EXTENT: 'extent',
MAX_RESOLUTION: 'maxResolution',
MIN_RESOLUTION: 'minResolution',
SOURCE: 'source'
};
/**
* @typedef {{layer: ol.layer.Layer,
* brightness: number,
* contrast: number,
* hue: number,
* opacity: number,
* saturation: number,
* sourceState: ol.source.State,
* visible: boolean,
* extent: (ol.Extent|undefined),
* maxResolution: number,
* minResolution: number}}
*/
ol.layer.LayerState;
/**
* @classdesc
* Abstract base class; normally only used for creating subclasses and not
* instantiated in apps.
* Note that with `ol.layer.Base` and all its subclasses, any property set in
* the options is set as a {@link ol.Object} property on the layer object, so
* is observable, and has get/set accessors.
*
* @constructor
* @extends {ol.Object}
* @param {olx.layer.BaseOptions} options Layer options.
* @api stable
*/
ol.layer.Base = function(options) {
goog.base(this);
/**
* @type {Object.<string, *>}
*/
var properties = goog.object.clone(options);
properties[ol.layer.LayerProperty.BRIGHTNESS] =
goog.isDef(options.brightness) ? options.brightness : 0;
properties[ol.layer.LayerProperty.CONTRAST] =
goog.isDef(options.contrast) ? options.contrast : 1;
properties[ol.layer.LayerProperty.HUE] =
goog.isDef(options.hue) ? options.hue : 0;
properties[ol.layer.LayerProperty.OPACITY] =
goog.isDef(options.opacity) ? options.opacity : 1;
properties[ol.layer.LayerProperty.SATURATION] =
goog.isDef(options.saturation) ? options.saturation : 1;
properties[ol.layer.LayerProperty.VISIBLE] =
goog.isDef(options.visible) ? options.visible : true;
properties[ol.layer.LayerProperty.MAX_RESOLUTION] =
goog.isDef(options.maxResolution) ? options.maxResolution : Infinity;
properties[ol.layer.LayerProperty.MIN_RESOLUTION] =
goog.isDef(options.minResolution) ? options.minResolution : 0;
this.setProperties(properties);
};
goog.inherits(ol.layer.Base, ol.Object);
/**
* Return the brightness of the layer.
* @return {number} The brightness of the layer.
* @observable
* @api
*/
ol.layer.Base.prototype.getBrightness = function() {
return /** @type {number} */ (this.get(ol.layer.LayerProperty.BRIGHTNESS));
};
/**
* Return the contrast of the layer.
* @return {number} The contrast of the layer.
* @observable
* @api
*/
ol.layer.Base.prototype.getContrast = function() {
return /** @type {number} */ (this.get(ol.layer.LayerProperty.CONTRAST));
};
/**
* Return the hue of the layer.
* @return {number} The hue of the layer.
* @observable
* @api
*/
ol.layer.Base.prototype.getHue = function() {
return /** @type {number} */ (this.get(ol.layer.LayerProperty.HUE));
};
/**
* @return {ol.layer.LayerState} Layer state.
*/
ol.layer.Base.prototype.getLayerState = function() {
var brightness = this.getBrightness();
var contrast = this.getContrast();
var hue = this.getHue();
var opacity = this.getOpacity();
var saturation = this.getSaturation();
var sourceState = this.getSourceState();
var visible = this.getVisible();
var extent = this.getExtent();
var maxResolution = this.getMaxResolution();
var minResolution = this.getMinResolution();
return {
layer: /** @type {ol.layer.Layer} */ (this),
brightness: goog.math.clamp(brightness, -1, 1),
contrast: Math.max(contrast, 0),
hue: hue,
opacity: goog.math.clamp(opacity, 0, 1),
saturation: Math.max(saturation, 0),
sourceState: sourceState,
visible: visible,
extent: extent,
maxResolution: maxResolution,
minResolution: Math.max(minResolution, 0)
};
};
/**
* @param {Array.<ol.layer.Layer>=} opt_array Array of layers (to be
* modified in place).
* @return {Array.<ol.layer.Layer>} Array of layers.
*/
ol.layer.Base.prototype.getLayersArray = goog.abstractMethod;
/**
* @param {Array.<ol.layer.LayerState>=} opt_states Optional list of layer
* states (to be modified in place).
* @return {Array.<ol.layer.LayerState>} List of layer states.
*/
ol.layer.Base.prototype.getLayerStatesArray = goog.abstractMethod;
/**
* Return the {@link ol.Extent extent} of the layer or `undefined` if it
* will be visible regardless of extent.
* @return {ol.Extent|undefined} The layer extent.
* @observable
* @api stable
*/
ol.layer.Base.prototype.getExtent = function() {
return /** @type {ol.Extent|undefined} */ (
this.get(ol.layer.LayerProperty.EXTENT));
};
/**
* Return the maximum resolution of the layer.
* @return {number} The maximum resolution of the layer.
* @observable
* @api stable
*/
ol.layer.Base.prototype.getMaxResolution = function() {
return /** @type {number} */ (
this.get(ol.layer.LayerProperty.MAX_RESOLUTION));
};
/**
* Return the minimum resolution of the layer.
* @return {number} The minimum resolution of the layer.
* @observable
* @api stable
*/
ol.layer.Base.prototype.getMinResolution = function() {
return /** @type {number} */ (
this.get(ol.layer.LayerProperty.MIN_RESOLUTION));
};
/**
* Return the opacity of the layer (between 0 and 1).
* @return {number} The opacity of the layer.
* @observable
* @api stable
*/
ol.layer.Base.prototype.getOpacity = function() {
return /** @type {number} */ (this.get(ol.layer.LayerProperty.OPACITY));
};
/**
* Return the saturation of the layer.
* @return {number} The saturation of the layer.
* @observable
* @api
*/
ol.layer.Base.prototype.getSaturation = function() {
return /** @type {number} */ (this.get(ol.layer.LayerProperty.SATURATION));
};
/**
* @return {ol.source.State} Source state.
*/
ol.layer.Base.prototype.getSourceState = goog.abstractMethod;
/**
* Return the visibility of the layer (`true` or `false`).
* @return {boolean} The visibility of the layer.
* @observable
* @api stable
*/
ol.layer.Base.prototype.getVisible = function() {
return /** @type {boolean} */ (this.get(ol.layer.LayerProperty.VISIBLE));
};
/**
* Adjust the layer brightness. A value of -1 will render the layer completely
* black. A value of 0 will leave the brightness unchanged. A value of 1 will
* render the layer completely white. Other values are linear multipliers on
* the effect (values are clamped between -1 and 1).
*
* The filter effects draft [1] says the brightness function is supposed to
* render 0 black, 1 unchanged, and all other values as a linear multiplier.
*
* The current WebKit implementation clamps values between -1 (black) and 1
* (white) [2]. There is a bug open to change the filter effect spec [3].
*
* TODO: revisit this if the spec is still unmodified before we release
*
* [1] https://dvcs.w3.org/hg/FXTF/raw-file/tip/filters/index.html
* [2] https://github.com/WebKit/webkit/commit/8f4765e569
* [3] https://www.w3.org/Bugs/Public/show_bug.cgi?id=15647
*
* @param {number} brightness The brightness of the layer.
* @observable
* @api
*/
ol.layer.Base.prototype.setBrightness = function(brightness) {
this.set(ol.layer.LayerProperty.BRIGHTNESS, brightness);
};
/**
* Adjust the layer contrast. A value of 0 will render the layer completely
* grey. A value of 1 will leave the contrast unchanged. Other values are
* linear multipliers on the effect (and values over 1 are permitted).
*
* @param {number} contrast The contrast of the layer.
* @observable
* @api
*/
ol.layer.Base.prototype.setContrast = function(contrast) {
this.set(ol.layer.LayerProperty.CONTRAST, contrast);
};
/**
* Apply a hue-rotation to the layer. A value of 0 will leave the hue
* unchanged. Other values are radians around the color circle.
* @param {number} hue The hue of the layer.
* @observable
* @api
*/
ol.layer.Base.prototype.setHue = function(hue) {
this.set(ol.layer.LayerProperty.HUE, hue);
};
/**
* Set the extent at which the layer is visible. If `undefined`, the layer
* will be visible at all extents.
* @param {ol.Extent|undefined} extent The extent of the layer.
* @observable
* @api stable
*/
ol.layer.Base.prototype.setExtent = function(extent) {
this.set(ol.layer.LayerProperty.EXTENT, extent);
};
/**
* Set the maximum resolution at which the layer is visible.
* @param {number} maxResolution The maximum resolution of the layer.
* @observable
* @api stable
*/
ol.layer.Base.prototype.setMaxResolution = function(maxResolution) {
this.set(ol.layer.LayerProperty.MAX_RESOLUTION, maxResolution);
};
/**
* Set the minimum resolution at which the layer is visible.
* @param {number} minResolution The minimum resolution of the layer.
* @observable
* @api stable
*/
ol.layer.Base.prototype.setMinResolution = function(minResolution) {
this.set(ol.layer.LayerProperty.MIN_RESOLUTION, minResolution);
};
/**
* Set the opacity of the layer, allowed values range from 0 to 1.
* @param {number} opacity The opacity of the layer.
* @observable
* @api stable
*/
ol.layer.Base.prototype.setOpacity = function(opacity) {
this.set(ol.layer.LayerProperty.OPACITY, opacity);
};
/**
* Adjust layer saturation. A value of 0 will render the layer completely
* unsaturated. A value of 1 will leave the saturation unchanged. Other
* values are linear multipliers of the effect (and values over 1 are
* permitted).
*
* @param {number} saturation The saturation of the layer.
* @observable
* @api
*/
ol.layer.Base.prototype.setSaturation = function(saturation) {
this.set(ol.layer.LayerProperty.SATURATION, saturation);
};
/**
* Set the visibility of the layer (`true` or `false`).
* @param {boolean} visible The visibility of the layer.
* @observable
* @api stable
*/
ol.layer.Base.prototype.setVisible = function(visible) {
this.set(ol.layer.LayerProperty.VISIBLE, visible);
};
|