/
style.js
76 lines (64 loc) · 1.97 KB
/
style.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
goog.provide('ol.style.Style');
goog.require('ol.Feature');
goog.require('ol.geom.GeometryType');
goog.require('ol.style.Rule');
goog.require('ol.style.SymbolizerLiteral');
/**
* @typedef {{rules: (Array.<ol.style.Rule>)}}
*/
ol.style.StyleOptions;
/**
* @constructor
* @param {ol.style.StyleOptions} options Style options.
*/
ol.style.Style = function(options) {
/**
* @type {Array.<ol.style.Rule>}
* @private
*/
this.rules_ = goog.isDef(options.rules) ? options.rules : [];
};
/**
* @param {ol.Feature} feature Feature.
* @return {Array.<ol.style.SymbolizerLiteral>} Symbolizer literals for the
* feature.
*/
ol.style.Style.prototype.apply = function(feature) {
var rules = this.rules_,
literals = [],
rule, symbolizers;
for (var i = 0, ii = rules.length; i < ii; ++i) {
rule = rules[i];
if (rule.applies(feature)) {
symbolizers = rule.getSymbolizers();
for (var j = 0, jj = symbolizers.length; j < jj; ++j) {
literals.push(symbolizers[j].createLiteral(feature));
}
}
}
return literals;
};
/**
* @param {ol.Feature} feature Feature.
* @return {Array.<ol.style.SymbolizerLiteral>} Default symbolizer literals for
* the feature.
*/
ol.style.Style.applyDefaultStyle = function(feature) {
var geometry = feature.getGeometry(),
symbolizerLiterals = [];
if (!goog.isNull(geometry)) {
var type = geometry.getType();
if (type === ol.geom.GeometryType.POINT ||
type === ol.geom.GeometryType.MULTIPOINT) {
symbolizerLiterals.push(ol.style.ShapeDefaults);
} else if (type === ol.geom.GeometryType.LINESTRING ||
type === ol.geom.GeometryType.MULTILINESTRING) {
symbolizerLiterals.push(ol.style.LineDefaults);
} else if (type === ol.geom.GeometryType.LINEARRING ||
type === ol.geom.GeometryType.POLYGON ||
type === ol.geom.GeometryType.MULTIPOLYGON) {
symbolizerLiterals.push(ol.style.PolygonDefaults);
}
}
return symbolizerLiterals;
};