forked from SuperMap/iClient-JavaScript
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCircleStyle.js
More file actions
97 lines (87 loc) · 3.33 KB
/
CircleStyle.js
File metadata and controls
97 lines (87 loc) · 3.33 KB
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
/* Copyright© 2000 - 2021 SuperMap Software Co.Ltd. All rights reserved.
* This program are made available under the terms of the Apache License, Version 2.0
* which accompanies this distribution and is available at http://www.apache.org/licenses/LICENSE-2.0.html.*/
import L from "leaflet";
import '../../core/Base';
/**
* @class L.supermap.circleStyle
* @classdesc 圆形要素风格。
* @category Visualization Graphic
* @extends {L.Class}
* @param {Object} options - 圆形要素风格参数。
* @param {boolean} [options.stroke=true] - 是否描边。
* @param {string} [options.color='#3388ff'] - 颜色。
* @param {number} [options.weight=1] - 线宽。
* @param {number} [options.opacity=1] - 透明度。
* @param {string} [options.lineCap='round'] - 线帽形状。
* @param {string} [options.lineJoin='round'] - 线条交汇边角形状。
* @param {boolean} [options.fill=false] - 是否填充。
* @param {string} [options.fillColor] - 填充色。
* @param {number} [options.fillOpacity=0.2] - 填充透明度。
* @param {string} [options.fillRule='evenodd'] - 填充形状。
* @param {number} [options.radius=3] - 半径。
*/
export var CircleStyle = L.Class.extend({
options: {
stroke: true,
color: '#3388ff',
weight: 1,
opacity: 1,
lineCap: 'round',
lineJoin: 'round',
fill: false,
fillColor: null,
fillOpacity: 0.2,
fillRule: 'evenodd',
radius: 3
},
initialize: function (options) {
options = options || {};
L.Util.setOptions(this, options);
this._canvas = document.createElement('canvas');
this._canvas.width = 2 * (this.options.radius + this.options.weight);
this._canvas.height = 2 * (this.options.radius + this.options.weight);
this._ctx = this._canvas.getContext('2d');
this._initStyle();
},
/**
* @deprecated
* @function L.supermap.circleStyle.prototype.getCanvas
* @description 获取画布,已弃用该设置,请使用 getStyle 接口。
*/
getCanvas: function () {
return this._canvas;
},
/**
* @function L.supermap.circleStyle.prototype.getStyle
* @description 获取画布。
*/
getStyle: function () {
return this._canvas;
},
_initStyle: function () {
this._ctx.beginPath();
this._ctx.arc(this._canvas.width / 2, this._canvas.height / 2, this.options.radius, 0, Math.PI * 2);
this._fillStroke();
},
_fillStroke: function () {
var options = this.options;
if (options.fill) {
this._ctx.globalAlpha = options.fillOpacity;
this._ctx.fillStyle = options.fillColor || options.color;
this._ctx.fill(options.fillRule || 'evenodd');
}
if (options.stroke && options.weight !== 0) {
this._ctx.globalAlpha = options.opacity;
this._ctx.lineWidth = options.weight;
this._ctx.strokeStyle = options.color;
this._ctx.lineCap = options.lineCap;
this._ctx.lineJoin = options.lineJoin;
this._ctx.stroke();
}
}
});
export var circleStyle = function (options) {
return new CircleStyle(options);
};
L.supermap.circleStyle = circleStyle;