/
vectorlayer.js
186 lines (152 loc) · 4.86 KB
/
vectorlayer.js
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
goog.provide('ol.layer.Vector');
goog.require('goog.asserts');
goog.require('ol');
goog.require('ol.layer.Layer');
goog.require('ol.object');
goog.require('ol.style.Style');
/**
* @enum {string}
*/
ol.layer.VectorProperty = {
RENDER_ORDER: 'renderOrder'
};
/**
* @classdesc
* Vector data that is rendered client-side.
* Note that any property set in the options is set as a {@link ol.Object}
* property on the layer object; for example, setting `title: 'My Title'` in the
* options means that `title` is observable, and has get/set accessors.
*
* @constructor
* @extends {ol.layer.Layer}
* @fires ol.render.Event
* @param {olx.layer.VectorOptions=} opt_options Options.
* @api stable
*/
ol.layer.Vector = function(opt_options) {
var options = opt_options ?
opt_options : /** @type {olx.layer.VectorOptions} */ ({});
goog.asserts.assert(
options.renderOrder === undefined || !options.renderOrder ||
typeof options.renderOrder === 'function',
'renderOrder must be a comparator function');
var baseOptions = ol.object.assign({}, options);
delete baseOptions.style;
delete baseOptions.renderBuffer;
delete baseOptions.updateWhileAnimating;
delete baseOptions.updateWhileInteracting;
ol.layer.Layer.call(this, /** @type {olx.layer.LayerOptions} */ (baseOptions));
/**
* @type {number}
* @private
*/
this.renderBuffer_ = options.renderBuffer !== undefined ?
options.renderBuffer : 100;
/**
* User provided style.
* @type {ol.style.Style|Array.<ol.style.Style>|ol.StyleFunction}
* @private
*/
this.style_ = null;
/**
* Style function for use within the library.
* @type {ol.StyleFunction|undefined}
* @private
*/
this.styleFunction_ = undefined;
this.setStyle(options.style);
/**
* @type {boolean}
* @private
*/
this.updateWhileAnimating_ = options.updateWhileAnimating !== undefined ?
options.updateWhileAnimating : false;
/**
* @type {boolean}
* @private
*/
this.updateWhileInteracting_ = options.updateWhileInteracting !== undefined ?
options.updateWhileInteracting : false;
};
ol.inherits(ol.layer.Vector, ol.layer.Layer);
/**
* @return {number|undefined} Render buffer.
*/
ol.layer.Vector.prototype.getRenderBuffer = function() {
return this.renderBuffer_;
};
/**
* @return {function(ol.Feature, ol.Feature): number|null|undefined} Render
* order.
*/
ol.layer.Vector.prototype.getRenderOrder = function() {
return /** @type {function(ol.Feature, ol.Feature):number|null|undefined} */ (
this.get(ol.layer.VectorProperty.RENDER_ORDER));
};
/**
* Return the associated {@link ol.source.Vector vectorsource} of the layer.
* @function
* @return {ol.source.Vector} Source.
* @api stable
*/
ol.layer.Vector.prototype.getSource;
/**
* Get the style for features. This returns whatever was passed to the `style`
* option at construction or to the `setStyle` method.
* @return {ol.style.Style|Array.<ol.style.Style>|ol.StyleFunction}
* Layer style.
* @api stable
*/
ol.layer.Vector.prototype.getStyle = function() {
return this.style_;
};
/**
* Get the style function.
* @return {ol.StyleFunction|undefined} Layer style function.
* @api stable
*/
ol.layer.Vector.prototype.getStyleFunction = function() {
return this.styleFunction_;
};
/**
* @return {boolean} Whether the rendered layer should be updated while
* animating.
*/
ol.layer.Vector.prototype.getUpdateWhileAnimating = function() {
return this.updateWhileAnimating_;
};
/**
* @return {boolean} Whether the rendered layer should be updated while
* interacting.
*/
ol.layer.Vector.prototype.getUpdateWhileInteracting = function() {
return this.updateWhileInteracting_;
};
/**
* @param {function(ol.Feature, ol.Feature):number|null|undefined} renderOrder
* Render order.
*/
ol.layer.Vector.prototype.setRenderOrder = function(renderOrder) {
goog.asserts.assert(
renderOrder === undefined || !renderOrder ||
typeof renderOrder === 'function',
'renderOrder must be a comparator function');
this.set(ol.layer.VectorProperty.RENDER_ORDER, renderOrder);
};
/**
* Set the style for features. This can be a single style object, an array
* of styles, or a function that takes a feature and resolution and returns
* an array of styles. If it is `undefined` the default style is used. If
* it is `null` the layer has no style (a `null` style), so only features
* that have their own styles will be rendered in the layer. See
* {@link ol.style} for information on the default style.
* @param {ol.style.Style|Array.<ol.style.Style>|ol.StyleFunction|null|undefined}
* style Layer style.
* @api stable
*/
ol.layer.Vector.prototype.setStyle = function(style) {
this.style_ = style !== undefined ? style : ol.style.defaultStyleFunction;
this.styleFunction_ = style === null ?
undefined : ol.style.createStyleFunction(this.style_);
this.changed();
};