|
1 L.Edit = L.Edit || {}; |
|
2 /** |
|
3 * @class L.Edit.Circle |
|
4 * @aka Edit.Circle |
|
5 * @inherits L.Edit.SimpleShape |
|
6 */ |
|
7 L.Edit.Circle = L.Edit.SimpleShape.extend({ |
|
8 _createMoveMarker: function () { |
|
9 var center = this._shape.getLatLng(); |
|
10 |
|
11 this._moveMarker = this._createMarker(center, this.options.moveIcon); |
|
12 }, |
|
13 |
|
14 _createResizeMarker: function () { |
|
15 var center = this._shape.getLatLng(), |
|
16 resizemarkerPoint = this._getResizeMarkerPoint(center); |
|
17 |
|
18 this._resizeMarkers = []; |
|
19 this._resizeMarkers.push(this._createMarker(resizemarkerPoint, this.options.resizeIcon)); |
|
20 }, |
|
21 |
|
22 _getResizeMarkerPoint: function (latlng) { |
|
23 // From L.shape.getBounds() |
|
24 var delta = this._shape._radius * Math.cos(Math.PI / 4), |
|
25 point = this._map.project(latlng); |
|
26 return this._map.unproject([point.x + delta, point.y - delta]); |
|
27 }, |
|
28 |
|
29 _move: function (latlng) { |
|
30 var resizemarkerPoint = this._getResizeMarkerPoint(latlng); |
|
31 |
|
32 // Move the resize marker |
|
33 this._resizeMarkers[0].setLatLng(resizemarkerPoint); |
|
34 |
|
35 // Move the circle |
|
36 this._shape.setLatLng(latlng); |
|
37 |
|
38 this._map.fire(L.Draw.Event.EDITMOVE, { layer: this._shape }); |
|
39 }, |
|
40 |
|
41 _resize: function (latlng) { |
|
42 var moveLatLng = this._moveMarker.getLatLng(), |
|
43 radius = moveLatLng.distanceTo(latlng); |
|
44 |
|
45 this._shape.setRadius(radius); |
|
46 |
|
47 this._map.fire(L.Draw.Event.EDITRESIZE, { layer: this._shape }); |
|
48 } |
|
49 }); |
|
50 |
|
51 L.Circle.addInitHook(function () { |
|
52 if (L.Edit.Circle) { |
|
53 this.editing = new L.Edit.Circle(this); |
|
54 |
|
55 if (this.options.editable) { |
|
56 this.editing.enable(); |
|
57 } |
|
58 } |
|
59 |
|
60 this.on('add', function () { |
|
61 if (this.editing && this.editing.enabled()) { |
|
62 this.editing.addHooks(); |
|
63 } |
|
64 }); |
|
65 |
|
66 this.on('remove', function () { |
|
67 if (this.editing && this.editing.enabled()) { |
|
68 this.editing.removeHooks(); |
|
69 } |
|
70 }); |
|
71 }); |