ansel0926
2022-05-18 f0efddd9e32b9c5dc828401c4092be004b4826cf
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
define(function () {
    /**
     *
     *@param {Object} options
     *@param {Cesium.Color|String}[options.outlineColor=Cesium.Color.YELLOW] 线或边颜色,仅线、面数据有效。
     *@param {Cesium.Color|String}[options.fillColor=Cesium.Color.fromBytes(0, 255, 255, 30)] 填充颜色,仅面数据有效。
     *@param {Cesium.Color|String}[options.backgroundColor] 背景色
     *@param {Number}[options.lineWidth=1.5] 线宽,仅线数据有效。
     *@param {Boolean}[options.outline=true] 是否显示边,仅面数据有效。
     *@param {Boolean}[options.fill=true] 是否填充,仅面数据有效。
     *@param {Cesium.Color|String}[options.fontColor=Cesium.Color.BLACK] 注记文本颜色
     *@param {Number}[options.fontSize=16] 注记文本字体大小,仅在数据有点时有效。
     *@param {String}[options.fontFamily="宋体"] 注记文本字体名称,仅在数据有点时有效。
     *@param {Boolean}[options.labelStroke] 是否显示注记文本轮廓线,仅在数据有点时有效。
     *@param {String}[options.labelStrokeWidth=1] 注记文本轮廓线宽,仅在数据有点时有效。
     *@param {Cesium.Color|String}[options.labelStrokeColor] 注记文本轮廓线颜色,仅在数据有点时有效。
     * 
     *@param {Number}[options.pointSize=4] 注记点大小,仅在数据有点时有效。
     *@param {Cesium.Color|String}[options.pointColor=Cesium.Color.YELLOW] 注记点颜色,仅在数据有点时有效。
     *@param {String}[options.labelPropertyName='NAME'] 注记文本属性名称,仅在数据有点时有效。
     *@param {String}[options.makerImage=undefined] 注记点图标,如果设置点图标,则其他点样式参数无效,仅在数据有点时有效。
     *@param {Number}[options.ringRadius=2] 注记点样式为Ring时,圆心点大小(半径),仅在数据有点时有效。
     *@param {String}[options.pointStyle='Ring'] 注记点样式,仅在数据有点时有效。'Solid'为实心圆,'Ring'为带圆心的圆形,'Circle'为空心圆
     *@param {Number}[options.circleLineWidth=2] 注记点样式为Circle时,圆形线宽
     *@param {Boolean}[options.showMaker=true] 是否显示注记点,仅在数据有点时有效。
     *@param {Boolean}[options.showLabel=true] 是否显示文本,仅在数据有点时有效。
     *@param {Boolean}[options.showCenterLabel=true] 是否显示文本,仅对线和面数据有效。
     *@param {String}[options.centerLabelPropertyName] 几何中心注记文本属性名称,仅对线和面数据有效。
     *@param {Number}[options.labelOffsetX=10] 标注文本x方向偏移量,仅在数据有点时有效。以屏幕为参考,左上角为0,向右为正,单位为像素
     *@param {Number}[options.labelOffsetY=5] 标注文本y方向偏移量,仅在数据有点时有效。以屏幕为参考,左上角为0,向下为正,单位为像素 
     *@param {Array.<Number>}[options.lineDash=undefined] 虚线样式,不设置则为实线
     *@param {String}[options.lineCap="butt"] 设置线条末端线帽的样式。 butt——默认。向线条的每个末端添加平直的边缘;round——向线条的每个末端添加圆形线帽;square——向线条的每个末端添加正方形线帽。
     *@param {String}[options.shadowColor=undefined] 设置用于阴影的颜色
     *@param {Number}[options.shadowBlur=undefined] 设置用于阴影的模糊级别
     *@param {Number}[options.shadowOffsetX=undefined] 设置阴影距形状的水平距离
     *@param {Number}[options.shadowOffsetY=undefined] 设置阴影距形状的垂直距离
     *@param {String}[options.lineJoin="miter"] 设置当两条线交汇时所创建边角的类型。bevel——斜角;round——创建圆角;miter——默认。创建尖角。
     *@param {Number}[options.miterLimit=10] 设置最大斜接长度。
     *@memberof Cesium
     *@constructor 
     */
    function VectorStyle(options) {
        //*@param {Number}[options.lineOffset=undefined] 双线样式参数,两线间距,单位为米(m)。不设置则为单线
    
        if (typeof document == 'undefined') {
            return options;
        }
        options = Cesium.defaultValue(options, Cesium.defaultValue.EMPTY_OBJECT);
        //面样式
        this.fillColor = Cesium.defaultValue(options.fillColor, Cesium.Color.fromBytes(0, 255, 255, 30));
        if (typeof this.fillColor == 'string') {
            this.fillColor = Cesium.Color.fromCssColorString(this.fillColor);
        }
        this.fill = Cesium.defaultValue(options.fill, true);
 
        this.labelStroke = options.labelStroke;
        this.labelStrokeWidth = Cesium.defaultValue(options.labelStrokeWidth, 1);
        this.labelStrokeColor = Cesium.defaultValue(options.labelStrokeColor, Cesium.Color.fromBytes(160, 99, 57));
        if (typeof this.labelStrokeColor == 'string') {
            this.labelStrokeColor = Cesium.Color.fromCssColorString(this.labelStrokeColor);
        }
        //线样式
        this.outlineColor = Cesium.defaultValue(options.outlineColor, Cesium.Color.YELLOW);
        if (typeof this.outlineColor == 'string') {
            this.outlineColor = Cesium.Color.fromCssColorString(this.outlineColor);
        }
        this.backgroundColor = options.backgroundColor;
        if (typeof this.backgroundColor == 'string') {
            this.backgroundColor = Cesium.Color.fromCssColorString(this.backgroundColor);
        }
 
        this.lineWidth = Cesium.defaultValue(options.lineWidth, 1.5);
        this.outline = Cesium.defaultValue(options.outline, true);
 
        //注记样式
        this.fontColor = Cesium.defaultValue(options.fontColor, Cesium.Color.BLACK);
        if (typeof this.fontColor == 'string') {
            this.fontColor = Cesium.Color.fromCssColorString(this.fontColor);
        }
 
        this.fontSize = Cesium.defaultValue(options.fontSize, 16);
        this.fontFamily = Cesium.defaultValue(options.fontFamily, "宋体");
        this.pointSize = Cesium.defaultValue(options.pointSize, 4);
        this.pointColor = Cesium.defaultValue(options.pointColor, Cesium.Color.YELLOW);
        if (typeof this.pointColor == 'string') {
            this.pointColor = Cesium.Color.fromCssColorString(this.pointColor);
        }
 
        this.pointStyle = Cesium.defaultValue(options.pointStyle, 'Ring');//'Solid','Ring','Circle'
        this.labelPropertyName = Cesium.defaultValue(options.labelPropertyName, 'NAME');
        this.ringRadius = Cesium.defaultValue(options.ringRadius, 2);
        this.circleLineWidth = Cesium.defaultValue(options.circleLineWidth, 2);
        this.showMaker = Cesium.defaultValue(options.showMaker, true);
        this.showLabel = Cesium.defaultValue(options.showLabel, true);
         
        this.showCenterLabel = Cesium.defaultValue(options.showCenterLabel, false);
        this.centerLabelPropertyName = options.centerLabelPropertyName;
 
        this.labelOffsetX = Cesium.defaultValue(options.labelOffsetX, 0);
        this.labelOffsetY = Cesium.defaultValue(options.labelOffsetY, 0);
        this.makerImage = options.makerImage;
 
        this.lineDash = options.lineDash;
        //this.lineOffset = options.lineOffset;
        this.lineCap = Cesium.defaultValue(options.lineCap, "butt");
        this.lineJoin = Cesium.defaultValue(options.lineJoin, "miter");
        this.shadowColor = options.shadowColor;
         
        this.shadowBlur = options.shadowBlur;
        this.shadowOffsetX = options.shadowOffsetX;
        this.shadowOffsetY = options.shadowOffsetY;
        this.miterLimit = Cesium.defaultValue(options.miterLimit, 10);
 
        this.makerImageEl = null;
        var makerImagePromise = null;
        this.readyPromise = Cesium.when.defer();
        var that = this;
        if (typeof this.makerImage == 'string') {
 
            var image = new Image();
            image.onload = function () {
                that.makerImageEl = this;
                that.readyPromise.resolve(true);
            }
            image.onerror = function (err) {
                that.readyPromise.reject(err);
            }
            image.src = this.makerImage;
        } else {
            if (this.makerImage instanceof Image) {
                this.makerImageEl = this.makerImage;
            }
            setTimeout(function () {
 
                that.readyPromise.resolve(true);
            }, 10)
        }
 
    }
 
    /**
    *
    *@return {Cesium.VectorStyle}
    */
    VectorStyle.prototype.clone = function () {
        var style = new VectorStyle();
        for (var i in this) {
 
            if (this.hasOwnProperty(i)) {
                if (this[i] instanceof Cesium.Color) {
                    style[i] = Cesium.Color.clone(this[i]);
                } else {
                    style[i] = this[i];
                }
            }
        }
        return style;
    }
 
    /**
    *
    *@type {Cesium.VectorStyle}
    */
    VectorStyle.Default = new VectorStyle();
 
    return VectorStyle;
})