CircleMarker
export var CircleMarker = Path.extend({
options: {
fill: true,
radius: 10,
},
initialize: function (latlng, options) {
Util.setOptions(this, options);
this._latlng = toLatLng(latlng);
this._radius = this.options.radius;
},
setLatLng: function (latlng) {
var oldLatLng = this._latlng;
this._latlng = toLatLng(latlng);
this.redraw();
return this.fire("move", { oldLatLng: oldLatLng, latlng: this._latlng });
},
getLatLng: function () {
return this._latlng;
},
setRadius: function (radius) {
this.options.radius = this._radius = radius;
return this.redraw();
},
getRadius: function () {
return this._radius;
},
setStyle: function (options) {
var radius = (options && options.radius) || this._radius;
Path.prototype.setStyle.call(this, options);
this.setRadius(radius);
return this;
},
_project: function () {
this._point = this._map.latLngToLayerPoint(this._latlng);
this._updateBounds();
},
_updateBounds: function () {
var r = this._radius,
r2 = this._radiusY || r,
w = this._clickTolerance(),
p = [r + w, r2 + w];
this._pxBounds = new Bounds(this._point.subtract(p), this._point.add(p));
},
_update: function () {
if (this._map) {
this._updatePath();
}
},
_updatePath: function () {
this._renderer._updateCircle(this);
},
_empty: function () {
return this._radius && !this._renderer._bounds.intersects(this._pxBounds);
},
_containsPoint: function (p) {
return p.distanceTo(this._point) <= this._radius + this._clickTolerance();
},
});
export function circleMarker(latlng, options) {
return new CircleMarker(latlng, options);
}
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
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
编辑 (opens new window)
上次更新: 2025/04/15, 08:40:23