This repository has been archived by the owner on Oct 6, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 32
/
Copy pathPolygonSymbol.js
66 lines (60 loc) · 2.18 KB
/
PolygonSymbol.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
import Symbol from './Symbol';
import lineSymbol from './LineSymbol';
export var PolygonSymbol = Symbol.extend({
statics: {
// not implemented: 'esriSFSBackwardDiagonal','esriSFSCross','esriSFSDiagonalCross','esriSFSForwardDiagonal','esriSFSHorizontal','esriSFSNull','esriSFSVertical'
POLYGONTYPES: ['esriSFSSolid']
},
initialize: function (symbolJson, options) {
Symbol.prototype.initialize.call(this, symbolJson, options);
if (symbolJson) {
if (symbolJson.outline && symbolJson.outline.style === 'esriSLSNull') {
this._lineStyles = { weight: 0 };
} else {
this._lineStyles = lineSymbol(symbolJson.outline, options).style();
}
this._fillStyles();
}
},
_fillStyles: function () {
if (this._lineStyles) {
if (this._lineStyles.weight === 0) {
// when weight is 0, setting the stroke to false can still look bad
// (gaps between the polygons)
this._styles.stroke = false;
} else {
// copy the line symbol styles into this symbol's styles
for (var styleAttr in this._lineStyles) {
this._styles[styleAttr] = this._lineStyles[styleAttr];
}
}
}
// set the fill for the polygon
if (this._symbolJson) {
if (this._symbolJson.color &&
// don't fill polygon if type is not supported
PolygonSymbol.POLYGONTYPES.indexOf(this._symbolJson.style >= 0)) {
this._styles.fill = true;
this._styles.fillColor = this.colorValue(this._symbolJson.color);
this._styles.fillOpacity = this.alphaValue(this._symbolJson.color);
} else {
this._styles.fill = false;
this._styles.fillOpacity = 0;
}
}
},
style: function (feature, visualVariables) {
if (!this._isDefault && visualVariables && visualVariables.colorInfo) {
var color = this.getColor(feature, visualVariables.colorInfo);
if (color) {
this._styles.fillColor = this.colorValue(color);
this._styles.fillOpacity = this.alphaValue(color);
}
}
return this._styles;
}
});
export function polygonSymbol (symbolJson, options) {
return new PolygonSymbol(symbolJson, options);
}
export default polygonSymbol;