派生自 wuyushui/SewerAndRainNetwork

陈泽平
2021-05-30 0110b78419d98e114c59fa9fb6f69663fbdc3c98
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
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
/*
 * L.CircleEditor is an extension of L.Circle, just to add the edition part (remember, radius in meters).
 */
'use strict'
/* eslint-disable */
import dragPng  from '../../assets/images/map-pages/buffer/area_query_drag.png'
// const init = (L) => {
    L.CircleEditor = L.Circle.extend ({
 
        options: {
            icon: new L.Icon({
                iconUrl: dragPng,
                iconSize: [30,30],
                //className: 'leaflet-div-icon leaflet-editing-icon'
            }),
            extendedIconClass : 'extend-icon'
        },
 
        onAdd: function (map) {
            L.Path.prototype.onAdd.call(this, map);
 
            this.addHooks();
        },
 
        onRemove: function (map) {
            this.removeHooks();
 
            L.Path.prototype.onRemove.call(this, map);
        },
 
 
        addHooks: function () {
            if (this._map) {
                if (!this._markerGroup) {
                    this._initMarkers();
                }
                this._map.addLayer(this._markerGroup);
            }
        },
 
        removeHooks: function () {
            if (this._map) {
                this._map.removeLayer(this._markerGroup);
                delete this._markerGroup;
                delete this._markers;
            }
        },
 
        updateMarkers: function () {
            this._markerGroup.clearLayers();
            this._initMarkers();
        },
 
        _initMarkers: function () {
            this._markerGroup = new L.LayerGroup();
            this._markers = [];
 
            var markerCenter = this._createMarker(this._latlng, 0, true);
            this._markers.push(markerCenter);
 
            var circleBounds = this.getBounds(),
                center = circleBounds.getCenter(),
                neCoord = circleBounds.getNorthEast(),
                northCenterCoord = new L.LatLng(center.lat, neCoord.lng, true);
            var markerNorthCenter = this._createMarker(northCenterCoord, 1);
            this._markers.push(markerNorthCenter);
 
            //xinzeng label
            var newNeCoord =  Number(neCoord.lng.toFixed(6))+Number(0.006030);
            var labelCenterCood = new L.LatLng(center.lat,newNeCoord, true);
            var markerLabel = this._createLableMaker(labelCenterCood,2,this.getRadius())
            this._markers.push(markerLabel);
        },
 
        _createLableMaker:function(latlng,index,radius){
            var html = parseInt(radius/1000) + "Km";
            var icon = new L.DivIcon({
                html:html,
                iconSize: new L.Point(30, 15),
                className: 'customLabel'
            });
            var marker = new L.Marker(latlng, {
                // draggable: true,
                icon: icon
            });
            marker._origLatLng = latlng;
            marker._index = index;
            // marker._isCenter = isCenter;
            this._markerGroup.addLayer(marker);
            return marker;
        },
 
        _createMarker: function (latlng, index, isCenter) {
            if(isCenter){
                var marker = new L.Marker(latlng, {
                    draggable: true,
                    icon: this.options.icon,
                    opacity    :0
                });
            }else{
                var marker = new L.Marker(latlng, {
                    draggable: true,
                    icon: this.options.icon
                });
            }
 
 
            if (isCenter === undefined) {
                isCenter = false;
            }
            //console.log("this is center point: " + isCenter);
 
            marker._origLatLng = latlng;
            marker._index = index;
            marker._isCenter = isCenter;
 
            if (isCenter) {
                //marker.on('drag', this._onCenterMove, this)
                //     .on('dragend', this._onCenterMoveEnd, this);
            } else {
                marker.on('drag', this._onMarkerDrag, this);
                marker.on('dragend', this._fireEdit, this)
                    .on('mouseover', this._onMouseOver, this)
                    .on('mouseout', this._onMouseOut, this);
            }
 
 
            this._markerGroup.addLayer(marker);
 
            return marker;
        },
        _onMouseOver: function (e) {
            var target = e.target,
                icon = target._icon,
                classValues = icon.getAttribute("class");
            //icon.setAttribute("class", "extend-icon " + classValues);
            icon.setAttribute("class", this.options.extendedIconClass + " " + classValues);
        },
        _onMouseOut: function (e) {
            var target = e.target,
                icon = target._icon,
                classValues = icon.getAttribute("class");
            //icon.setAttribute("class", classValues.replace("extend-icon", ""));
            icon.setAttribute("class", classValues.replace(this.options.extendedIconClass, ""));
        },
 
        _fireEdit: function () {
            this.fire('edit');
        },
 
        _onCenterMove: function (e) {
            var marker = e.target;
            //console.log("center move - START");
 
            L.Util.extend(marker._origLatLng, marker._latlng);
 
            var mm = this._markers[1];
            mm.setOpacity(0.1);
 
            this.redraw();
 
            //console.log("END");
        },
 
        _onCenterMoveEnd: function (e) {
            var marker = e.target;
 
            //now resetting the side point
            var circleBounds = this.getBounds(),
                center = circleBounds.getCenter(),
                neCoord = circleBounds.getNorthEast(),
                northCenterCoord = new L.LatLng(center.lat, neCoord.lng, true);
 
            var mm = this._markers[1];
            mm.setLatLng(northCenterCoord);
            mm.setOpacity(1);
 
            this.fire('centerchange');
        },
 
        _onMarkerDrag: function (e) {
            var marker = e.target;
            //console.log("marker drag - START");
            var center = this._markers[0].getLatLng();
            var axis = marker._latlng;
 
            var distance = center.distanceTo(axis);
 
            this.setRadius(distance);
 
            this.redraw();
            //console.log("END");
 
            this.fire('radiuschange');
 
 
            this._markerGroup.removeLayer(this._markers[2]);
            this._markers.pop();
 
            var circleBounds = this.getBounds(),
                center = circleBounds.getCenter(),
                neCoord = circleBounds.getNorthEast();
            var newNeCoord =  Number(neCoord.lng.toFixed(6))+Number(0.011010);
            var labelCenterCood1 = new L.LatLng(center.lat,newNeCoord, true);
            var markerLabel1 = this._createLableMaker(labelCenterCood1,2,this.getRadius())
            this._markers.push(markerLabel1);
        },
 
        centerchange: function() {},
        radiuschange: function() {}
    });
// }
//
// export default {
//     init
// }