hy-dispatch-ui-v3 0.2.53 → 0.2.54
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/tailwind.css +53 -0
- package/es/components/hyBatchUploadDialog/batchUploadDialog.vue.mjs +39 -10
- package/es/components/hyConfirmDialog/confirmDialog.vue.mjs +12 -22
- package/es/components/hyDialog/dialog.vue.mjs +9 -7
- package/es/components/hyForm/cpns/arrayItem.vue.mjs +5 -5
- package/es/components/hyForm/cpns/extraItem.vue.mjs +6 -1
- package/es/components/hyForm/cpns/formItem.vue.mjs +29 -14
- package/es/components/hyForm/js/index.mjs +29 -25
- package/es/components/hyForm/js/useAppForm.mjs +15 -30
- package/es/components/hyIconBox/iconBox.vue.mjs +1 -1
- package/es/components/hyIconBox/style/iconBox.scss +1 -1
- package/es/components/hyMap/index.mjs +6 -0
- package/es/components/hyMap/js/index.mjs +59 -0
- package/es/components/hyMap/map.vue.mjs +59 -0
- package/es/components/hyOrgCascader/js/index.mjs +53 -0
- package/es/components/hyOrgCascader/orgCascader.vue.mjs +22 -25
- package/es/components/hySearch/search.vue.mjs +6 -8
- package/es/components/hyTable/cpns/columnSelect.vue.mjs +10 -18
- package/es/components/hyTable/table.vue.mjs +8 -11
- package/es/components/hyTableActionButton/tableActionButton.vue.mjs +6 -3
- package/es/components/hyTableForm/batchTableForm.vue.mjs +182 -135
- package/es/components/hyTableForm/js/index.mjs +2 -2
- package/es/components/hyTableForm/tableForm.vue.mjs +29 -20
- package/es/components/hyTooltip/tooltip.vue.mjs +1 -1
- package/es/components/hyTree/js/index.mjs +5 -4
- package/es/components/hyTree/tree.vue.mjs +5 -0
- package/es/components/index.mjs +1 -0
- package/es/hooks/index.mjs +1 -0
- package/es/hooks/useApi.mjs +11 -5
- package/es/hooks/useAudioPlayerConfig.mjs +13 -5
- package/es/hooks/useEnsureHyIcon.mjs +11 -5
- package/es/hooks/useLocale.mjs +6 -5
- package/es/hooks/usePermissionMap.mjs +13 -5
- package/es/hooks/useSubscribe.mjs +28 -0
- package/es/hooks/useTooltipConfig.mjs +11 -5
- package/es/hooks/useUserAvatarMap.mjs +13 -5
- package/es/hooks/useVideoPlayerConfig.mjs +13 -5
- package/es/index.mjs +3 -2
- package/es/static/map/CFCASIPInput.min.js +258 -0
- package/es/static/map/MarkerCluster.css +75 -0
- package/es/static/map/bigemap.css +838 -0
- package/es/static/map/bigemap.js +5 -0
- package/es/static/map/bm.geometryutil.js +754 -0
- package/es/static/map/bmDraw.css +329 -0
- package/es/static/map/bmDraw.js +181 -0
- package/es/static/map/car.png +0 -0
- package/es/static/map/markercluster.js +2679 -0
- package/es/static/map/moveMarker.js +74 -0
- package/es/utils/form.mjs +38 -2
- package/es/utils/index.mjs +1 -2
- package/es/utils/map/hook/bigMap.mjs +1136 -0
- package/es/utils/map/hook/gaode.mjs +683 -0
- package/es/utils/map/hook/leafletjs.mjs +1336 -0
- package/es/utils/map/index.mjs +291 -0
- package/es/utils/map/js/mapProxy.mjs +38 -0
- package/es/utils/map/js/webgis.mjs +153 -0
- package/es/version.mjs +1 -1
- package/lib/components/hyBatchUploadDialog/batchUploadDialog.vue.js +40 -11
- package/lib/components/hyConfirmDialog/confirmDialog.vue.js +13 -23
- package/lib/components/hyDialog/dialog.vue.js +9 -7
- package/lib/components/hyForm/cpns/arrayItem.vue.js +4 -4
- package/lib/components/hyForm/cpns/extraItem.vue.js +6 -1
- package/lib/components/hyForm/cpns/formItem.vue.js +26 -11
- package/lib/components/hyForm/js/index.js +29 -23
- package/lib/components/hyForm/js/useAppForm.js +14 -29
- package/lib/components/hyIconBox/iconBox.vue.js +1 -1
- package/lib/components/hyIconBox/style/iconBox.scss +1 -1
- package/lib/components/hyMap/index.js +11 -0
- package/lib/components/hyMap/js/index.js +61 -0
- package/lib/components/hyMap/map.vue.js +63 -0
- package/lib/components/hyOrgCascader/js/index.js +56 -0
- package/lib/components/hyOrgCascader/orgCascader.vue.js +21 -24
- package/lib/components/hySearch/search.vue.js +4 -6
- package/lib/components/hyTable/cpns/columnSelect.vue.js +12 -20
- package/lib/components/hyTable/table.vue.js +17 -20
- package/lib/components/hyTableActionButton/tableActionButton.vue.js +5 -2
- package/lib/components/hyTableForm/batchTableForm.vue.js +181 -134
- package/lib/components/hyTableForm/js/index.js +1 -1
- package/lib/components/hyTableForm/tableForm.vue.js +29 -20
- package/lib/components/hyTooltip/tooltip.vue.js +1 -1
- package/lib/components/hyTree/js/index.js +5 -4
- package/lib/components/hyTree/tree.vue.js +5 -0
- package/lib/components/index.js +22 -20
- package/lib/hooks/index.js +3 -0
- package/lib/hooks/useApi.js +10 -4
- package/lib/hooks/useAudioPlayerConfig.js +12 -4
- package/lib/hooks/useEnsureHyIcon.js +10 -4
- package/lib/hooks/useLocale.js +5 -4
- package/lib/hooks/usePermissionMap.js +12 -4
- package/lib/hooks/useSubscribe.js +31 -0
- package/lib/hooks/useTooltipConfig.js +10 -4
- package/lib/hooks/useUserAvatarMap.js +12 -4
- package/lib/hooks/useVideoPlayerConfig.js +12 -4
- package/lib/index.js +27 -22
- package/lib/static/map/CFCASIPInput.min.js +258 -0
- package/lib/static/map/MarkerCluster.css +75 -0
- package/lib/static/map/bigemap.css +838 -0
- package/lib/static/map/bigemap.js +5 -0
- package/lib/static/map/bm.geometryutil.js +754 -0
- package/lib/static/map/bmDraw.css +329 -0
- package/lib/static/map/bmDraw.js +181 -0
- package/lib/static/map/car.png +0 -0
- package/lib/static/map/markercluster.js +2679 -0
- package/lib/static/map/moveMarker.js +74 -0
- package/lib/utils/form.js +38 -0
- package/lib/utils/index.js +2 -2
- package/lib/utils/map/hook/bigMap.js +1140 -0
- package/lib/utils/map/hook/gaode.js +687 -0
- package/lib/utils/map/hook/leafletjs.js +1360 -0
- package/lib/utils/map/index.js +298 -0
- package/lib/utils/map/js/mapProxy.js +44 -0
- package/lib/utils/map/js/webgis.js +162 -0
- package/lib/version.js +1 -1
- package/package.json +16 -1
- package/es/utils/bus.mjs +0 -5
- package/lib/utils/bus.js +0 -7
|
@@ -0,0 +1,1140 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
|
+
|
|
5
|
+
var L = require('leaflet');
|
|
6
|
+
var events = require('events');
|
|
7
|
+
var webgis = require('../js/webgis.js');
|
|
8
|
+
var mapProxy = require('../js/mapProxy.js');
|
|
9
|
+
|
|
10
|
+
var __defProp = Object.defineProperty;
|
|
11
|
+
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
12
|
+
var __publicField = (obj, key, value) => __defNormalProp(obj, key + "" , value);
|
|
13
|
+
const CIRCLE_SEGMENTS = 36;
|
|
14
|
+
function remToPx(rem) {
|
|
15
|
+
const rootFontSize = parseFloat(
|
|
16
|
+
getComputedStyle(document.documentElement).fontSize
|
|
17
|
+
);
|
|
18
|
+
return rem * rootFontSize;
|
|
19
|
+
}
|
|
20
|
+
function rangingStartIconOption(options, dicId) {
|
|
21
|
+
return {
|
|
22
|
+
html: `<div style="width:32px;height:32px;border-radius:9999px;background-color:${options.labelColor || "#2df2ff3f"};display:flex;justify-content:center;align-items:center;position:relative;">
|
|
23
|
+
<div style="width:12px;height:12px;border-radius:9999px;background-color:${options.labelFillColor || "#fff"};border:1px solid ${options.lineColor || "#2df2ff"};"></div>
|
|
24
|
+
<div style="position:absolute;left:0;top:32px;padding-left:4px;padding-right:4px;font-size:12px;line-height:16px;background-color:#fff;border:1px solid #000;color:#000;white-space:nowrap;">\u8D77\u70B9
|
|
25
|
+
<i data-id="${dicId}" class="el-icon-close"></i></div>
|
|
26
|
+
</div>`,
|
|
27
|
+
className: "my-div-icon",
|
|
28
|
+
iconSize: [remToPx(2), remToPx(2)],
|
|
29
|
+
iconAnchor: [remToPx(1), remToPx(1)]
|
|
30
|
+
};
|
|
31
|
+
}
|
|
32
|
+
function rangingPointIconOption(options, distance, dicId, showDeleteAll = false) {
|
|
33
|
+
return {
|
|
34
|
+
html: `<div style="width:12px;height:12px;border-radius:9999px;background-color:${options.labelFillColor || "#fff"};border:1px solid ${options.lineColor || "#2df2ff"};position:relative;">
|
|
35
|
+
<div style="position:absolute;left:0;top:12px;padding-left:4px;padding-right:4px;font-size:12px;line-height:16px;background-color:#fff;border:1px solid #000;color:#000;white-space:nowrap;">${distance}km
|
|
36
|
+
<i data-id="${dicId}" class="el-icon-close"></i>
|
|
37
|
+
${showDeleteAll ? '<i data-id="delete-all" class="el-icon-delete"></i>' : ""}
|
|
38
|
+
</div>
|
|
39
|
+
</div>`,
|
|
40
|
+
className: "my-div-icon",
|
|
41
|
+
iconSize: [remToPx(0.75), remToPx(0.75)],
|
|
42
|
+
iconAnchor: [remToPx(0.375), remToPx(0.375)]
|
|
43
|
+
};
|
|
44
|
+
}
|
|
45
|
+
function circleToPolygonPoints(center, radius, asObject = false) {
|
|
46
|
+
const points = [];
|
|
47
|
+
const angleStep = Math.PI * 2 / CIRCLE_SEGMENTS;
|
|
48
|
+
for (let i = 0; i < CIRCLE_SEGMENTS; i++) {
|
|
49
|
+
const angle = angleStep * i;
|
|
50
|
+
const lat = center.lat + radius * Math.cos(angle) / 111.32;
|
|
51
|
+
const lng = center.lng + radius * Math.sin(angle) / (111.32 * Math.cos(center.lat * Math.PI / 180));
|
|
52
|
+
points.push(asObject ? { lat, lng } : [lat, lng]);
|
|
53
|
+
}
|
|
54
|
+
return points;
|
|
55
|
+
}
|
|
56
|
+
const generalMapMethods = {
|
|
57
|
+
// 导入到地图里面
|
|
58
|
+
getBounds: function(target) {
|
|
59
|
+
const bounds = target.getBounds();
|
|
60
|
+
let southWest = bounds.getSouthWest();
|
|
61
|
+
let northEast = bounds.getNorthEast();
|
|
62
|
+
let center = bounds.getCenter();
|
|
63
|
+
bounds.getSouthWest = function() {
|
|
64
|
+
const { lat, lng } = latAndLngCheck(southWest);
|
|
65
|
+
return { lat, lng };
|
|
66
|
+
};
|
|
67
|
+
bounds.getNorthEast = function() {
|
|
68
|
+
const { lat, lng } = latAndLngCheck(northEast);
|
|
69
|
+
return { lat, lng };
|
|
70
|
+
};
|
|
71
|
+
bounds.getCenter = function() {
|
|
72
|
+
const { lat, lng } = latAndLngCheck(center);
|
|
73
|
+
return { lat, lng };
|
|
74
|
+
};
|
|
75
|
+
return bounds;
|
|
76
|
+
},
|
|
77
|
+
getMap: function(map) {
|
|
78
|
+
return mapProxy.createMapProxy(map, {
|
|
79
|
+
getCenter: function(target) {
|
|
80
|
+
const center = target.getCenter();
|
|
81
|
+
const { lng, lat } = latAndLngCheck(center);
|
|
82
|
+
return { lat, lng };
|
|
83
|
+
}
|
|
84
|
+
});
|
|
85
|
+
},
|
|
86
|
+
// 导出到外面
|
|
87
|
+
getBoundsExport: function(target) {
|
|
88
|
+
const bounds = target.getBounds();
|
|
89
|
+
let southWest = bounds.getSouthWest();
|
|
90
|
+
let northEast = bounds.getNorthEast();
|
|
91
|
+
let center = bounds.getCenter();
|
|
92
|
+
bounds.getSouthWest = function() {
|
|
93
|
+
const { lat, lng } = latAndLngCheckExport(southWest);
|
|
94
|
+
return { lat, lng };
|
|
95
|
+
};
|
|
96
|
+
bounds.getNorthEast = function() {
|
|
97
|
+
const { lat, lng } = latAndLngCheckExport(northEast);
|
|
98
|
+
return { lat, lng };
|
|
99
|
+
};
|
|
100
|
+
bounds.getCenter = function() {
|
|
101
|
+
const { lat, lng } = latAndLngCheckExport(center);
|
|
102
|
+
return { lat, lng };
|
|
103
|
+
};
|
|
104
|
+
return bounds;
|
|
105
|
+
}
|
|
106
|
+
};
|
|
107
|
+
function latAndLngCheck(item) {
|
|
108
|
+
const type = Array.isArray(item);
|
|
109
|
+
if (type) {
|
|
110
|
+
return webgis.importCoordinate({
|
|
111
|
+
lat: item[0],
|
|
112
|
+
lng: item[1]
|
|
113
|
+
});
|
|
114
|
+
} else {
|
|
115
|
+
return webgis.importCoordinate({
|
|
116
|
+
lat: item.lat,
|
|
117
|
+
lng: item.lng
|
|
118
|
+
});
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
function latAndLngCheckExport(item) {
|
|
122
|
+
const type = Array.isArray(item);
|
|
123
|
+
if (type) {
|
|
124
|
+
return webgis.exportCoordinate({
|
|
125
|
+
lat: item[0],
|
|
126
|
+
lng: item[1]
|
|
127
|
+
});
|
|
128
|
+
} else {
|
|
129
|
+
return webgis.exportCoordinate({
|
|
130
|
+
lat: item.lat,
|
|
131
|
+
lng: item.lng
|
|
132
|
+
});
|
|
133
|
+
}
|
|
134
|
+
}
|
|
135
|
+
function latLngListCheck(dataList = []) {
|
|
136
|
+
const newDataList = [];
|
|
137
|
+
for (let i = 0; i < dataList.length; i++) {
|
|
138
|
+
const item = dataList[i];
|
|
139
|
+
const type = Array.isArray(item);
|
|
140
|
+
let { lat, lng } = latAndLngCheck(item);
|
|
141
|
+
if (type) {
|
|
142
|
+
newDataList.push([lat, lng]);
|
|
143
|
+
} else {
|
|
144
|
+
newDataList.push({
|
|
145
|
+
...item,
|
|
146
|
+
lat,
|
|
147
|
+
lng
|
|
148
|
+
});
|
|
149
|
+
}
|
|
150
|
+
}
|
|
151
|
+
return newDataList;
|
|
152
|
+
}
|
|
153
|
+
function latLngListCheckExport(dataList = []) {
|
|
154
|
+
const newDataList = [];
|
|
155
|
+
for (let i = 0; i < dataList.length; i++) {
|
|
156
|
+
const item = dataList[i];
|
|
157
|
+
const type = Array.isArray(item);
|
|
158
|
+
let { lat, lng } = latAndLngCheckExport(item);
|
|
159
|
+
if (type) {
|
|
160
|
+
newDataList.push([lat, lng]);
|
|
161
|
+
} else {
|
|
162
|
+
newDataList.push({
|
|
163
|
+
...item,
|
|
164
|
+
lat,
|
|
165
|
+
lng
|
|
166
|
+
});
|
|
167
|
+
}
|
|
168
|
+
}
|
|
169
|
+
return newDataList;
|
|
170
|
+
}
|
|
171
|
+
class bigMap extends events.EventEmitter {
|
|
172
|
+
constructor(request) {
|
|
173
|
+
super();
|
|
174
|
+
// 绘画多边形覆盖物
|
|
175
|
+
__publicField(this, "Polygon", (pathList = [], option) => {
|
|
176
|
+
if (pathList && pathList.length !== 0) {
|
|
177
|
+
pathList = latLngListCheck(pathList);
|
|
178
|
+
}
|
|
179
|
+
const polygon = new this.BM.Polygon([pathList], option);
|
|
180
|
+
const wrappedHandlers = mapProxy.createWrappedHandlerStore();
|
|
181
|
+
const handlers = {
|
|
182
|
+
addTo: function(target, map) {
|
|
183
|
+
return target.addTo(generalMapMethods.getMap(map));
|
|
184
|
+
},
|
|
185
|
+
// 修改位置
|
|
186
|
+
getBounds: function(target) {
|
|
187
|
+
return generalMapMethods.getBoundsExport(target);
|
|
188
|
+
},
|
|
189
|
+
getLatLngs: function(target) {
|
|
190
|
+
const latLngList = target.getLatLngs();
|
|
191
|
+
const item = JSON.parse(JSON.stringify(latLngList[0]));
|
|
192
|
+
return [latLngListCheckExport([...item])];
|
|
193
|
+
},
|
|
194
|
+
on: function(target, types, fn, context) {
|
|
195
|
+
if (types === "click") {
|
|
196
|
+
const customClickHandler = (e) => {
|
|
197
|
+
const newEvent = { ...e };
|
|
198
|
+
const { lat, lng } = latAndLngCheckExport(newEvent.latlng);
|
|
199
|
+
newEvent.latlng = L.latLng(lat, lng);
|
|
200
|
+
fn.call(context || target, newEvent);
|
|
201
|
+
};
|
|
202
|
+
wrappedHandlers.remember(types, fn, customClickHandler);
|
|
203
|
+
return target.on(types, customClickHandler, context);
|
|
204
|
+
}
|
|
205
|
+
return target.on(types, fn, context);
|
|
206
|
+
},
|
|
207
|
+
off: function(target, types, fn, context) {
|
|
208
|
+
const wrappedFn = wrappedHandlers.take(types, fn);
|
|
209
|
+
return target.off(types, wrappedFn || fn, context);
|
|
210
|
+
}
|
|
211
|
+
};
|
|
212
|
+
return mapProxy.createMapProxy(polygon, handlers);
|
|
213
|
+
});
|
|
214
|
+
this.initParams = request;
|
|
215
|
+
}
|
|
216
|
+
// 初始化地图
|
|
217
|
+
InitMap(domId, option) {
|
|
218
|
+
this.BM = this.initParams.BM;
|
|
219
|
+
this.BM.Config.HTTP_URL = this.initParams.bmHttpsUrl;
|
|
220
|
+
this.BM.Config.HTTPS_URL = this.initParams.bmHttpsUrl;
|
|
221
|
+
const { center } = option;
|
|
222
|
+
const { lat, lng } = latAndLngCheck([center.lat, center.lng]);
|
|
223
|
+
const crsJons = {};
|
|
224
|
+
if (this.initParams.crs) {
|
|
225
|
+
crsJons.crs = this.BM.CRS[`${this.initParams.crs}`];
|
|
226
|
+
}
|
|
227
|
+
const load = () => {
|
|
228
|
+
if (option.completeCallbacks) {
|
|
229
|
+
option.completeCallbacks();
|
|
230
|
+
}
|
|
231
|
+
};
|
|
232
|
+
const newMap = this.BM.map(domId, this.initParams.bmUiName, {
|
|
233
|
+
...crsJons,
|
|
234
|
+
center: [lat, lng],
|
|
235
|
+
minZoom: option.minZoom,
|
|
236
|
+
maxZoom: option.maxZoom,
|
|
237
|
+
zoom: option.zoom,
|
|
238
|
+
zoomControl: false,
|
|
239
|
+
attributionControl: false,
|
|
240
|
+
load: load()
|
|
241
|
+
});
|
|
242
|
+
const wrappedHandlers = mapProxy.createWrappedHandlerStore();
|
|
243
|
+
const handlers = {
|
|
244
|
+
// 获取原始地图实例(不经过代理)
|
|
245
|
+
getRawMap: function(target) {
|
|
246
|
+
return target;
|
|
247
|
+
},
|
|
248
|
+
// 删除地图
|
|
249
|
+
removeMap: function(target, params) {
|
|
250
|
+
if (!params) {
|
|
251
|
+
target.remove();
|
|
252
|
+
target.off();
|
|
253
|
+
}
|
|
254
|
+
},
|
|
255
|
+
fitBounds: function(target, params) {
|
|
256
|
+
if (!Array.isArray(params)) {
|
|
257
|
+
params = [params];
|
|
258
|
+
}
|
|
259
|
+
const fitBoundsList = params.map(
|
|
260
|
+
(item) => mapProxy.createMapProxy(item, {
|
|
261
|
+
getBounds: (boundsTarget) => generalMapMethods.getBounds(boundsTarget)
|
|
262
|
+
})
|
|
263
|
+
);
|
|
264
|
+
return target.fitBounds(fitBoundsList);
|
|
265
|
+
},
|
|
266
|
+
// 获取中心点
|
|
267
|
+
getCenter: function(target) {
|
|
268
|
+
const center2 = target.getCenter();
|
|
269
|
+
return latAndLngCheckExport(center2);
|
|
270
|
+
},
|
|
271
|
+
// 四个角
|
|
272
|
+
getBounds: function(target) {
|
|
273
|
+
const bounds = target.getBounds();
|
|
274
|
+
let southWest = bounds.getSouthWest();
|
|
275
|
+
let northEast = bounds.getNorthEast();
|
|
276
|
+
bounds.getSouthWest = function() {
|
|
277
|
+
return latAndLngCheckExport(southWest);
|
|
278
|
+
};
|
|
279
|
+
bounds.getNorthEast = function() {
|
|
280
|
+
return latAndLngCheckExport(northEast);
|
|
281
|
+
};
|
|
282
|
+
return bounds;
|
|
283
|
+
},
|
|
284
|
+
// 移动至目标位置
|
|
285
|
+
panTo: function(target, center2, options) {
|
|
286
|
+
const { lat: lat2, lng: lng2 } = latAndLngCheck(center2);
|
|
287
|
+
return target.panTo({ lat: lat2, lng: lng2 }, options);
|
|
288
|
+
},
|
|
289
|
+
// 移动至目标位置并缩放图层
|
|
290
|
+
setView: function(target, center2, zoom, options) {
|
|
291
|
+
const { lat: lat2, lng: lng2 } = latAndLngCheck(center2);
|
|
292
|
+
return target.setView({ lat: lat2, lng: lng2 }, zoom, options);
|
|
293
|
+
},
|
|
294
|
+
// 自定义地图
|
|
295
|
+
on: function(target, types, fn, context) {
|
|
296
|
+
if (types === "click") {
|
|
297
|
+
const customClickHandler = (e) => {
|
|
298
|
+
const newEvent = { ...e };
|
|
299
|
+
newEvent.latlng = latAndLngCheckExport(newEvent.latlng);
|
|
300
|
+
fn.call(context || target, newEvent);
|
|
301
|
+
};
|
|
302
|
+
wrappedHandlers.remember(types, fn, customClickHandler);
|
|
303
|
+
return target.on(types, customClickHandler, context);
|
|
304
|
+
} else if (types === "pm:create") {
|
|
305
|
+
const customClickHandler = (e) => {
|
|
306
|
+
const newEvent = { ...e };
|
|
307
|
+
const bounds = newEvent.layer.getBounds();
|
|
308
|
+
if (!newEvent.layer.getLatLngs) {
|
|
309
|
+
newEvent.layer.getLatLngs = () => {
|
|
310
|
+
const circle = newEvent.layer;
|
|
311
|
+
const points = circleToPolygonPoints(
|
|
312
|
+
circle.getLatLng(),
|
|
313
|
+
circle.getRadius() / 1e3,
|
|
314
|
+
true
|
|
315
|
+
);
|
|
316
|
+
return [latLngListCheckExport(points)];
|
|
317
|
+
};
|
|
318
|
+
} else {
|
|
319
|
+
const latLngList = newEvent.layer.getLatLngs();
|
|
320
|
+
newEvent.layer.getLatLngs = () => {
|
|
321
|
+
const item = JSON.parse(JSON.stringify(latLngList[0]));
|
|
322
|
+
return [latLngListCheckExport([...item])];
|
|
323
|
+
};
|
|
324
|
+
}
|
|
325
|
+
newEvent.layer.getBounds = () => {
|
|
326
|
+
let southWest = bounds.getSouthWest();
|
|
327
|
+
let northEast = bounds.getNorthEast();
|
|
328
|
+
bounds.getSouthWest = function() {
|
|
329
|
+
return latAndLngCheckExport(southWest);
|
|
330
|
+
};
|
|
331
|
+
bounds.getNorthEast = function() {
|
|
332
|
+
return latAndLngCheckExport(northEast);
|
|
333
|
+
};
|
|
334
|
+
return bounds;
|
|
335
|
+
};
|
|
336
|
+
fn.call(context || target, newEvent);
|
|
337
|
+
};
|
|
338
|
+
wrappedHandlers.remember(types, fn, customClickHandler);
|
|
339
|
+
return target.on(types, customClickHandler, context);
|
|
340
|
+
}
|
|
341
|
+
return target.on(types, fn, context);
|
|
342
|
+
},
|
|
343
|
+
off: function(target, types, fn, context) {
|
|
344
|
+
const wrappedFn = wrappedHandlers.take(types, fn);
|
|
345
|
+
return target.off(types, wrappedFn || fn, context);
|
|
346
|
+
}
|
|
347
|
+
};
|
|
348
|
+
return mapProxy.createMapProxy(newMap, handlers);
|
|
349
|
+
}
|
|
350
|
+
// 地图图层
|
|
351
|
+
layerGroup(map, markers = []) {
|
|
352
|
+
const layerGroup = this.BM.layerGroup(markers);
|
|
353
|
+
layerGroup.addTo(map);
|
|
354
|
+
return layerGroup;
|
|
355
|
+
}
|
|
356
|
+
// 自定义图标
|
|
357
|
+
DivIcon(option) {
|
|
358
|
+
option = {
|
|
359
|
+
...option,
|
|
360
|
+
html: option.html,
|
|
361
|
+
className: option.className,
|
|
362
|
+
iconSize: option.iconSize,
|
|
363
|
+
iconAnchor: option.iconAnchor
|
|
364
|
+
};
|
|
365
|
+
return this.BM.divIcon(option);
|
|
366
|
+
}
|
|
367
|
+
// 生成 marker
|
|
368
|
+
Marker(markerOptions) {
|
|
369
|
+
const { position = {} } = markerOptions;
|
|
370
|
+
markerOptions = {
|
|
371
|
+
...markerOptions,
|
|
372
|
+
position: [position.lat, position.lng],
|
|
373
|
+
icon: markerOptions.icon,
|
|
374
|
+
pane: markerOptions.pane || "markerPane"
|
|
375
|
+
};
|
|
376
|
+
if (markerOptions.position && markerOptions.position.length !== 0) {
|
|
377
|
+
const { lat, lng } = latAndLngCheck(markerOptions.position);
|
|
378
|
+
markerOptions.position = [lat, lng];
|
|
379
|
+
}
|
|
380
|
+
const marker = new this.BM.marker(markerOptions.position, markerOptions);
|
|
381
|
+
marker.getInitMarker = () => {
|
|
382
|
+
return marker;
|
|
383
|
+
};
|
|
384
|
+
marker.extData = markerOptions.extData || null;
|
|
385
|
+
const wrappedHandlers = mapProxy.createWrappedHandlerStore();
|
|
386
|
+
const handlers = {
|
|
387
|
+
getLatLng: function(target) {
|
|
388
|
+
const latlng = target.getLatLng();
|
|
389
|
+
const { lat, lng } = latAndLngCheckExport(latlng);
|
|
390
|
+
return { lat, lng };
|
|
391
|
+
},
|
|
392
|
+
// 更改标记位置。
|
|
393
|
+
setLatLng: function(target, lngAndLat) {
|
|
394
|
+
const { lat, lng } = latAndLngCheck(lngAndLat);
|
|
395
|
+
target.setLatLng([lat, lng]);
|
|
396
|
+
},
|
|
397
|
+
// 更改标记图标。
|
|
398
|
+
setIcon: function(target, iconParams) {
|
|
399
|
+
target.setIcon(iconParams.divIcon);
|
|
400
|
+
},
|
|
401
|
+
on: function(target, types, fn, context) {
|
|
402
|
+
if (types === "click") {
|
|
403
|
+
const customClickHandler = (e) => {
|
|
404
|
+
const newEvent = { ...e, originEvent: e.originalEvent };
|
|
405
|
+
const { lat, lng } = latAndLngCheckExport(newEvent.latlng);
|
|
406
|
+
newEvent.latlng = { lat, lng };
|
|
407
|
+
fn.call(context || target, newEvent);
|
|
408
|
+
};
|
|
409
|
+
wrappedHandlers.remember(types, fn, customClickHandler);
|
|
410
|
+
return target.on(types, customClickHandler, context);
|
|
411
|
+
}
|
|
412
|
+
return target.on(types, fn, context);
|
|
413
|
+
},
|
|
414
|
+
off: function(target, types, fn, context) {
|
|
415
|
+
const wrappedFn = wrappedHandlers.take(types, fn);
|
|
416
|
+
return target.off(types, wrappedFn || fn, context);
|
|
417
|
+
}
|
|
418
|
+
};
|
|
419
|
+
return mapProxy.createMapProxy(marker, handlers);
|
|
420
|
+
}
|
|
421
|
+
// 生成 聚合点
|
|
422
|
+
MarkerClusterGroup(map, markerList, option) {
|
|
423
|
+
option = {
|
|
424
|
+
showCoverageOnHover: false,
|
|
425
|
+
zoomToBoundsOnClick: true,
|
|
426
|
+
removeOutsideVisibleBounds: true,
|
|
427
|
+
spiderfyDistanceMultiplier: 1,
|
|
428
|
+
spiderLegPolylineOptions: { weight: 1, color: "#5E9DB4", opacity: 1 },
|
|
429
|
+
...option,
|
|
430
|
+
iconCreateFunction: option.iconCreateFunction,
|
|
431
|
+
disableClusteringAtZoom: option.disableClusteringAtZoom,
|
|
432
|
+
maxClusterRadius: option.maxClusterRadius
|
|
433
|
+
};
|
|
434
|
+
const displayCluster = new this.BM.MarkerClusterGroup(option);
|
|
435
|
+
map.addLayer(displayCluster);
|
|
436
|
+
const toNativeMarkers = (list = []) => {
|
|
437
|
+
const markers = Array.isArray(list) ? list : [list];
|
|
438
|
+
return markers.map(
|
|
439
|
+
(marker) => marker?.getInitMarker ? marker.getInitMarker() : marker
|
|
440
|
+
).filter(Boolean);
|
|
441
|
+
};
|
|
442
|
+
const handlers = {
|
|
443
|
+
remove: function(target) {
|
|
444
|
+
target.remove();
|
|
445
|
+
},
|
|
446
|
+
removeLayers: function(target, markerList2 = []) {
|
|
447
|
+
target.removeLayers(toNativeMarkers(markerList2));
|
|
448
|
+
},
|
|
449
|
+
addLayers: function(target, markerList2 = []) {
|
|
450
|
+
target.addLayers(toNativeMarkers(markerList2));
|
|
451
|
+
}
|
|
452
|
+
};
|
|
453
|
+
const newDisplayCluster = mapProxy.createMapProxy(displayCluster, handlers);
|
|
454
|
+
newDisplayCluster.addLayers(markerList);
|
|
455
|
+
return newDisplayCluster;
|
|
456
|
+
}
|
|
457
|
+
// 绘画圆
|
|
458
|
+
Circle(latLngList = {}, option = {}) {
|
|
459
|
+
option = {
|
|
460
|
+
...option,
|
|
461
|
+
radius: option.radius,
|
|
462
|
+
color: option.color,
|
|
463
|
+
opacity: option.opacity,
|
|
464
|
+
weight: option.weight,
|
|
465
|
+
fillColor: option.fillColor,
|
|
466
|
+
fillOpacity: option.fillOpacity
|
|
467
|
+
};
|
|
468
|
+
const { lat, lng } = latAndLngCheck(latLngList);
|
|
469
|
+
latLngList = [lat, lng];
|
|
470
|
+
const circle = new this.BM.Circle(latLngList, option);
|
|
471
|
+
const handlers = {
|
|
472
|
+
// 添加到地图
|
|
473
|
+
addTo: function(target, map) {
|
|
474
|
+
return target.addTo(generalMapMethods.getMap(map));
|
|
475
|
+
},
|
|
476
|
+
// 修改位置
|
|
477
|
+
getBounds: function(target) {
|
|
478
|
+
return generalMapMethods.getBoundsExport(target);
|
|
479
|
+
},
|
|
480
|
+
// 圆形转多边形坐标
|
|
481
|
+
getLatLngs: function(target) {
|
|
482
|
+
const points = circleToPolygonPoints(
|
|
483
|
+
target.getLatLng(),
|
|
484
|
+
target.getRadius() / 1e3
|
|
485
|
+
);
|
|
486
|
+
return [latLngListCheckExport(points)];
|
|
487
|
+
}
|
|
488
|
+
};
|
|
489
|
+
return mapProxy.createMapProxy(circle, handlers);
|
|
490
|
+
}
|
|
491
|
+
// 自定义 popup
|
|
492
|
+
Popup(option) {
|
|
493
|
+
option = {
|
|
494
|
+
closeButton: false,
|
|
495
|
+
...option
|
|
496
|
+
};
|
|
497
|
+
const popup = new this.BM.Popup(option);
|
|
498
|
+
const handlers = {
|
|
499
|
+
addTo: function(target, map) {
|
|
500
|
+
return target.addTo(generalMapMethods.getMap(map));
|
|
501
|
+
},
|
|
502
|
+
// 修改位置
|
|
503
|
+
getBounds: function(target) {
|
|
504
|
+
return generalMapMethods.getBoundsExport(target);
|
|
505
|
+
},
|
|
506
|
+
// 修改位置
|
|
507
|
+
setLatLng: function(target, latLngList) {
|
|
508
|
+
if (latLngList && latLngList.length !== 0) {
|
|
509
|
+
latLngList = latAndLngCheck(latLngList);
|
|
510
|
+
}
|
|
511
|
+
return target.setLatLng(latLngList);
|
|
512
|
+
}
|
|
513
|
+
};
|
|
514
|
+
return mapProxy.createMapProxy(popup, handlers);
|
|
515
|
+
}
|
|
516
|
+
// 自定义 线条
|
|
517
|
+
Polyline(latLngList = [], option = {}) {
|
|
518
|
+
if (latLngList && latLngList.length !== 0) {
|
|
519
|
+
latLngList = latLngListCheck(latLngList);
|
|
520
|
+
}
|
|
521
|
+
const polyline = this.BM.polyline(latLngList, option);
|
|
522
|
+
const wrappedHandlers = mapProxy.createWrappedHandlerStore();
|
|
523
|
+
const handlers = {
|
|
524
|
+
addTo: function(target, map) {
|
|
525
|
+
return target.addTo(generalMapMethods.getMap(map));
|
|
526
|
+
},
|
|
527
|
+
// 修改位置
|
|
528
|
+
getBounds: function(target) {
|
|
529
|
+
return generalMapMethods.getBoundsExport(target);
|
|
530
|
+
},
|
|
531
|
+
on: function(target, types, fn, context) {
|
|
532
|
+
if (types === "click") {
|
|
533
|
+
const customClickHandler = (e) => {
|
|
534
|
+
const newEvent = { ...e };
|
|
535
|
+
const { lat, lng } = latAndLngCheckExport(newEvent.latlng);
|
|
536
|
+
newEvent.latlng = { lat, lng };
|
|
537
|
+
fn.call(context || target, newEvent);
|
|
538
|
+
};
|
|
539
|
+
wrappedHandlers.remember(types, fn, customClickHandler);
|
|
540
|
+
return target.on(types, customClickHandler, context);
|
|
541
|
+
}
|
|
542
|
+
return target.on(types, fn, context);
|
|
543
|
+
},
|
|
544
|
+
off: function(target, types, fn, context) {
|
|
545
|
+
const wrappedFn = wrappedHandlers.take(types, fn);
|
|
546
|
+
return target.off(types, wrappedFn || fn, context);
|
|
547
|
+
}
|
|
548
|
+
};
|
|
549
|
+
return mapProxy.createMapProxy(polyline, handlers);
|
|
550
|
+
}
|
|
551
|
+
// 轨迹回放
|
|
552
|
+
TrackPlayer(latLngList = [], option = {}, map = null) {
|
|
553
|
+
let monitorTrack = null;
|
|
554
|
+
let speed = option.speed;
|
|
555
|
+
let polyline = this.Polyline(latLngList, {
|
|
556
|
+
color: option.notPassedLineColor || "#FF1875",
|
|
557
|
+
// 线颜色
|
|
558
|
+
weight: 4
|
|
559
|
+
}).addTo(map);
|
|
560
|
+
let passedPolyline = this.Polyline([], {
|
|
561
|
+
color: option.passedLineColor || "#2EE19E",
|
|
562
|
+
// 线颜色
|
|
563
|
+
weight: 4
|
|
564
|
+
}).addTo(map);
|
|
565
|
+
let marker = this.Marker({
|
|
566
|
+
position: latLngList[0],
|
|
567
|
+
icon: this.DivIcon({
|
|
568
|
+
html: option.svgContent,
|
|
569
|
+
className: "my-div-icon",
|
|
570
|
+
iconSize: option.iconSize || 0,
|
|
571
|
+
iconAnchor: option.iconAnchor || 0
|
|
572
|
+
})
|
|
573
|
+
}).addTo(map);
|
|
574
|
+
marker.on("update_position", (e) => {
|
|
575
|
+
passedPolyline.setLatLngs(e.path);
|
|
576
|
+
if (monitorTrack) {
|
|
577
|
+
clearTimeout(monitorTrack);
|
|
578
|
+
}
|
|
579
|
+
monitorTrack = setTimeout(() => {
|
|
580
|
+
if (option.onEnd) option.onEnd();
|
|
581
|
+
}, 500);
|
|
582
|
+
});
|
|
583
|
+
map.setView(latLngList[0], 18);
|
|
584
|
+
const moveAlong = () => {
|
|
585
|
+
if (!marker) return;
|
|
586
|
+
marker.moveAlong(latLngList, speed / 3.6, {
|
|
587
|
+
replay: false
|
|
588
|
+
});
|
|
589
|
+
};
|
|
590
|
+
const handlers = {
|
|
591
|
+
// 开始
|
|
592
|
+
startAnimation: function() {
|
|
593
|
+
moveAlong();
|
|
594
|
+
},
|
|
595
|
+
// 暂停
|
|
596
|
+
pauseAnimation: function() {
|
|
597
|
+
if (marker) {
|
|
598
|
+
marker.pauseMove();
|
|
599
|
+
if (monitorTrack) {
|
|
600
|
+
clearTimeout(monitorTrack);
|
|
601
|
+
}
|
|
602
|
+
}
|
|
603
|
+
},
|
|
604
|
+
// 恢复
|
|
605
|
+
resumeAnimation: function() {
|
|
606
|
+
if (marker) {
|
|
607
|
+
marker.resumeMove();
|
|
608
|
+
}
|
|
609
|
+
},
|
|
610
|
+
// 修改速度
|
|
611
|
+
motionSpeed: function(target, changeSpeed) {
|
|
612
|
+
speed = changeSpeed;
|
|
613
|
+
moveAlong();
|
|
614
|
+
},
|
|
615
|
+
// 移除轨迹回放
|
|
616
|
+
removeTrackPlayer: function() {
|
|
617
|
+
marker.remove();
|
|
618
|
+
polyline.remove();
|
|
619
|
+
passedPolyline.remove();
|
|
620
|
+
marker = null;
|
|
621
|
+
polyline = null;
|
|
622
|
+
passedPolyline = null;
|
|
623
|
+
if (monitorTrack) {
|
|
624
|
+
clearTimeout(monitorTrack);
|
|
625
|
+
monitorTrack = null;
|
|
626
|
+
}
|
|
627
|
+
}
|
|
628
|
+
};
|
|
629
|
+
return mapProxy.createMapProxy(marker, handlers);
|
|
630
|
+
}
|
|
631
|
+
/**
|
|
632
|
+
*
|
|
633
|
+
* @param {*} pmType 创建绘画工具 rectangle 正方形 circle 圆形 polygon 多边形
|
|
634
|
+
* @param {*} options circleClick 解决直接点击时圆形绘制无效问题,绘制电子围栏时为false防止与定点绘制冲突
|
|
635
|
+
* @param {*} map 地图实例
|
|
636
|
+
* @returns
|
|
637
|
+
*/
|
|
638
|
+
CreatePm(pmType = "rectangle", options = { circleClick: true }, map) {
|
|
639
|
+
const rawMap = map.getRawMap ? map.getRawMap() : map;
|
|
640
|
+
const Draw = {};
|
|
641
|
+
Draw.draw = {
|
|
642
|
+
rectangle: new this.BM.Draw.Rectangle(rawMap),
|
|
643
|
+
circle: new this.BM.Draw.Circle(rawMap),
|
|
644
|
+
polygon: new this.BM.Draw.Polygon(rawMap)
|
|
645
|
+
};
|
|
646
|
+
let mouseToolName = pmType;
|
|
647
|
+
Draw.draw[`${pmType}`].enable();
|
|
648
|
+
Draw.current = pmType;
|
|
649
|
+
let layer = null;
|
|
650
|
+
let isEnd = false;
|
|
651
|
+
rawMap.on(this.BM.Draw.Event.CREATED, (e) => {
|
|
652
|
+
isEnd = true;
|
|
653
|
+
layer = e.layer;
|
|
654
|
+
if (!layer._latlngs) {
|
|
655
|
+
const center = latAndLngCheckExport(layer.getLatLng());
|
|
656
|
+
layer._latlngs = [
|
|
657
|
+
circleToPolygonPoints(center, layer.getRadius() / 1e3, true)
|
|
658
|
+
];
|
|
659
|
+
} else {
|
|
660
|
+
layer._latlngs[0] = latLngListCheckExport(layer._latlngs[0]);
|
|
661
|
+
}
|
|
662
|
+
layer.addTo(rawMap);
|
|
663
|
+
if (options.onChange) {
|
|
664
|
+
options.onChange(layer._latlngs[0]);
|
|
665
|
+
}
|
|
666
|
+
});
|
|
667
|
+
const mapClick = () => {
|
|
668
|
+
if (mouseToolName === "circle" && !isEnd) {
|
|
669
|
+
Draw.draw[`${mouseToolName}`].disable();
|
|
670
|
+
setTimeout(() => {
|
|
671
|
+
Draw.draw[`${mouseToolName}`].enable();
|
|
672
|
+
Draw.current = mouseToolName;
|
|
673
|
+
});
|
|
674
|
+
}
|
|
675
|
+
isEnd = false;
|
|
676
|
+
};
|
|
677
|
+
if (options.circleClick) {
|
|
678
|
+
map.on("click", mapClick);
|
|
679
|
+
}
|
|
680
|
+
const handlers = {
|
|
681
|
+
remove: function(target) {
|
|
682
|
+
Draw.draw.rectangle.disable();
|
|
683
|
+
Draw.draw.circle.disable();
|
|
684
|
+
Draw.draw.polygon.disable();
|
|
685
|
+
rawMap.off(BM.Draw.Event.CREATED);
|
|
686
|
+
Draw.draw = null;
|
|
687
|
+
mouseToolName = null;
|
|
688
|
+
layer?.remove();
|
|
689
|
+
layer = null;
|
|
690
|
+
map.off("click", mapClick);
|
|
691
|
+
},
|
|
692
|
+
close: function(target) {
|
|
693
|
+
layer?.remove();
|
|
694
|
+
if (mouseToolName) {
|
|
695
|
+
Draw.draw[`${mouseToolName}`].disable();
|
|
696
|
+
}
|
|
697
|
+
},
|
|
698
|
+
setMouseTool: function(target, toolType) {
|
|
699
|
+
if (mouseToolName) {
|
|
700
|
+
Draw.draw[`${mouseToolName}`].disable();
|
|
701
|
+
}
|
|
702
|
+
setTimeout(() => {
|
|
703
|
+
mouseToolName = toolType;
|
|
704
|
+
Draw.draw[`${mouseToolName}`].enable();
|
|
705
|
+
Draw.current = mouseToolName;
|
|
706
|
+
isEnd = false;
|
|
707
|
+
});
|
|
708
|
+
}
|
|
709
|
+
};
|
|
710
|
+
return mapProxy.createMapProxy({}, handlers);
|
|
711
|
+
}
|
|
712
|
+
// 电子围栏
|
|
713
|
+
CreateFence(pmType = "rectangle", options = {}, map) {
|
|
714
|
+
let polygon = null;
|
|
715
|
+
const clearPolygon = () => {
|
|
716
|
+
if (polygon) {
|
|
717
|
+
polygon.remove();
|
|
718
|
+
polygon = null;
|
|
719
|
+
}
|
|
720
|
+
};
|
|
721
|
+
const setPolygon = (pointList) => {
|
|
722
|
+
clearPolygon();
|
|
723
|
+
polygon = this.Polygon(pointList, {
|
|
724
|
+
...options,
|
|
725
|
+
fillColor: options.fillColor || "#00b0ff",
|
|
726
|
+
fillOpacity: options.fillOpacity || 0.5,
|
|
727
|
+
color: options.color || "#80d8ff",
|
|
728
|
+
weight: options.weight || 4,
|
|
729
|
+
opacity: options.opacity || 1,
|
|
730
|
+
zIndex: options.zIndex || 1e6
|
|
731
|
+
});
|
|
732
|
+
polygon.addTo(map);
|
|
733
|
+
map.fitBounds(polygon.getBounds());
|
|
734
|
+
polygon.editing.enable();
|
|
735
|
+
pm.close();
|
|
736
|
+
};
|
|
737
|
+
const onChange = (pointList) => {
|
|
738
|
+
setPolygon(latLngListCheck(pointList));
|
|
739
|
+
};
|
|
740
|
+
const pm = this.CreatePm(
|
|
741
|
+
pmType,
|
|
742
|
+
{
|
|
743
|
+
...options,
|
|
744
|
+
onChange,
|
|
745
|
+
circleClick: false
|
|
746
|
+
},
|
|
747
|
+
map
|
|
748
|
+
);
|
|
749
|
+
pm.close();
|
|
750
|
+
const handlers = {
|
|
751
|
+
getPath: function() {
|
|
752
|
+
return polygon ? polygon.getLatLngs()[0] : [];
|
|
753
|
+
},
|
|
754
|
+
// 定点绘制(radius 为直径,故取半)
|
|
755
|
+
setFixedPoint: function(target, { lnglat, radius }) {
|
|
756
|
+
setPolygon(circleToPolygonPoints(lnglat, radius / 2e3));
|
|
757
|
+
},
|
|
758
|
+
setPolygon: function(target, pointList) {
|
|
759
|
+
setPolygon(latLngListCheck(pointList));
|
|
760
|
+
},
|
|
761
|
+
startDraw: function(target, toolType = "rectangle") {
|
|
762
|
+
clearPolygon();
|
|
763
|
+
target.setMouseTool(toolType);
|
|
764
|
+
},
|
|
765
|
+
clearDraw: function() {
|
|
766
|
+
clearPolygon();
|
|
767
|
+
},
|
|
768
|
+
remove: function(target) {
|
|
769
|
+
clearPolygon();
|
|
770
|
+
target.close(true);
|
|
771
|
+
target.remove();
|
|
772
|
+
},
|
|
773
|
+
close: function(target) {
|
|
774
|
+
target.close(true);
|
|
775
|
+
},
|
|
776
|
+
setMouseTool: function(target, toolType) {
|
|
777
|
+
target.setMouseTool(toolType);
|
|
778
|
+
}
|
|
779
|
+
};
|
|
780
|
+
return mapProxy.createMapProxy(pm, handlers);
|
|
781
|
+
}
|
|
782
|
+
// 测距工具 labelColor labelFillColor lineColor
|
|
783
|
+
RangingTool(options = {}, map) {
|
|
784
|
+
let rangingMarker = [];
|
|
785
|
+
let rangingPolylines = [];
|
|
786
|
+
let rangingPointsIng = [];
|
|
787
|
+
let rangingPointsEnd = [];
|
|
788
|
+
let rangingTrun = false;
|
|
789
|
+
const _this = this;
|
|
790
|
+
function rangingClick(res) {
|
|
791
|
+
setRangingTrun(res.latlng);
|
|
792
|
+
}
|
|
793
|
+
function calcTotalDistance(index, preIndex) {
|
|
794
|
+
const current = rangingMarker[index].options.extData.latlng;
|
|
795
|
+
const previous = rangingMarker[preIndex].options.extData.latlng;
|
|
796
|
+
const distance = parseFloat(
|
|
797
|
+
(map.distance(current, previous) / 1e3).toFixed(2)
|
|
798
|
+
);
|
|
799
|
+
const total = parseFloat(
|
|
800
|
+
rangingMarker[preIndex].options.extData.distance || 0
|
|
801
|
+
);
|
|
802
|
+
return (distance + total).toFixed(2);
|
|
803
|
+
}
|
|
804
|
+
function removeLineBetween(groupIndex, aIndex, bIndex) {
|
|
805
|
+
const latlngOne = rangingMarker[aIndex]?.options?.extData?.latlng;
|
|
806
|
+
const latlngTwo = rangingMarker[bIndex]?.options?.extData?.latlng;
|
|
807
|
+
const polygonIndex = rangingPolylines.findIndex((v) => {
|
|
808
|
+
const extData = v.options.extData;
|
|
809
|
+
return groupIndex === extData.index && extData.latlngs === "" + latlngOne.lat + latlngOne.lng + latlngTwo.lat + latlngTwo.lng;
|
|
810
|
+
});
|
|
811
|
+
rangingPolylines[polygonIndex] && rangingPolylines[polygonIndex].remove();
|
|
812
|
+
rangingPolylines.splice(polygonIndex, 1);
|
|
813
|
+
}
|
|
814
|
+
function setStartIcon(index) {
|
|
815
|
+
const markerItem = rangingMarker[index];
|
|
816
|
+
markerItem.setIcon({
|
|
817
|
+
divIcon: _this.DivIcon(
|
|
818
|
+
rangingStartIconOption(options, markerItem.options.extData.dicId)
|
|
819
|
+
)
|
|
820
|
+
});
|
|
821
|
+
markerItem.options.extData.distance = 0;
|
|
822
|
+
}
|
|
823
|
+
function setPointIcon(index, distance, showDeleteAll) {
|
|
824
|
+
const markerItem = rangingMarker[index];
|
|
825
|
+
const isLast = !rangingMarker[index + 1]?.options?.extData?.distance;
|
|
826
|
+
markerItem.setIcon({
|
|
827
|
+
divIcon: _this.DivIcon(
|
|
828
|
+
rangingPointIconOption(
|
|
829
|
+
options,
|
|
830
|
+
distance,
|
|
831
|
+
markerItem.options.extData.dicId,
|
|
832
|
+
isLast
|
|
833
|
+
)
|
|
834
|
+
)
|
|
835
|
+
});
|
|
836
|
+
markerItem.options.extData.distance = distance;
|
|
837
|
+
}
|
|
838
|
+
function setRangingTrun({ lat, lng }) {
|
|
839
|
+
const dicId = `${rangingPointsEnd.length}-${lat}-${lng}`;
|
|
840
|
+
if (!rangingPointsIng.length) {
|
|
841
|
+
const customIcon = _this.DivIcon(rangingStartIconOption(options, dicId));
|
|
842
|
+
const markerItem = _this.Marker({
|
|
843
|
+
position: { lat, lng },
|
|
844
|
+
icon: customIcon,
|
|
845
|
+
extData: {
|
|
846
|
+
latlng: { lat, lng },
|
|
847
|
+
index: rangingPointsEnd.length,
|
|
848
|
+
distance: 0,
|
|
849
|
+
dicId
|
|
850
|
+
}
|
|
851
|
+
});
|
|
852
|
+
markerItem.on("click", (res) => {
|
|
853
|
+
if (res.originalEvent.target.dataset?.id) {
|
|
854
|
+
clickItem();
|
|
855
|
+
}
|
|
856
|
+
});
|
|
857
|
+
markerItem.addTo(map);
|
|
858
|
+
rangingMarker.push(markerItem);
|
|
859
|
+
rangingPointsIng.push({ lat, lng });
|
|
860
|
+
} else {
|
|
861
|
+
const latlngs = [
|
|
862
|
+
[
|
|
863
|
+
rangingPointsIng[rangingPointsIng.length - 1].lat,
|
|
864
|
+
rangingPointsIng[rangingPointsIng.length - 1].lng
|
|
865
|
+
],
|
|
866
|
+
[lat, lng]
|
|
867
|
+
];
|
|
868
|
+
const polyline = _this.Polyline(latlngs, {
|
|
869
|
+
color: "#2df2ff",
|
|
870
|
+
weight: 2,
|
|
871
|
+
extData: {
|
|
872
|
+
latlngs: "" + latlngs[0][0] + latlngs[0][1] + latlngs[1][0] + latlngs[1][1],
|
|
873
|
+
index: rangingPointsEnd.length
|
|
874
|
+
}
|
|
875
|
+
});
|
|
876
|
+
polyline.addTo(map);
|
|
877
|
+
rangingPolylines.push(polyline);
|
|
878
|
+
let distance = map.distance(
|
|
879
|
+
{ lat: latlngs[0][0], lng: latlngs[0][1] },
|
|
880
|
+
{ lat: latlngs[1][0], lng: latlngs[1][1] }
|
|
881
|
+
);
|
|
882
|
+
distance = parseFloat((distance / 1e3).toFixed(2));
|
|
883
|
+
const total = parseFloat(
|
|
884
|
+
rangingMarker[rangingMarker.length - 1].options.extData.distance || 0
|
|
885
|
+
);
|
|
886
|
+
distance = (distance + total).toFixed(2);
|
|
887
|
+
const customIcon = _this.DivIcon(
|
|
888
|
+
rangingPointIconOption(options, distance, dicId)
|
|
889
|
+
);
|
|
890
|
+
const markerItem = _this.Marker({
|
|
891
|
+
position: { lat, lng },
|
|
892
|
+
icon: customIcon,
|
|
893
|
+
extData: {
|
|
894
|
+
latlng: { lat, lng },
|
|
895
|
+
index: rangingPointsEnd.length,
|
|
896
|
+
distance,
|
|
897
|
+
dicId
|
|
898
|
+
}
|
|
899
|
+
});
|
|
900
|
+
markerItem.on("click", (res) => {
|
|
901
|
+
if (res.originalEvent.target.dataset?.id === "delete-all") {
|
|
902
|
+
deleteAll();
|
|
903
|
+
} else if (res.originalEvent.target.dataset?.id) {
|
|
904
|
+
clickItem();
|
|
905
|
+
}
|
|
906
|
+
});
|
|
907
|
+
markerItem.addTo(map);
|
|
908
|
+
rangingMarker.push(markerItem);
|
|
909
|
+
rangingPointsIng.push({ lat, lng });
|
|
910
|
+
}
|
|
911
|
+
const rangEndIndex = rangingPointsEnd.length;
|
|
912
|
+
function clickItem() {
|
|
913
|
+
if (rangEndIndex === rangingPointsEnd.length) {
|
|
914
|
+
if (options.message) {
|
|
915
|
+
options.message({
|
|
916
|
+
type: "warning",
|
|
917
|
+
message: "\u8BF7\u5148\u5B8C\u6210\u672C\u6B21\u6D4B\u8DDD\uFF0C\u518D\u5220\u9664\u6D4B\u8DDD\u70B9"
|
|
918
|
+
});
|
|
919
|
+
}
|
|
920
|
+
return;
|
|
921
|
+
}
|
|
922
|
+
const index = rangingMarker.findIndex((v) => {
|
|
923
|
+
const extData = v?.options?.extData;
|
|
924
|
+
return extData?.index === rangEndIndex && extData?.latlng?.lat === lat && extData?.latlng?.lng === lng;
|
|
925
|
+
});
|
|
926
|
+
const distance = rangingMarker[index].options.extData.distance;
|
|
927
|
+
if (distance === 0) {
|
|
928
|
+
const nextMarker = rangingMarker[index + 1]?.options?.extData?.distance;
|
|
929
|
+
const nextTwo = rangingMarker[index + 2]?.options?.extData?.distance;
|
|
930
|
+
if (!(nextMarker && nextMarker !== 0 && nextTwo && nextTwo !== 0)) {
|
|
931
|
+
if (nextMarker) {
|
|
932
|
+
removeLineBetween(rangEndIndex, index, index + 1);
|
|
933
|
+
setTimeout(() => {
|
|
934
|
+
rangingMarker[index + 1].remove();
|
|
935
|
+
rangingMarker[index].remove();
|
|
936
|
+
rangingMarker.splice(index, 1);
|
|
937
|
+
setTimeout(() => {
|
|
938
|
+
rangingMarker.splice(index, 1);
|
|
939
|
+
});
|
|
940
|
+
});
|
|
941
|
+
} else {
|
|
942
|
+
setTimeout(() => {
|
|
943
|
+
rangingMarker[index].remove();
|
|
944
|
+
rangingMarker.splice(index, 1);
|
|
945
|
+
});
|
|
946
|
+
}
|
|
947
|
+
return;
|
|
948
|
+
} else {
|
|
949
|
+
removeLineBetween(rangEndIndex, index, index + 1);
|
|
950
|
+
let changeIndex = index + 1;
|
|
951
|
+
while (rangingMarker[changeIndex]?.options?.extData?.distance) {
|
|
952
|
+
if (changeIndex - 1 === index) {
|
|
953
|
+
setStartIcon(changeIndex);
|
|
954
|
+
} else {
|
|
955
|
+
setPointIcon(
|
|
956
|
+
changeIndex,
|
|
957
|
+
calcTotalDistance(changeIndex, changeIndex - 1)
|
|
958
|
+
);
|
|
959
|
+
}
|
|
960
|
+
changeIndex++;
|
|
961
|
+
}
|
|
962
|
+
setTimeout(() => {
|
|
963
|
+
rangingMarker[index].remove();
|
|
964
|
+
rangingMarker.splice(index, 1);
|
|
965
|
+
});
|
|
966
|
+
}
|
|
967
|
+
} else {
|
|
968
|
+
const nextDistance = rangingMarker[index + 1]?.options?.extData?.distance;
|
|
969
|
+
if (nextDistance) {
|
|
970
|
+
const latlngOne = rangingMarker[index - 1]?.options?.extData?.latlng;
|
|
971
|
+
const latlngTree = rangingMarker[index + 1]?.options?.extData?.latlng;
|
|
972
|
+
removeLineBetween(rangEndIndex, index - 1, index);
|
|
973
|
+
removeLineBetween(rangEndIndex, index, index + 1);
|
|
974
|
+
const latlngs = [
|
|
975
|
+
[latlngOne.lat, latlngOne.lng],
|
|
976
|
+
[latlngTree.lat, latlngTree.lng]
|
|
977
|
+
];
|
|
978
|
+
const polyline = _this.Polyline(latlngs, {
|
|
979
|
+
color: "#2df2ff",
|
|
980
|
+
weight: 2,
|
|
981
|
+
extData: {
|
|
982
|
+
latlngs: "" + latlngs[0][0] + latlngs[0][1] + latlngs[1][0] + latlngs[1][1],
|
|
983
|
+
index: rangEndIndex
|
|
984
|
+
}
|
|
985
|
+
});
|
|
986
|
+
polyline.addTo(map);
|
|
987
|
+
rangingPolylines.push(polyline);
|
|
988
|
+
let changeIndex = index + 1;
|
|
989
|
+
while (rangingMarker[changeIndex]?.options?.extData?.distance) {
|
|
990
|
+
const disIndex = changeIndex - 1 === index ? changeIndex - 2 : changeIndex - 1;
|
|
991
|
+
setPointIcon(
|
|
992
|
+
changeIndex,
|
|
993
|
+
calcTotalDistance(changeIndex, disIndex)
|
|
994
|
+
);
|
|
995
|
+
changeIndex++;
|
|
996
|
+
}
|
|
997
|
+
setTimeout(() => {
|
|
998
|
+
rangingMarker[index].remove();
|
|
999
|
+
rangingMarker.splice(index, 1);
|
|
1000
|
+
});
|
|
1001
|
+
} else {
|
|
1002
|
+
const beforeDistance = rangingMarker[index - 1]?.options?.extData?.distance;
|
|
1003
|
+
if (beforeDistance) {
|
|
1004
|
+
const latlngOne = rangingMarker[index - 1]?.options?.extData?.latlng;
|
|
1005
|
+
const latlngTwo = rangingMarker[index]?.options?.extData?.latlng;
|
|
1006
|
+
const polygonIndex = rangingPolylines.findIndex((v) => {
|
|
1007
|
+
const extData = v.options.extData;
|
|
1008
|
+
return rangEndIndex === extData.index && extData.latlngs === "" + latlngOne.lat + latlngOne.lng + latlngTwo.lat + latlngTwo.lng;
|
|
1009
|
+
});
|
|
1010
|
+
rangingPolylines[polygonIndex] && rangingPolylines[polygonIndex].remove();
|
|
1011
|
+
rangingPolylines.splice(polygonIndex, 1);
|
|
1012
|
+
const lastMarker = rangingMarker[index - 1];
|
|
1013
|
+
const customIcon = _this.DivIcon({
|
|
1014
|
+
html: `<div style="width:12px;height:12px;border-radius:9999px;background-color:${options.labelFillColor || "#fff"};border:1px solid ${options.lineColor || "#2df2ff"};position:relative;">
|
|
1015
|
+
<div style="position:absolute;left:0;top:12px;padding-left:4px;padding-right:4px;font-size:12px;line-height:16px;background-color:#fff;border:1px solid #000;color:#000;white-space:nowrap;">${lastMarker.options.extData.distance}km
|
|
1016
|
+
<i data-id="${lastMarker.options.extData.dicId}" class="el-icon-close"></i>
|
|
1017
|
+
<i data-id="delete-all" class="el-icon-delete"></i>
|
|
1018
|
+
</div>
|
|
1019
|
+
</div>`,
|
|
1020
|
+
className: "my-div-icon",
|
|
1021
|
+
iconSize: [remToPx(0.75), remToPx(0.75)],
|
|
1022
|
+
iconAnchor: [remToPx(0.375), remToPx(0.375)]
|
|
1023
|
+
});
|
|
1024
|
+
lastMarker.setIcon({ divIcon: customIcon });
|
|
1025
|
+
setTimeout(() => {
|
|
1026
|
+
rangingMarker[index].remove();
|
|
1027
|
+
rangingMarker.splice(index, 1);
|
|
1028
|
+
});
|
|
1029
|
+
} else {
|
|
1030
|
+
const latlngOne = rangingMarker[index - 1]?.options?.extData?.latlng;
|
|
1031
|
+
const latlngTwo = rangingMarker[index]?.options?.extData?.latlng;
|
|
1032
|
+
const polygonIndex = rangingPolylines.findIndex((v) => {
|
|
1033
|
+
const extData = v.options.extData;
|
|
1034
|
+
return rangEndIndex === extData.index && extData.latlngs === "" + latlngOne.lat + latlngOne.lng + latlngTwo.lat + latlngTwo.lng;
|
|
1035
|
+
});
|
|
1036
|
+
rangingPolylines[polygonIndex] && rangingPolylines[polygonIndex].remove();
|
|
1037
|
+
rangingPolylines.splice(polygonIndex, 1);
|
|
1038
|
+
setTimeout(() => {
|
|
1039
|
+
rangingMarker[index - 1].remove();
|
|
1040
|
+
rangingMarker[index].remove();
|
|
1041
|
+
rangingMarker.splice(index, 1);
|
|
1042
|
+
rangingMarker.splice(index - 1, 1);
|
|
1043
|
+
});
|
|
1044
|
+
}
|
|
1045
|
+
}
|
|
1046
|
+
}
|
|
1047
|
+
}
|
|
1048
|
+
function deleteAll() {
|
|
1049
|
+
for (let i = 0; i < rangingPolylines.length; i++) {
|
|
1050
|
+
const polygon = rangingPolylines[i];
|
|
1051
|
+
if (polygon?.options?.extData?.index === rangEndIndex) {
|
|
1052
|
+
polygon.remove();
|
|
1053
|
+
rangingPolylines.splice(i, 1);
|
|
1054
|
+
i--;
|
|
1055
|
+
}
|
|
1056
|
+
}
|
|
1057
|
+
setTimeout(() => {
|
|
1058
|
+
let index = rangingMarker.findIndex((v) => {
|
|
1059
|
+
const extData = v?.options?.extData;
|
|
1060
|
+
return extData?.index === rangEndIndex && extData?.latlng?.lat === lat && extData?.latlng?.lng === lng;
|
|
1061
|
+
});
|
|
1062
|
+
while (rangingMarker[index]?.options?.extData?.distance) {
|
|
1063
|
+
rangingMarker[index].remove();
|
|
1064
|
+
rangingMarker.splice(index, 1);
|
|
1065
|
+
index--;
|
|
1066
|
+
}
|
|
1067
|
+
rangingMarker[index].remove();
|
|
1068
|
+
rangingMarker.splice(index, 1);
|
|
1069
|
+
});
|
|
1070
|
+
}
|
|
1071
|
+
}
|
|
1072
|
+
function setRangingTrunEnd() {
|
|
1073
|
+
const marker = rangingMarker[rangingMarker.length - 1];
|
|
1074
|
+
if (marker) {
|
|
1075
|
+
if (marker.options.extData.distance) {
|
|
1076
|
+
const customIcon = _this.DivIcon({
|
|
1077
|
+
html: `<div style="width:12px;height:12px;border-radius:9999px;background-color:${options.labelFillColor || "#fff"};border:1px solid ${options.lineColor || "#2df2ff"};position:relative;">
|
|
1078
|
+
<div style="position:absolute;left:0;top:12px;padding-left:4px;padding-right:4px;font-size:12px;line-height:16px;background-color:#fff;border:1px solid #000;color:#000;white-space:nowrap;">${marker.options.extData.distance}km
|
|
1079
|
+
<i data-id="${marker.options.extData.dicId}" class="el-icon-close"></i>
|
|
1080
|
+
<i data-id="delete-all" class="el-icon-delete"></i>
|
|
1081
|
+
</div>
|
|
1082
|
+
</div>`,
|
|
1083
|
+
className: "my-div-icon",
|
|
1084
|
+
iconSize: [remToPx(0.75), remToPx(0.75)],
|
|
1085
|
+
iconAnchor: [remToPx(0.375), remToPx(0.375)]
|
|
1086
|
+
});
|
|
1087
|
+
marker.setIcon({ divIcon: customIcon });
|
|
1088
|
+
} else {
|
|
1089
|
+
marker.remove();
|
|
1090
|
+
rangingMarker.splice(rangingMarker.length - 1, 1);
|
|
1091
|
+
}
|
|
1092
|
+
}
|
|
1093
|
+
rangingPointsEnd.push(rangingPointsIng);
|
|
1094
|
+
rangingPointsIng = [];
|
|
1095
|
+
}
|
|
1096
|
+
const handlers = {
|
|
1097
|
+
turnOn: function(target) {
|
|
1098
|
+
if (rangingTrun) return;
|
|
1099
|
+
map.on("click", rangingClick);
|
|
1100
|
+
map.on("contextmenu", setRangingTrunEnd);
|
|
1101
|
+
rangingTrun = true;
|
|
1102
|
+
},
|
|
1103
|
+
turnOff: function(target) {
|
|
1104
|
+
if (!rangingTrun) return;
|
|
1105
|
+
rangingMarker.forEach((marker) => {
|
|
1106
|
+
marker && marker?.remove();
|
|
1107
|
+
});
|
|
1108
|
+
rangingPolylines.forEach((polygon) => {
|
|
1109
|
+
polygon && polygon?.remove();
|
|
1110
|
+
});
|
|
1111
|
+
map.off("click", rangingClick);
|
|
1112
|
+
map.off("contextmenu", setRangingTrunEnd);
|
|
1113
|
+
rangingMarker = [];
|
|
1114
|
+
rangingPolylines = [];
|
|
1115
|
+
rangingPointsIng = [];
|
|
1116
|
+
rangingPointsEnd = [];
|
|
1117
|
+
rangingTrun = false;
|
|
1118
|
+
},
|
|
1119
|
+
remove: function(target) {
|
|
1120
|
+
if (!rangingTrun) return;
|
|
1121
|
+
rangingMarker.forEach((marker) => {
|
|
1122
|
+
marker && marker?.remove();
|
|
1123
|
+
});
|
|
1124
|
+
rangingPolylines.forEach((polygon) => {
|
|
1125
|
+
polygon && polygon?.remove();
|
|
1126
|
+
});
|
|
1127
|
+
map.off("click", rangingClick);
|
|
1128
|
+
map.off("contextmenu", setRangingTrunEnd);
|
|
1129
|
+
rangingTrun = false;
|
|
1130
|
+
rangingMarker = null;
|
|
1131
|
+
rangingPolylines = null;
|
|
1132
|
+
rangingPointsIng = null;
|
|
1133
|
+
rangingPointsEnd = null;
|
|
1134
|
+
}
|
|
1135
|
+
};
|
|
1136
|
+
return mapProxy.createMapProxy({}, handlers);
|
|
1137
|
+
}
|
|
1138
|
+
}
|
|
1139
|
+
|
|
1140
|
+
exports.default = bigMap;
|