hy-dispatch-ui-v3 0.2.53 → 0.2.55
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,1360 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
|
+
|
|
5
|
+
var events = require('events');
|
|
6
|
+
var L = require('leaflet');
|
|
7
|
+
var webgis = require('../js/webgis.js');
|
|
8
|
+
var mapProxy = require('../js/mapProxy.js');
|
|
9
|
+
var esriNS = require('esri-leaflet');
|
|
10
|
+
var cluster = require('esri-leaflet-cluster');
|
|
11
|
+
var related = require('esri-leaflet-related/dist/esri-leaflet-related');
|
|
12
|
+
|
|
13
|
+
function _interopNamespaceDefault(e) {
|
|
14
|
+
var n = Object.create(null);
|
|
15
|
+
if (e) {
|
|
16
|
+
Object.keys(e).forEach(function (k) {
|
|
17
|
+
if (k !== 'default') {
|
|
18
|
+
var d = Object.getOwnPropertyDescriptor(e, k);
|
|
19
|
+
Object.defineProperty(n, k, d.get ? d : {
|
|
20
|
+
enumerable: true,
|
|
21
|
+
get: function () { return e[k]; }
|
|
22
|
+
});
|
|
23
|
+
}
|
|
24
|
+
});
|
|
25
|
+
}
|
|
26
|
+
n.default = e;
|
|
27
|
+
return Object.freeze(n);
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
var esriNS__namespace = /*#__PURE__*/_interopNamespaceDefault(esriNS);
|
|
31
|
+
var cluster__namespace = /*#__PURE__*/_interopNamespaceDefault(cluster);
|
|
32
|
+
|
|
33
|
+
var __defProp = Object.defineProperty;
|
|
34
|
+
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
35
|
+
var __publicField = (obj, key, value) => __defNormalProp(obj, key + "" , value);
|
|
36
|
+
import "leaflet/dist/leaflet.css";
|
|
37
|
+
|
|
38
|
+
import "leaflet.pm/dist/leaflet.pm.css";
|
|
39
|
+
|
|
40
|
+
import "leaflet.markercluster/dist/MarkerCluster.Default.css";
|
|
41
|
+
|
|
42
|
+
const esri = { ...esriNS__namespace };
|
|
43
|
+
L.esri = esri;
|
|
44
|
+
L.esri.Cluster = cluster__namespace;
|
|
45
|
+
L.esri.Related = related;
|
|
46
|
+
const DEFAULT_CRS = L.CRS.EPSG3857;
|
|
47
|
+
const CIRCLE_SEGMENTS = 36;
|
|
48
|
+
const DEFAULT_TILE_FILTER = "grayscale(98%) invert(100%) sepia(20%) hue-rotate(180deg) saturate(1600%) brightness(80%) contrast(90%)";
|
|
49
|
+
const PM_TYPES = {
|
|
50
|
+
rectangle: "Rectangle",
|
|
51
|
+
circle: "Circle",
|
|
52
|
+
polygon: "Polygon"
|
|
53
|
+
};
|
|
54
|
+
const DEFAULT_MAP_OPTIONS = {
|
|
55
|
+
zoomControl: false,
|
|
56
|
+
// 禁用 + - 按钮
|
|
57
|
+
doubleClickZoom: true,
|
|
58
|
+
// 禁用双击放大
|
|
59
|
+
attributionControl: false,
|
|
60
|
+
// 移除右下角leaflet标识
|
|
61
|
+
dragging: true,
|
|
62
|
+
// 禁止鼠标拖动滚动
|
|
63
|
+
boxZoom: true,
|
|
64
|
+
// 决定地图是否可被缩放到鼠标拖拽出的矩形的视图,鼠标拖拽时需要同时按住shift键.
|
|
65
|
+
scrollWheelZoom: true
|
|
66
|
+
// 禁止鼠标滚动缩放
|
|
67
|
+
};
|
|
68
|
+
const remToPx = (rem) => {
|
|
69
|
+
const rootFontSize = parseFloat(
|
|
70
|
+
getComputedStyle(document.documentElement).fontSize
|
|
71
|
+
);
|
|
72
|
+
return rem * rootFontSize;
|
|
73
|
+
};
|
|
74
|
+
const createUniqueId = () => {
|
|
75
|
+
const random = Number(Math.random().toString().substr(2)).toString(36);
|
|
76
|
+
return `${Date.now().toString(36)}${random}`;
|
|
77
|
+
};
|
|
78
|
+
const generalMapMethods = {
|
|
79
|
+
/**
|
|
80
|
+
* 包装Bounds(导入转换)
|
|
81
|
+
* @param {L.Layer} target - 图层实例
|
|
82
|
+
* @returns {L.LatLngBounds} 包装后的Bounds
|
|
83
|
+
*/
|
|
84
|
+
getBounds(target) {
|
|
85
|
+
const bounds = target.getBounds();
|
|
86
|
+
const southWest = bounds.getSouthWest();
|
|
87
|
+
const northEast = bounds.getNorthEast();
|
|
88
|
+
const center = bounds.getCenter();
|
|
89
|
+
bounds.getSouthWest = () => {
|
|
90
|
+
const { lat, lng } = latAndLngCheck(southWest);
|
|
91
|
+
return L.latLng(lat, lng);
|
|
92
|
+
};
|
|
93
|
+
bounds.getNorthEast = () => {
|
|
94
|
+
const { lat, lng } = latAndLngCheck(northEast);
|
|
95
|
+
return L.latLng(lat, lng);
|
|
96
|
+
};
|
|
97
|
+
bounds.getCenter = () => {
|
|
98
|
+
const { lat, lng } = latAndLngCheck(center);
|
|
99
|
+
return L.latLng(lat, lng);
|
|
100
|
+
};
|
|
101
|
+
return bounds;
|
|
102
|
+
},
|
|
103
|
+
/**
|
|
104
|
+
* 包装Map实例
|
|
105
|
+
* @param {L.Map} map - 地图实例
|
|
106
|
+
* @returns {Proxy} 包装后的Map
|
|
107
|
+
*/
|
|
108
|
+
getMap(map) {
|
|
109
|
+
return mapProxy.createMapProxy(getInitMap(map), {
|
|
110
|
+
getCenter(target) {
|
|
111
|
+
const center = target.getCenter();
|
|
112
|
+
const { lng, lat } = latAndLngCheck(center);
|
|
113
|
+
return L.latLng(lat, lng);
|
|
114
|
+
}
|
|
115
|
+
});
|
|
116
|
+
},
|
|
117
|
+
/**
|
|
118
|
+
* 包装Bounds(导出转换)
|
|
119
|
+
* @param {L.Layer} target - 图层实例
|
|
120
|
+
* @returns {L.LatLngBounds} 包装后的Bounds
|
|
121
|
+
*/
|
|
122
|
+
getBoundsExport(target) {
|
|
123
|
+
const bounds = target.getBounds();
|
|
124
|
+
const southWest = bounds.getSouthWest();
|
|
125
|
+
const northEast = bounds.getNorthEast();
|
|
126
|
+
const center = bounds.getCenter();
|
|
127
|
+
bounds.getSouthWest = () => {
|
|
128
|
+
const { lat, lng } = latAndLngCheckExport(southWest);
|
|
129
|
+
return L.latLng(lat, lng);
|
|
130
|
+
};
|
|
131
|
+
bounds.getNorthEast = () => {
|
|
132
|
+
const { lat, lng } = latAndLngCheckExport(northEast);
|
|
133
|
+
return L.latLng(lat, lng);
|
|
134
|
+
};
|
|
135
|
+
bounds.getCenter = () => {
|
|
136
|
+
const { lat, lng } = latAndLngCheckExport(center);
|
|
137
|
+
return L.latLng(lat, lng);
|
|
138
|
+
};
|
|
139
|
+
return bounds;
|
|
140
|
+
}
|
|
141
|
+
};
|
|
142
|
+
function latAndLngCheck(item) {
|
|
143
|
+
const isArray = Array.isArray(item);
|
|
144
|
+
return webgis.importCoordinate({
|
|
145
|
+
lat: isArray ? item[0] : item.lat,
|
|
146
|
+
lng: isArray ? item[1] : item.lng
|
|
147
|
+
});
|
|
148
|
+
}
|
|
149
|
+
function latAndLngCheckExport(item) {
|
|
150
|
+
const isArray = Array.isArray(item);
|
|
151
|
+
return webgis.exportCoordinate({
|
|
152
|
+
lat: isArray ? item[0] : item.lat,
|
|
153
|
+
lng: isArray ? item[1] : item.lng
|
|
154
|
+
});
|
|
155
|
+
}
|
|
156
|
+
function latLngListCheck(dataList = []) {
|
|
157
|
+
return dataList.map((item) => {
|
|
158
|
+
const isArray = Array.isArray(item);
|
|
159
|
+
const { lat, lng } = latAndLngCheck(item);
|
|
160
|
+
return isArray ? [lat, lng] : { ...item, lat, lng };
|
|
161
|
+
});
|
|
162
|
+
}
|
|
163
|
+
function latLngListCheckExport(dataList = []) {
|
|
164
|
+
return dataList.map((item) => {
|
|
165
|
+
const isArray = Array.isArray(item);
|
|
166
|
+
const { lat, lng } = latAndLngCheckExport(item);
|
|
167
|
+
return isArray ? [lat, lng] : { ...item, lat, lng };
|
|
168
|
+
});
|
|
169
|
+
}
|
|
170
|
+
function circleToPolygonPoints(center, radius, asObject = false) {
|
|
171
|
+
const points = [];
|
|
172
|
+
const angleStep = Math.PI * 2 / CIRCLE_SEGMENTS;
|
|
173
|
+
for (let i = 0; i < CIRCLE_SEGMENTS; i++) {
|
|
174
|
+
const angle = angleStep * i;
|
|
175
|
+
const lat = center.lat + radius * Math.cos(angle) / 111.32;
|
|
176
|
+
const lng = center.lng + radius * Math.sin(angle) / (111.32 * Math.cos(center.lat * Math.PI / 180));
|
|
177
|
+
points.push(asObject ? { lat, lng } : [lat, lng]);
|
|
178
|
+
}
|
|
179
|
+
return points;
|
|
180
|
+
}
|
|
181
|
+
function wrapDrawLayer(layer) {
|
|
182
|
+
const bounds = layer.getBounds();
|
|
183
|
+
if (!layer.getLatLngs) {
|
|
184
|
+
layer.getLatLngs = () => {
|
|
185
|
+
const points = circleToPolygonPoints(
|
|
186
|
+
layer.getLatLng(),
|
|
187
|
+
layer.getRadius() / 1e3,
|
|
188
|
+
true
|
|
189
|
+
);
|
|
190
|
+
return [latLngListCheckExport(points)];
|
|
191
|
+
};
|
|
192
|
+
} else {
|
|
193
|
+
const latLngList = layer.getLatLngs();
|
|
194
|
+
layer.getLatLngs = () => {
|
|
195
|
+
const item = JSON.parse(JSON.stringify(latLngList[0]));
|
|
196
|
+
return [latLngListCheckExport([...item])];
|
|
197
|
+
};
|
|
198
|
+
}
|
|
199
|
+
layer.getBounds = () => {
|
|
200
|
+
const southWest = bounds.getSouthWest();
|
|
201
|
+
const northEast = bounds.getNorthEast();
|
|
202
|
+
bounds.getSouthWest = () => {
|
|
203
|
+
const { lat, lng } = latAndLngCheckExport(southWest);
|
|
204
|
+
return L.latLng(lat, lng);
|
|
205
|
+
};
|
|
206
|
+
bounds.getNorthEast = () => {
|
|
207
|
+
const { lat, lng } = latAndLngCheckExport(northEast);
|
|
208
|
+
return L.latLng(lat, lng);
|
|
209
|
+
};
|
|
210
|
+
return bounds;
|
|
211
|
+
};
|
|
212
|
+
}
|
|
213
|
+
function createClickHandler(fn, context, target, withOriginEvent = false) {
|
|
214
|
+
return (e) => {
|
|
215
|
+
const newEvent = withOriginEvent ? { ...e, originEvent: e.originalEvent } : { ...e };
|
|
216
|
+
const { lat, lng } = latAndLngCheckExport(newEvent.latlng);
|
|
217
|
+
newEvent.latlng = L.latLng(lat, lng);
|
|
218
|
+
fn.call(context || target, newEvent);
|
|
219
|
+
};
|
|
220
|
+
}
|
|
221
|
+
function getCrs(crs) {
|
|
222
|
+
if (crs === "CRS4490" && !L.CRS.CRS4490) {
|
|
223
|
+
const matrixIds = Array.from({ length: 24 }, (_, i) => i);
|
|
224
|
+
const resolutions = [
|
|
225
|
+
29582935545456606e-8,
|
|
226
|
+
14791467772728303e-8,
|
|
227
|
+
7395733886364101e-8,
|
|
228
|
+
36978669431821e-6,
|
|
229
|
+
1848933471591e-5,
|
|
230
|
+
9244667357955e-6,
|
|
231
|
+
4622333678977999e-9,
|
|
232
|
+
2.3111668394889995e6,
|
|
233
|
+
1.1555834197439998e6,
|
|
234
|
+
577791.7098719999,
|
|
235
|
+
288895.85493599996,
|
|
236
|
+
144447.92746799998,
|
|
237
|
+
72223.96373399999,
|
|
238
|
+
36111.981866999995,
|
|
239
|
+
18055.990934000005,
|
|
240
|
+
9027.995467000002,
|
|
241
|
+
4513.997732999999,
|
|
242
|
+
2256.9988670000002,
|
|
243
|
+
1128.499433,
|
|
244
|
+
564.2497170000001,
|
|
245
|
+
282.124858,
|
|
246
|
+
141.062429,
|
|
247
|
+
70.53121499999999,
|
|
248
|
+
35.26560700000001
|
|
249
|
+
].map((item) => 0.0254 * item / (96 * (Math.PI * 2 * 6378137 / 360)));
|
|
250
|
+
L.CRS.CRS4490 = new L.Proj.CRS(
|
|
251
|
+
"EPSG:4490",
|
|
252
|
+
"+proj=longlat +ellps=GRS80 +no_defs +type=crs",
|
|
253
|
+
{ matrixIds, resolutions, origin: [-180, 90] }
|
|
254
|
+
);
|
|
255
|
+
}
|
|
256
|
+
return crs ? L.CRS[`${crs}`] : DEFAULT_CRS;
|
|
257
|
+
}
|
|
258
|
+
function getInitMap(map) {
|
|
259
|
+
return map?.getInitMap ? map.getInitMap() : map;
|
|
260
|
+
}
|
|
261
|
+
function rangingStartIconOption(options, dicId) {
|
|
262
|
+
return {
|
|
263
|
+
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;">
|
|
264
|
+
<div style="width:12px;height:12px;border-radius:9999px;background-color:${options.labelFillColor || "#fff"};border:1px solid ${options.lineColor || "#2df2ff"};"></div>
|
|
265
|
+
<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
|
|
266
|
+
<i data-id="${dicId}" class="el-icon-close"></i></div>
|
|
267
|
+
</div>`,
|
|
268
|
+
iconSize: [remToPx(2), remToPx(2)],
|
|
269
|
+
iconAnchor: [remToPx(1), remToPx(1)]
|
|
270
|
+
};
|
|
271
|
+
}
|
|
272
|
+
function rangingPointIconOption(options, distance, dicId, showDeleteAll = false) {
|
|
273
|
+
return {
|
|
274
|
+
html: `<div style="width:12px;height:12px;border-radius:9999px;background-color:${options.labelFillColor || "#fff"};border:1px solid ${options.lineColor || "#2df2ff"};position:relative;">
|
|
275
|
+
<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
|
|
276
|
+
<i data-id="${dicId}" class="el-icon-close"></i>
|
|
277
|
+
${showDeleteAll ? '<i data-id="delete-all" class="el-icon-delete"></i>' : ""}
|
|
278
|
+
</div>
|
|
279
|
+
</div>`,
|
|
280
|
+
iconSize: [remToPx(0.75), remToPx(0.75)],
|
|
281
|
+
iconAnchor: [remToPx(0.375), remToPx(0.375)]
|
|
282
|
+
};
|
|
283
|
+
}
|
|
284
|
+
class Leafletjs extends events.EventEmitter {
|
|
285
|
+
constructor(request) {
|
|
286
|
+
super();
|
|
287
|
+
// 绘画多边形覆盖物
|
|
288
|
+
__publicField(this, "Polygon", (pathList = [], option) => {
|
|
289
|
+
if (pathList && pathList.length !== 0) {
|
|
290
|
+
pathList = latLngListCheck(pathList);
|
|
291
|
+
}
|
|
292
|
+
const polygon = L.polygon(pathList, option);
|
|
293
|
+
const wrappedHandlers = mapProxy.createWrappedHandlerStore();
|
|
294
|
+
const handlers = {
|
|
295
|
+
addTo: function(target, map) {
|
|
296
|
+
return target.addTo(generalMapMethods.getMap(map));
|
|
297
|
+
},
|
|
298
|
+
// 四个角
|
|
299
|
+
getBounds: function(target) {
|
|
300
|
+
return generalMapMethods.getBoundsExport(target);
|
|
301
|
+
},
|
|
302
|
+
getLatLngs: function(target) {
|
|
303
|
+
const latLngList = target.getLatLngs();
|
|
304
|
+
const item = JSON.parse(JSON.stringify(latLngList[0]));
|
|
305
|
+
return [latLngListCheckExport([...item])];
|
|
306
|
+
},
|
|
307
|
+
// 修改位置
|
|
308
|
+
setLatLngs: function(target, lngLatList = []) {
|
|
309
|
+
return target.setLatLngs(latLngListCheck(lngLatList));
|
|
310
|
+
},
|
|
311
|
+
on: function(target, types, fn, context) {
|
|
312
|
+
if (types === "click") {
|
|
313
|
+
const customClickHandler = createClickHandler(fn, context, target);
|
|
314
|
+
wrappedHandlers.remember(types, fn, customClickHandler);
|
|
315
|
+
return target.on(types, customClickHandler, context);
|
|
316
|
+
}
|
|
317
|
+
return target.on(types, fn, context);
|
|
318
|
+
},
|
|
319
|
+
off: function(target, types, fn, context) {
|
|
320
|
+
const wrappedFn = wrappedHandlers.take(types, fn);
|
|
321
|
+
return target.off(types, wrappedFn || fn, context);
|
|
322
|
+
}
|
|
323
|
+
};
|
|
324
|
+
return mapProxy.createMapProxy(polygon, handlers);
|
|
325
|
+
});
|
|
326
|
+
this.initParams = request;
|
|
327
|
+
}
|
|
328
|
+
// 初始化地图
|
|
329
|
+
InitMap(domId, option) {
|
|
330
|
+
option = {
|
|
331
|
+
// 其他配置项
|
|
332
|
+
...DEFAULT_MAP_OPTIONS,
|
|
333
|
+
...option,
|
|
334
|
+
minZoom: option.minZoom,
|
|
335
|
+
maxZoom: option.maxZoom,
|
|
336
|
+
zoom: option.zoom,
|
|
337
|
+
center: option.center,
|
|
338
|
+
crs: getCrs(this.initParams.crs)
|
|
339
|
+
};
|
|
340
|
+
const center = option.center;
|
|
341
|
+
const { lat, lng } = latAndLngCheck([center.lat, center.lng]);
|
|
342
|
+
option.center = [lat, lng];
|
|
343
|
+
const newMap = L.map(domId, option);
|
|
344
|
+
newMap.getInitMap = () => newMap;
|
|
345
|
+
const wrappedHandlers = mapProxy.createWrappedHandlerStore();
|
|
346
|
+
const handlers = {
|
|
347
|
+
// 删除地图
|
|
348
|
+
removeMap: function(target, params) {
|
|
349
|
+
if (!params) {
|
|
350
|
+
target.remove();
|
|
351
|
+
target.off();
|
|
352
|
+
wrappedHandlers.clear();
|
|
353
|
+
}
|
|
354
|
+
},
|
|
355
|
+
fitBounds: function(target, params) {
|
|
356
|
+
if (!Array.isArray(params)) {
|
|
357
|
+
params = [params];
|
|
358
|
+
}
|
|
359
|
+
const fitBoundsList = params.map(
|
|
360
|
+
(item) => mapProxy.createMapProxy(item, {
|
|
361
|
+
getBounds: (boundsTarget) => generalMapMethods.getBounds(boundsTarget)
|
|
362
|
+
})
|
|
363
|
+
);
|
|
364
|
+
return target.fitBounds(fitBoundsList);
|
|
365
|
+
},
|
|
366
|
+
// 获取中心点
|
|
367
|
+
getCenter: function(target) {
|
|
368
|
+
const center2 = target.getCenter();
|
|
369
|
+
const { lng: lng2, lat: lat2 } = latAndLngCheckExport(center2);
|
|
370
|
+
return L.latLng(lat2, lng2);
|
|
371
|
+
},
|
|
372
|
+
// 四个角
|
|
373
|
+
getBounds: function(target) {
|
|
374
|
+
const bounds = target.getBounds();
|
|
375
|
+
const southWest = bounds.getSouthWest();
|
|
376
|
+
const northEast = bounds.getNorthEast();
|
|
377
|
+
bounds.getSouthWest = () => {
|
|
378
|
+
const { lat: lat2, lng: lng2 } = latAndLngCheckExport(southWest);
|
|
379
|
+
return L.latLng(lat2, lng2);
|
|
380
|
+
};
|
|
381
|
+
bounds.getNorthEast = () => {
|
|
382
|
+
const { lat: lat2, lng: lng2 } = latAndLngCheckExport(northEast);
|
|
383
|
+
return L.latLng(lat2, lng2);
|
|
384
|
+
};
|
|
385
|
+
return bounds;
|
|
386
|
+
},
|
|
387
|
+
// 移动至目标位置
|
|
388
|
+
panTo: function(target, center2, options) {
|
|
389
|
+
const { lat: lat2, lng: lng2 } = latAndLngCheck(center2);
|
|
390
|
+
return target.panTo(L.latLng(lat2, lng2), options);
|
|
391
|
+
},
|
|
392
|
+
// 移动至目标位置并缩放图层
|
|
393
|
+
setView: function(target, center2, zoom, options) {
|
|
394
|
+
const { lat: lat2, lng: lng2 } = latAndLngCheck(center2);
|
|
395
|
+
return target.setView(L.latLng(lat2, lng2), zoom, options);
|
|
396
|
+
},
|
|
397
|
+
// 自定义地图
|
|
398
|
+
on: function(target, types, fn, context) {
|
|
399
|
+
if (types === "click") {
|
|
400
|
+
const customClickHandler = createClickHandler(fn, context, target);
|
|
401
|
+
wrappedHandlers.remember(types, fn, customClickHandler);
|
|
402
|
+
return target.on(types, customClickHandler, context);
|
|
403
|
+
} else if (types === "pm:create") {
|
|
404
|
+
const customClickHandler = (e) => {
|
|
405
|
+
const newEvent = { ...e };
|
|
406
|
+
wrapDrawLayer(newEvent.layer);
|
|
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
|
+
const map = mapProxy.createMapProxy(newMap, handlers);
|
|
420
|
+
map.id = createUniqueId();
|
|
421
|
+
map.whenReady(() => {
|
|
422
|
+
if (option.completeCallbacks) {
|
|
423
|
+
option.completeCallbacks();
|
|
424
|
+
}
|
|
425
|
+
});
|
|
426
|
+
this.setLayersUrl(map);
|
|
427
|
+
return map;
|
|
428
|
+
}
|
|
429
|
+
// 设置地图瓦片地址
|
|
430
|
+
setLayersUrl(map) {
|
|
431
|
+
const layersUrlList = this.initParams.layersUrlList || [];
|
|
432
|
+
const layersIndex = this.initParams.layersIndex || 0;
|
|
433
|
+
const layersOption = layersUrlList[layersIndex];
|
|
434
|
+
if (!layersOption) {
|
|
435
|
+
return;
|
|
436
|
+
}
|
|
437
|
+
const { mapServerType } = this.initParams;
|
|
438
|
+
if (mapServerType === "WMTS" || mapServerType === "Dynamic") {
|
|
439
|
+
return this.createLayers(map, layersOption);
|
|
440
|
+
}
|
|
441
|
+
const { layersUrls = "", filter, key } = layersOption;
|
|
442
|
+
layersUrls.split(",").forEach((layersUrl) => {
|
|
443
|
+
if (layersUrl.indexOf("{mapKey}") !== -1) {
|
|
444
|
+
layersUrl = layersUrl.replace("{mapKey}", key);
|
|
445
|
+
}
|
|
446
|
+
if (filter) {
|
|
447
|
+
this.createCustomLayers(map, layersUrl, { filter });
|
|
448
|
+
} else {
|
|
449
|
+
this.createLayers(map, layersUrl);
|
|
450
|
+
}
|
|
451
|
+
});
|
|
452
|
+
}
|
|
453
|
+
// 超图 WMTS 图层(不适用所有的WMTS图层,目前仅支持超图WMTS,因不同的WMTS服务规范不一样,主要体现在路由访问参数)
|
|
454
|
+
createWMTSLayer(map, option = {}) {
|
|
455
|
+
const {
|
|
456
|
+
url,
|
|
457
|
+
layer,
|
|
458
|
+
tilematrixSet,
|
|
459
|
+
format = "image/png"
|
|
460
|
+
} = typeof option === "string" ? { url: option } : option;
|
|
461
|
+
const crs = getCrs(this.initParams.crs);
|
|
462
|
+
if (!L.WMTSLayer) {
|
|
463
|
+
L.WMTSLayer = L.TileLayer.extend({
|
|
464
|
+
options: {
|
|
465
|
+
version: "1.0.0",
|
|
466
|
+
style: "default",
|
|
467
|
+
tilematrixSet: "",
|
|
468
|
+
format: "image/png",
|
|
469
|
+
tileSize: 256,
|
|
470
|
+
matrixIds: null,
|
|
471
|
+
layer: "",
|
|
472
|
+
zoomOffset: null,
|
|
473
|
+
requestEncoding: "KVP",
|
|
474
|
+
noWrap: true,
|
|
475
|
+
crs
|
|
476
|
+
},
|
|
477
|
+
initialize(layerUrl, options) {
|
|
478
|
+
this._url = layerUrl;
|
|
479
|
+
L.setOptions(this, options);
|
|
480
|
+
},
|
|
481
|
+
getTileUrl(coords) {
|
|
482
|
+
const zoom = this._getZoomForUrl();
|
|
483
|
+
const ident = this.options.matrixIds?.[zoom]?.identifier || zoom;
|
|
484
|
+
const params = {
|
|
485
|
+
service: "WMTS",
|
|
486
|
+
request: "GetTile",
|
|
487
|
+
version: this.options.version,
|
|
488
|
+
layer: this.options.layer,
|
|
489
|
+
style: this.options.style,
|
|
490
|
+
tilematrixSet: this.options.tilematrixSet,
|
|
491
|
+
format: this.options.format,
|
|
492
|
+
zoomOffset: this.options.zoomOffset,
|
|
493
|
+
crs: this.options.crs,
|
|
494
|
+
tilematrix: ident,
|
|
495
|
+
tilerow: coords.y,
|
|
496
|
+
tilecol: coords.x
|
|
497
|
+
};
|
|
498
|
+
return this._url + L.Util.getParamString(params, this._url);
|
|
499
|
+
}
|
|
500
|
+
});
|
|
501
|
+
L.wmtsLayer = (layerUrl, options) => new L.WMTSLayer(layerUrl, options);
|
|
502
|
+
}
|
|
503
|
+
const matrixIds = Array.from({ length: 21 }, (_, i) => ({
|
|
504
|
+
identifier: `${i}`
|
|
505
|
+
}));
|
|
506
|
+
const wmtsLayer = L.wmtsLayer(url, {
|
|
507
|
+
layer,
|
|
508
|
+
style: "default",
|
|
509
|
+
tilematrixSet,
|
|
510
|
+
format,
|
|
511
|
+
matrixIds,
|
|
512
|
+
tileSize: 256,
|
|
513
|
+
version: "1.0.0",
|
|
514
|
+
noWrap: true,
|
|
515
|
+
zoomOffset: url.includes("chinaMap/wmts") ? 1 : 0
|
|
516
|
+
});
|
|
517
|
+
wmtsLayer.addTo(getInitMap(map));
|
|
518
|
+
return wmtsLayer;
|
|
519
|
+
}
|
|
520
|
+
// arcgis 动态图层
|
|
521
|
+
createDynamicLayer(map, url) {
|
|
522
|
+
const arcLayer = L.esri.dynamicMapLayer({
|
|
523
|
+
url,
|
|
524
|
+
f: "image",
|
|
525
|
+
format: "png24",
|
|
526
|
+
opacity: 1,
|
|
527
|
+
transparent: false
|
|
528
|
+
});
|
|
529
|
+
arcLayer.addTo(getInitMap(map));
|
|
530
|
+
return arcLayer;
|
|
531
|
+
}
|
|
532
|
+
// 切片图层
|
|
533
|
+
createLayers(map, url, option = {}) {
|
|
534
|
+
const { zoomOffset, mapServerType } = this.initParams;
|
|
535
|
+
if (mapServerType === "WMTS") return this.createWMTSLayer(map, url);
|
|
536
|
+
if (mapServerType === "Dynamic")
|
|
537
|
+
return this.createDynamicLayer(map, url.url || url);
|
|
538
|
+
const newLeayer = L.tileLayer(url, {
|
|
539
|
+
...option,
|
|
540
|
+
zoomOffset: zoomOffset || 0
|
|
541
|
+
});
|
|
542
|
+
newLeayer.addTo(generalMapMethods.getMap(map));
|
|
543
|
+
return newLeayer;
|
|
544
|
+
}
|
|
545
|
+
// 切片图层(自定义滤镜)
|
|
546
|
+
createCustomLayers(map, url, option = {}) {
|
|
547
|
+
const { zoomOffset, mapServerType } = this.initParams;
|
|
548
|
+
if (mapServerType === "WMTS") return this.createWMTSLayer(map, url);
|
|
549
|
+
if (mapServerType === "Dynamic")
|
|
550
|
+
return this.createDynamicLayer(map, url.url || url);
|
|
551
|
+
const filter = option.filter || DEFAULT_TILE_FILTER;
|
|
552
|
+
const CustomTileLayer = L.TileLayer.extend({
|
|
553
|
+
options: {
|
|
554
|
+
...option,
|
|
555
|
+
zoomOffset
|
|
556
|
+
},
|
|
557
|
+
createTile(coords, done) {
|
|
558
|
+
const tile = document.createElement("img");
|
|
559
|
+
tile.onload = () => done(null, tile);
|
|
560
|
+
tile.src = this.getTileUrl(coords);
|
|
561
|
+
tile.style.filter = filter;
|
|
562
|
+
return tile;
|
|
563
|
+
}
|
|
564
|
+
});
|
|
565
|
+
const newLeayer = new CustomTileLayer(url);
|
|
566
|
+
newLeayer.addTo(generalMapMethods.getMap(map));
|
|
567
|
+
return newLeayer;
|
|
568
|
+
}
|
|
569
|
+
// 地图图层
|
|
570
|
+
layerGroup(map, markers = []) {
|
|
571
|
+
return L.layerGroup(markers).addTo(getInitMap(map));
|
|
572
|
+
}
|
|
573
|
+
// 自定义图标
|
|
574
|
+
DivIcon(option) {
|
|
575
|
+
option = {
|
|
576
|
+
...option,
|
|
577
|
+
html: option.html,
|
|
578
|
+
className: option.className,
|
|
579
|
+
iconSize: option.iconSize,
|
|
580
|
+
iconAnchor: option.iconAnchor
|
|
581
|
+
};
|
|
582
|
+
return L.divIcon(option);
|
|
583
|
+
}
|
|
584
|
+
// 生成 marker
|
|
585
|
+
Marker(markerOptions) {
|
|
586
|
+
const { position = {} } = markerOptions;
|
|
587
|
+
markerOptions = {
|
|
588
|
+
...markerOptions,
|
|
589
|
+
icon: markerOptions.icon,
|
|
590
|
+
zIndexOffset: markerOptions.zIndexOffset,
|
|
591
|
+
position: [position.lat, position.lng],
|
|
592
|
+
extData: markerOptions.extData
|
|
593
|
+
};
|
|
594
|
+
if (markerOptions.position && markerOptions.position.length !== 0) {
|
|
595
|
+
const { lat, lng } = latAndLngCheck(markerOptions.position);
|
|
596
|
+
markerOptions.position = [lat, lng];
|
|
597
|
+
}
|
|
598
|
+
const marker = L.marker(markerOptions.position, markerOptions);
|
|
599
|
+
marker.getInitMarker = () => {
|
|
600
|
+
return marker;
|
|
601
|
+
};
|
|
602
|
+
const wrappedHandlers = mapProxy.createWrappedHandlerStore();
|
|
603
|
+
const handlers = {
|
|
604
|
+
addTo: function(target, map) {
|
|
605
|
+
return target.addTo(getInitMap(map));
|
|
606
|
+
},
|
|
607
|
+
removeFrom: function(target, map) {
|
|
608
|
+
return target.removeFrom(getInitMap(map));
|
|
609
|
+
},
|
|
610
|
+
// 移除(聚合点内的 marker 需要从聚合图层移除,否则残留)
|
|
611
|
+
remove: function(target) {
|
|
612
|
+
if (target._clusterRef?.removeLayer) {
|
|
613
|
+
target._clusterRef.removeLayer(target);
|
|
614
|
+
} else {
|
|
615
|
+
target.remove();
|
|
616
|
+
}
|
|
617
|
+
return target;
|
|
618
|
+
},
|
|
619
|
+
// 彻底销毁:解绑事件并释放引用,避免内存泄漏
|
|
620
|
+
destroy: function(target) {
|
|
621
|
+
handlers.remove(target);
|
|
622
|
+
target.off();
|
|
623
|
+
wrappedHandlers.clear();
|
|
624
|
+
target._clusterRef = null;
|
|
625
|
+
if (target.options) {
|
|
626
|
+
target.options.icon = null;
|
|
627
|
+
}
|
|
628
|
+
target._isDestroyed = true;
|
|
629
|
+
},
|
|
630
|
+
getLatLng: function(target) {
|
|
631
|
+
const latlng = target.getLatLng();
|
|
632
|
+
const { lat, lng } = latAndLngCheckExport(latlng);
|
|
633
|
+
return L.latLng(lat, lng);
|
|
634
|
+
},
|
|
635
|
+
// 更改标记位置。
|
|
636
|
+
setLatLng: function(target, lngAndLat) {
|
|
637
|
+
const { lat, lng } = latAndLngCheck(lngAndLat);
|
|
638
|
+
target.setLatLng([lat, lng]);
|
|
639
|
+
},
|
|
640
|
+
setIcon: function(target, iconParams) {
|
|
641
|
+
target.setIcon(iconParams.divIcon);
|
|
642
|
+
},
|
|
643
|
+
on: function(target, types, fn, context) {
|
|
644
|
+
if (types === "click") {
|
|
645
|
+
const customClickHandler = createClickHandler(
|
|
646
|
+
fn,
|
|
647
|
+
context,
|
|
648
|
+
target,
|
|
649
|
+
true
|
|
650
|
+
);
|
|
651
|
+
wrappedHandlers.remember(types, fn, customClickHandler);
|
|
652
|
+
return target.on(types, customClickHandler, context);
|
|
653
|
+
}
|
|
654
|
+
return target.on(types, fn, context);
|
|
655
|
+
},
|
|
656
|
+
off: function(target, types, fn, context) {
|
|
657
|
+
const wrappedFn = wrappedHandlers.take(types, fn);
|
|
658
|
+
return target.off(types, wrappedFn || fn, context);
|
|
659
|
+
}
|
|
660
|
+
};
|
|
661
|
+
const markerProxy = mapProxy.createMapProxy(marker, handlers);
|
|
662
|
+
marker._proxy = markerProxy;
|
|
663
|
+
return markerProxy;
|
|
664
|
+
}
|
|
665
|
+
// 生成 聚合点
|
|
666
|
+
MarkerClusterGroup(map, markerList = [], option) {
|
|
667
|
+
option = {
|
|
668
|
+
spiderfyDistanceMultiplier: 1,
|
|
669
|
+
spiderLegPolylineOptions: { weight: 1, color: "#5E9DB4", opacity: 1 },
|
|
670
|
+
...option,
|
|
671
|
+
iconCreateFunction: option.iconCreateFunction,
|
|
672
|
+
disableClusteringAtZoom: option.disableClusteringAtZoom,
|
|
673
|
+
maxClusterRadius: option.maxClusterRadius
|
|
674
|
+
};
|
|
675
|
+
const displayCluster = L.markerClusterGroup(option);
|
|
676
|
+
const nativeMap = getInitMap(map);
|
|
677
|
+
nativeMap.addLayer(displayCluster);
|
|
678
|
+
const toNativeMarkers = (list = [], clusterRef = null) => {
|
|
679
|
+
const markers = Array.isArray(list) ? list : [list];
|
|
680
|
+
return markers.map((marker) => {
|
|
681
|
+
const nativeMarker = marker?.getInitMarker ? marker.getInitMarker() : marker;
|
|
682
|
+
if (nativeMarker) nativeMarker._clusterRef = clusterRef;
|
|
683
|
+
return nativeMarker;
|
|
684
|
+
}).filter(Boolean);
|
|
685
|
+
};
|
|
686
|
+
const handlers = {
|
|
687
|
+
remove: function(target) {
|
|
688
|
+
nativeMap.removeLayer(target);
|
|
689
|
+
},
|
|
690
|
+
removeLayers: function(target, markerList2 = []) {
|
|
691
|
+
target.removeLayers(toNativeMarkers(markerList2, null));
|
|
692
|
+
target._unspiderfy?.();
|
|
693
|
+
},
|
|
694
|
+
addLayers: function(target, markerList2 = []) {
|
|
695
|
+
target.addLayers(toNativeMarkers(markerList2, target));
|
|
696
|
+
},
|
|
697
|
+
// 销毁聚合内所有 marker 并清空图层
|
|
698
|
+
destroyAll: function(target) {
|
|
699
|
+
target.getLayers().forEach((layer) => {
|
|
700
|
+
layer._clusterRef = null;
|
|
701
|
+
if (layer._proxy?.destroy) {
|
|
702
|
+
layer._proxy.destroy();
|
|
703
|
+
} else {
|
|
704
|
+
layer.off();
|
|
705
|
+
}
|
|
706
|
+
});
|
|
707
|
+
target.clearLayers();
|
|
708
|
+
}
|
|
709
|
+
};
|
|
710
|
+
const newDisplayCluster = mapProxy.createMapProxy(displayCluster, handlers);
|
|
711
|
+
newDisplayCluster.addLayers(markerList);
|
|
712
|
+
return newDisplayCluster;
|
|
713
|
+
}
|
|
714
|
+
// 绘画圆
|
|
715
|
+
Circle(latLngList = {}, option = {}) {
|
|
716
|
+
option = {
|
|
717
|
+
...option,
|
|
718
|
+
radius: option.radius,
|
|
719
|
+
color: option.color,
|
|
720
|
+
opacity: option.opacity,
|
|
721
|
+
weight: option.weight,
|
|
722
|
+
fillColor: option.fillColor,
|
|
723
|
+
fillOpacity: option.fillOpacity
|
|
724
|
+
};
|
|
725
|
+
const { lat, lng } = latAndLngCheck(latLngList);
|
|
726
|
+
latLngList = [lat, lng];
|
|
727
|
+
const circle = L.circle(latLngList, option);
|
|
728
|
+
const handlers = {
|
|
729
|
+
addTo: function(target, map) {
|
|
730
|
+
return target.addTo(generalMapMethods.getMap(map));
|
|
731
|
+
},
|
|
732
|
+
// 四个角
|
|
733
|
+
getBounds: function(target) {
|
|
734
|
+
return generalMapMethods.getBoundsExport(target);
|
|
735
|
+
},
|
|
736
|
+
// 圆形转多边形坐标
|
|
737
|
+
getLatLngs: function(target) {
|
|
738
|
+
const points = circleToPolygonPoints(
|
|
739
|
+
target.getLatLng(),
|
|
740
|
+
target.getRadius() / 1e3
|
|
741
|
+
);
|
|
742
|
+
return [latLngListCheckExport(points)];
|
|
743
|
+
}
|
|
744
|
+
};
|
|
745
|
+
return mapProxy.createMapProxy(circle, handlers);
|
|
746
|
+
}
|
|
747
|
+
// 自定义 popup
|
|
748
|
+
Popup(option) {
|
|
749
|
+
option = {
|
|
750
|
+
closeButton: false,
|
|
751
|
+
...option
|
|
752
|
+
};
|
|
753
|
+
const popup = L.popup(option);
|
|
754
|
+
const handlers = {
|
|
755
|
+
addTo: function(target, map) {
|
|
756
|
+
return target.addTo(generalMapMethods.getMap(map));
|
|
757
|
+
},
|
|
758
|
+
// 四个角
|
|
759
|
+
getBounds: function(target) {
|
|
760
|
+
return generalMapMethods.getBoundsExport(target);
|
|
761
|
+
},
|
|
762
|
+
/**
|
|
763
|
+
* 修改位置
|
|
764
|
+
* @param {Array|Object} latLngList - 坐标
|
|
765
|
+
* @param {boolean} translation - 是否做坐标转换(已转换过的坐标传 false)
|
|
766
|
+
*/
|
|
767
|
+
setLatLng: function(target, latLngList, translation = true) {
|
|
768
|
+
if (latLngList && latLngList.length !== 0) {
|
|
769
|
+
const isArray = Array.isArray(latLngList);
|
|
770
|
+
const { lat, lng } = translation ? latAndLngCheck(latLngList) : {
|
|
771
|
+
lat: isArray ? latLngList[0] : latLngList.lat,
|
|
772
|
+
lng: isArray ? latLngList[1] : latLngList.lng
|
|
773
|
+
};
|
|
774
|
+
latLngList = L.latLng(lat, lng);
|
|
775
|
+
}
|
|
776
|
+
return target.setLatLng(latLngList);
|
|
777
|
+
}
|
|
778
|
+
};
|
|
779
|
+
return mapProxy.createMapProxy(popup, handlers);
|
|
780
|
+
}
|
|
781
|
+
// 自定义 线条
|
|
782
|
+
Polyline(latLngList = [], option = {}) {
|
|
783
|
+
if (latLngList && latLngList.length !== 0) {
|
|
784
|
+
latLngList = latLngListCheck(latLngList);
|
|
785
|
+
}
|
|
786
|
+
const polyline = L.polyline(latLngList, option);
|
|
787
|
+
const wrappedHandlers = mapProxy.createWrappedHandlerStore();
|
|
788
|
+
const handlers = {
|
|
789
|
+
addTo: function(target, map) {
|
|
790
|
+
return target.addTo(generalMapMethods.getMap(map));
|
|
791
|
+
},
|
|
792
|
+
// 四个角
|
|
793
|
+
getBounds: function(target) {
|
|
794
|
+
return generalMapMethods.getBoundsExport(target);
|
|
795
|
+
},
|
|
796
|
+
// 设置经纬度坐标
|
|
797
|
+
setLatLngs: function(target, lngLatList = []) {
|
|
798
|
+
return target.setLatLngs(latLngListCheck(lngLatList));
|
|
799
|
+
},
|
|
800
|
+
// 添加经纬度坐标
|
|
801
|
+
addLatLng: function(target, lngLat) {
|
|
802
|
+
return target.addLatLng(latAndLngCheck(lngLat));
|
|
803
|
+
},
|
|
804
|
+
on: function(target, types, fn, context) {
|
|
805
|
+
if (types === "click") {
|
|
806
|
+
const customClickHandler = createClickHandler(fn, context, target);
|
|
807
|
+
wrappedHandlers.remember(types, fn, customClickHandler);
|
|
808
|
+
return target.on(types, customClickHandler, context);
|
|
809
|
+
}
|
|
810
|
+
return target.on(types, fn, context);
|
|
811
|
+
},
|
|
812
|
+
off: function(target, types, fn, context) {
|
|
813
|
+
const wrappedFn = wrappedHandlers.take(types, fn);
|
|
814
|
+
return target.off(types, wrappedFn || fn, context);
|
|
815
|
+
}
|
|
816
|
+
};
|
|
817
|
+
return mapProxy.createMapProxy(polyline, handlers);
|
|
818
|
+
}
|
|
819
|
+
MotionPolyline(latLngList = [], option = {}, motionOption = {}, markerOption = {}) {
|
|
820
|
+
if (latLngList && latLngList.length !== 0) {
|
|
821
|
+
latLngList = latLngListCheck(latLngList);
|
|
822
|
+
}
|
|
823
|
+
const polyline = L.motion.polyline(
|
|
824
|
+
latLngList,
|
|
825
|
+
option,
|
|
826
|
+
motionOption,
|
|
827
|
+
markerOption
|
|
828
|
+
);
|
|
829
|
+
return mapProxy.createMapProxy(polyline, {
|
|
830
|
+
addTo: function(target, map) {
|
|
831
|
+
return target.addTo(generalMapMethods.getMap(map));
|
|
832
|
+
}
|
|
833
|
+
});
|
|
834
|
+
}
|
|
835
|
+
motionSeq(motion, options) {
|
|
836
|
+
const seq = L.motion.seq(motion, options);
|
|
837
|
+
return mapProxy.createMapProxy(seq, {
|
|
838
|
+
addTo: function(target, map) {
|
|
839
|
+
return target.addTo(generalMapMethods.getMap(map));
|
|
840
|
+
}
|
|
841
|
+
});
|
|
842
|
+
}
|
|
843
|
+
// 自定义 轨迹回放
|
|
844
|
+
TrackPlayer(latLngList = [], option = {}, map = null) {
|
|
845
|
+
if (!(latLngList && latLngList.length !== 0)) {
|
|
846
|
+
return null;
|
|
847
|
+
}
|
|
848
|
+
let speed = option.speed;
|
|
849
|
+
const carIcon = this.DivIcon({
|
|
850
|
+
className: "custom-marker-icon",
|
|
851
|
+
html: option.svgContent,
|
|
852
|
+
iconSize: option.iconSize || 0,
|
|
853
|
+
iconAnchor: option.iconAnchor || 0
|
|
854
|
+
});
|
|
855
|
+
const trackRoute = latLngList;
|
|
856
|
+
let trackPolyline = this.MotionPolyline(
|
|
857
|
+
trackRoute,
|
|
858
|
+
{
|
|
859
|
+
color: option.passedLineColor || "#2EE19E",
|
|
860
|
+
// 线颜色
|
|
861
|
+
weight: 4
|
|
862
|
+
},
|
|
863
|
+
{
|
|
864
|
+
speed: option.speed
|
|
865
|
+
},
|
|
866
|
+
{
|
|
867
|
+
showMarker: true,
|
|
868
|
+
icon: carIcon
|
|
869
|
+
}
|
|
870
|
+
);
|
|
871
|
+
let marker = this.motionSeq([trackPolyline]);
|
|
872
|
+
marker.on(L.Motion.Event.Ended, () => {
|
|
873
|
+
if (option.onEnd) option.onEnd();
|
|
874
|
+
});
|
|
875
|
+
let polyline = this.Polyline(trackRoute, {
|
|
876
|
+
color: option.notPassedLineColor || "#FF1875",
|
|
877
|
+
// 线颜色
|
|
878
|
+
weight: 4
|
|
879
|
+
});
|
|
880
|
+
marker.addTo(map);
|
|
881
|
+
polyline.addTo(map);
|
|
882
|
+
map.panTo([trackRoute[0].lat, trackRoute[0].lng]);
|
|
883
|
+
const handlers = {
|
|
884
|
+
// 开始
|
|
885
|
+
startAnimation: function() {
|
|
886
|
+
if (marker && marker.motionStart) {
|
|
887
|
+
trackPolyline.motionSpeed(speed);
|
|
888
|
+
marker.motionStart();
|
|
889
|
+
}
|
|
890
|
+
},
|
|
891
|
+
// 暂停
|
|
892
|
+
pauseAnimation: function() {
|
|
893
|
+
if (marker && marker.motionPause) {
|
|
894
|
+
marker.motionPause();
|
|
895
|
+
}
|
|
896
|
+
},
|
|
897
|
+
// 恢复
|
|
898
|
+
resumeAnimation: function() {
|
|
899
|
+
if (marker) {
|
|
900
|
+
marker.motionResume();
|
|
901
|
+
}
|
|
902
|
+
},
|
|
903
|
+
// 修改速度
|
|
904
|
+
motionSpeed: function(target, changeSpeed) {
|
|
905
|
+
speed = changeSpeed;
|
|
906
|
+
trackPolyline.motionSpeed(speed);
|
|
907
|
+
if (marker && marker.motionStart) {
|
|
908
|
+
marker.motionStart();
|
|
909
|
+
}
|
|
910
|
+
},
|
|
911
|
+
// 移除轨迹回放
|
|
912
|
+
removeTrackPlayer: function() {
|
|
913
|
+
marker.remove();
|
|
914
|
+
polyline.remove();
|
|
915
|
+
marker = null;
|
|
916
|
+
polyline = null;
|
|
917
|
+
trackPolyline = null;
|
|
918
|
+
}
|
|
919
|
+
};
|
|
920
|
+
return mapProxy.createMapProxy(marker, handlers);
|
|
921
|
+
}
|
|
922
|
+
// 创建绘画工具 rectangle 正方形 circle 圆形 polygon 多边形
|
|
923
|
+
CreatePm(pmType = "rectangle", options = {}, map) {
|
|
924
|
+
map.off("pm:create");
|
|
925
|
+
const drawOptions = {
|
|
926
|
+
pathOptions: {
|
|
927
|
+
color: options.fillColor || "#00b0ff"
|
|
928
|
+
},
|
|
929
|
+
snappable: true,
|
|
930
|
+
// 设置是否对齐到其他图层
|
|
931
|
+
snapDistance: 20
|
|
932
|
+
// 对齐距离阈值
|
|
933
|
+
};
|
|
934
|
+
const enableDraw = (toolType) => map.pm.enableDraw(PM_TYPES[toolType], drawOptions);
|
|
935
|
+
let layer = null;
|
|
936
|
+
const clearLayer = () => {
|
|
937
|
+
if (layer) {
|
|
938
|
+
map.removeLayer(layer);
|
|
939
|
+
layer = null;
|
|
940
|
+
}
|
|
941
|
+
};
|
|
942
|
+
enableDraw(pmType);
|
|
943
|
+
map.on("pm:create", (e) => {
|
|
944
|
+
layer = e.layer;
|
|
945
|
+
if (options.onChange) {
|
|
946
|
+
const pointsList = latLngListCheckExport(layer.getLatLngs()[0]);
|
|
947
|
+
options.onChange(pointsList);
|
|
948
|
+
}
|
|
949
|
+
});
|
|
950
|
+
const handlers = {
|
|
951
|
+
remove: function() {
|
|
952
|
+
map.off("pm:create");
|
|
953
|
+
clearLayer();
|
|
954
|
+
map.pm.disableDraw();
|
|
955
|
+
},
|
|
956
|
+
close: function() {
|
|
957
|
+
clearLayer();
|
|
958
|
+
map.pm.disableDraw();
|
|
959
|
+
},
|
|
960
|
+
setMouseTool: function(target, toolType) {
|
|
961
|
+
enableDraw(toolType);
|
|
962
|
+
}
|
|
963
|
+
};
|
|
964
|
+
return mapProxy.createMapProxy({}, handlers);
|
|
965
|
+
}
|
|
966
|
+
// 电子围栏
|
|
967
|
+
CreateFence(pmType = "rectangle", options = {}, map) {
|
|
968
|
+
let polygon = null;
|
|
969
|
+
const clearPolygon = () => {
|
|
970
|
+
if (polygon) {
|
|
971
|
+
map.removeLayer(polygon);
|
|
972
|
+
polygon = null;
|
|
973
|
+
}
|
|
974
|
+
};
|
|
975
|
+
const setPolygon = (pointList) => {
|
|
976
|
+
clearPolygon();
|
|
977
|
+
polygon = this.Polygon(pointList, {
|
|
978
|
+
...options,
|
|
979
|
+
fillColor: options.fillColor || "#00b0ff",
|
|
980
|
+
fillOpacity: options.fillOpacity || 0.5,
|
|
981
|
+
color: options.color || "#80d8ff",
|
|
982
|
+
weight: options.weight || 4,
|
|
983
|
+
opacity: options.opacity || 1,
|
|
984
|
+
zIndex: options.zIndex || 1e6
|
|
985
|
+
});
|
|
986
|
+
polygon.addTo(map);
|
|
987
|
+
map.fitBounds(polygon.getBounds());
|
|
988
|
+
polygon.pm.enable();
|
|
989
|
+
pm.close();
|
|
990
|
+
};
|
|
991
|
+
const onChange = (pointList) => {
|
|
992
|
+
setPolygon(latLngListCheck(pointList));
|
|
993
|
+
};
|
|
994
|
+
const pm = this.CreatePm(
|
|
995
|
+
pmType,
|
|
996
|
+
{
|
|
997
|
+
...options,
|
|
998
|
+
onChange
|
|
999
|
+
},
|
|
1000
|
+
map
|
|
1001
|
+
);
|
|
1002
|
+
pm.close();
|
|
1003
|
+
const handlers = {
|
|
1004
|
+
getPath: function() {
|
|
1005
|
+
return polygon ? polygon.getLatLngs()[0] : [];
|
|
1006
|
+
},
|
|
1007
|
+
// 定点绘制(radius 为直径,故取半)
|
|
1008
|
+
setFixedPoint: function(target, { lnglat, radius }) {
|
|
1009
|
+
setPolygon(circleToPolygonPoints(lnglat, radius / 2e3));
|
|
1010
|
+
},
|
|
1011
|
+
setPolygon: function(target, pointList) {
|
|
1012
|
+
setPolygon(latLngListCheck(pointList));
|
|
1013
|
+
},
|
|
1014
|
+
startDraw: function(target, toolType = "rectangle") {
|
|
1015
|
+
clearPolygon();
|
|
1016
|
+
target.setMouseTool(toolType);
|
|
1017
|
+
},
|
|
1018
|
+
clearDraw: function() {
|
|
1019
|
+
clearPolygon();
|
|
1020
|
+
},
|
|
1021
|
+
remove: function(target) {
|
|
1022
|
+
clearPolygon();
|
|
1023
|
+
target.close(true);
|
|
1024
|
+
target.remove();
|
|
1025
|
+
},
|
|
1026
|
+
close: function(target) {
|
|
1027
|
+
target.close(true);
|
|
1028
|
+
},
|
|
1029
|
+
setMouseTool: function(target, toolType) {
|
|
1030
|
+
target.setMouseTool(toolType);
|
|
1031
|
+
}
|
|
1032
|
+
};
|
|
1033
|
+
return mapProxy.createMapProxy(pm, handlers);
|
|
1034
|
+
}
|
|
1035
|
+
// 测距工具 labelColor labelFillColor lineColor
|
|
1036
|
+
RangingTool(options = {}, map) {
|
|
1037
|
+
let rangingMarker = [];
|
|
1038
|
+
let rangingPolylines = [];
|
|
1039
|
+
let rangingPointsIng = [];
|
|
1040
|
+
let rangingPointsEnd = [];
|
|
1041
|
+
let rangingTrun = false;
|
|
1042
|
+
const _this = this;
|
|
1043
|
+
function rangingClick(res) {
|
|
1044
|
+
setRangingTrun(res.latlng);
|
|
1045
|
+
}
|
|
1046
|
+
function calcTotalDistance(index, preIndex) {
|
|
1047
|
+
const current = rangingMarker[index].options.extData.latlng;
|
|
1048
|
+
const previous = rangingMarker[preIndex].options.extData.latlng;
|
|
1049
|
+
const distance = parseFloat(
|
|
1050
|
+
(map.distance(current, previous) / 1e3).toFixed(2)
|
|
1051
|
+
);
|
|
1052
|
+
const total = parseFloat(
|
|
1053
|
+
rangingMarker[preIndex].options.extData.distance || 0
|
|
1054
|
+
);
|
|
1055
|
+
return (distance + total).toFixed(2);
|
|
1056
|
+
}
|
|
1057
|
+
function setStartIcon(index) {
|
|
1058
|
+
const markerItem = rangingMarker[index];
|
|
1059
|
+
markerItem.setIcon({
|
|
1060
|
+
divIcon: _this.DivIcon(
|
|
1061
|
+
rangingStartIconOption(options, markerItem.options.extData.dicId)
|
|
1062
|
+
)
|
|
1063
|
+
});
|
|
1064
|
+
markerItem.options.extData.distance = 0;
|
|
1065
|
+
}
|
|
1066
|
+
function removeLineBetween(groupIndex, aIndex, bIndex) {
|
|
1067
|
+
const latlngOne = rangingMarker[aIndex]?.options?.extData?.latlng;
|
|
1068
|
+
const latlngTwo = rangingMarker[bIndex]?.options?.extData?.latlng;
|
|
1069
|
+
const polygonIndex = rangingPolylines.findIndex((v) => {
|
|
1070
|
+
const extData = v.options.extData;
|
|
1071
|
+
return groupIndex === extData.index && extData.latlngs === "" + latlngOne.lat + latlngOne.lng + latlngTwo.lat + latlngTwo.lng;
|
|
1072
|
+
});
|
|
1073
|
+
rangingPolylines[polygonIndex] && rangingPolylines[polygonIndex].remove();
|
|
1074
|
+
rangingPolylines.splice(polygonIndex, 1);
|
|
1075
|
+
}
|
|
1076
|
+
function setPointIcon(index, distance, showDeleteAll) {
|
|
1077
|
+
const markerItem = rangingMarker[index];
|
|
1078
|
+
const isLast = showDeleteAll ?? !rangingMarker[index + 1]?.options?.extData?.distance;
|
|
1079
|
+
markerItem.setIcon({
|
|
1080
|
+
divIcon: _this.DivIcon(
|
|
1081
|
+
rangingPointIconOption(
|
|
1082
|
+
options,
|
|
1083
|
+
distance,
|
|
1084
|
+
markerItem.options.extData.dicId,
|
|
1085
|
+
isLast
|
|
1086
|
+
)
|
|
1087
|
+
)
|
|
1088
|
+
});
|
|
1089
|
+
markerItem.options.extData.distance = distance;
|
|
1090
|
+
}
|
|
1091
|
+
function setRangingTrun({ lat, lng }) {
|
|
1092
|
+
const dicId = `${rangingPointsEnd.length}-${lat}-${lng}`;
|
|
1093
|
+
if (!rangingPointsIng.length) {
|
|
1094
|
+
const customIcon = _this.DivIcon(rangingStartIconOption(options, dicId));
|
|
1095
|
+
const markerItem = _this.Marker({
|
|
1096
|
+
icon: customIcon,
|
|
1097
|
+
position: { lat, lng },
|
|
1098
|
+
extData: {
|
|
1099
|
+
latlng: { lat, lng },
|
|
1100
|
+
index: rangingPointsEnd.length,
|
|
1101
|
+
distance: 0,
|
|
1102
|
+
dicId
|
|
1103
|
+
}
|
|
1104
|
+
});
|
|
1105
|
+
markerItem.on("click", (res) => {
|
|
1106
|
+
if (res.originalEvent.target.dataset?.id) {
|
|
1107
|
+
clickItem();
|
|
1108
|
+
}
|
|
1109
|
+
});
|
|
1110
|
+
markerItem.addTo(map);
|
|
1111
|
+
rangingMarker.push(markerItem);
|
|
1112
|
+
rangingPointsIng.push({ lat, lng });
|
|
1113
|
+
} else {
|
|
1114
|
+
const latlngs = [
|
|
1115
|
+
[
|
|
1116
|
+
rangingPointsIng[rangingPointsIng.length - 1].lat,
|
|
1117
|
+
rangingPointsIng[rangingPointsIng.length - 1].lng
|
|
1118
|
+
],
|
|
1119
|
+
[lat, lng]
|
|
1120
|
+
];
|
|
1121
|
+
const polyline = _this.Polyline(latlngs, {
|
|
1122
|
+
color: options.lineColor || "#2df2ff",
|
|
1123
|
+
weight: 2,
|
|
1124
|
+
extData: {
|
|
1125
|
+
latlngs: "" + latlngs[0][0] + latlngs[0][1] + latlngs[1][0] + latlngs[1][1],
|
|
1126
|
+
index: rangingPointsEnd.length
|
|
1127
|
+
}
|
|
1128
|
+
});
|
|
1129
|
+
polyline.addTo(map);
|
|
1130
|
+
rangingPolylines.push(polyline);
|
|
1131
|
+
let distance = map.distance(
|
|
1132
|
+
{ lat: latlngs[0][0], lng: latlngs[0][1] },
|
|
1133
|
+
{ lat: latlngs[1][0], lng: latlngs[1][1] }
|
|
1134
|
+
);
|
|
1135
|
+
distance = parseFloat((distance / 1e3).toFixed(2));
|
|
1136
|
+
const total = parseFloat(
|
|
1137
|
+
rangingMarker[rangingMarker.length - 1].options.extData.distance || 0
|
|
1138
|
+
);
|
|
1139
|
+
distance = (distance + total).toFixed(2);
|
|
1140
|
+
const customIcon = _this.DivIcon(
|
|
1141
|
+
rangingPointIconOption(options, distance, dicId)
|
|
1142
|
+
);
|
|
1143
|
+
const markerItem = _this.Marker({
|
|
1144
|
+
icon: customIcon,
|
|
1145
|
+
position: { lat, lng },
|
|
1146
|
+
extData: {
|
|
1147
|
+
latlng: { lat, lng },
|
|
1148
|
+
index: rangingPointsEnd.length,
|
|
1149
|
+
distance,
|
|
1150
|
+
dicId
|
|
1151
|
+
}
|
|
1152
|
+
});
|
|
1153
|
+
markerItem.on("click", (res) => {
|
|
1154
|
+
if (res.originalEvent.target.dataset?.id === "delete-all") {
|
|
1155
|
+
deleteAll();
|
|
1156
|
+
} else if (res.originalEvent.target.dataset?.id) {
|
|
1157
|
+
clickItem();
|
|
1158
|
+
}
|
|
1159
|
+
});
|
|
1160
|
+
markerItem.addTo(map);
|
|
1161
|
+
rangingMarker.push(markerItem);
|
|
1162
|
+
rangingPointsIng.push({ lat, lng });
|
|
1163
|
+
}
|
|
1164
|
+
const rangEndIndex = rangingPointsEnd.length;
|
|
1165
|
+
function clickItem() {
|
|
1166
|
+
if (rangEndIndex === rangingPointsEnd.length) {
|
|
1167
|
+
if (options.message) {
|
|
1168
|
+
options.message({
|
|
1169
|
+
type: "warning",
|
|
1170
|
+
message: "\u8BF7\u5148\u5B8C\u6210\u672C\u6B21\u6D4B\u8DDD\uFF0C\u518D\u5220\u9664\u6D4B\u8DDD\u70B9"
|
|
1171
|
+
});
|
|
1172
|
+
}
|
|
1173
|
+
return;
|
|
1174
|
+
}
|
|
1175
|
+
const index = rangingMarker.findIndex((v) => {
|
|
1176
|
+
const extData = v?.options?.extData;
|
|
1177
|
+
return extData?.index === rangEndIndex && extData?.latlng?.lat === lat && extData?.latlng?.lng === lng;
|
|
1178
|
+
});
|
|
1179
|
+
const distance = rangingMarker[index].options.extData.distance;
|
|
1180
|
+
if (distance === 0) {
|
|
1181
|
+
const nextMarker = rangingMarker[index + 1]?.options?.extData?.distance;
|
|
1182
|
+
const nextTwo = rangingMarker[index + 2]?.options?.extData?.distance;
|
|
1183
|
+
if (!(nextMarker && nextMarker !== 0 && nextTwo && nextTwo !== 0)) {
|
|
1184
|
+
if (nextMarker) {
|
|
1185
|
+
removeLineBetween(rangEndIndex, index, index + 1);
|
|
1186
|
+
setTimeout(() => {
|
|
1187
|
+
rangingMarker[index + 1].remove();
|
|
1188
|
+
rangingMarker[index].remove();
|
|
1189
|
+
rangingMarker.splice(index, 1);
|
|
1190
|
+
setTimeout(() => {
|
|
1191
|
+
rangingMarker.splice(index, 1);
|
|
1192
|
+
});
|
|
1193
|
+
});
|
|
1194
|
+
} else {
|
|
1195
|
+
setTimeout(() => {
|
|
1196
|
+
rangingMarker[index].remove();
|
|
1197
|
+
rangingMarker.splice(index, 1);
|
|
1198
|
+
});
|
|
1199
|
+
}
|
|
1200
|
+
return;
|
|
1201
|
+
} else {
|
|
1202
|
+
removeLineBetween(rangEndIndex, index, index + 1);
|
|
1203
|
+
let changeIndex = index + 1;
|
|
1204
|
+
while (rangingMarker[changeIndex]?.options?.extData?.distance) {
|
|
1205
|
+
if (changeIndex - 1 === index) {
|
|
1206
|
+
setStartIcon(changeIndex);
|
|
1207
|
+
} else {
|
|
1208
|
+
setPointIcon(
|
|
1209
|
+
changeIndex,
|
|
1210
|
+
calcTotalDistance(changeIndex, changeIndex - 1)
|
|
1211
|
+
);
|
|
1212
|
+
}
|
|
1213
|
+
changeIndex++;
|
|
1214
|
+
}
|
|
1215
|
+
setTimeout(() => {
|
|
1216
|
+
rangingMarker[index].remove();
|
|
1217
|
+
rangingMarker.splice(index, 1);
|
|
1218
|
+
});
|
|
1219
|
+
}
|
|
1220
|
+
} else {
|
|
1221
|
+
const nextDistance = rangingMarker[index + 1]?.options?.extData?.distance;
|
|
1222
|
+
if (nextDistance) {
|
|
1223
|
+
const latlngOne = rangingMarker[index - 1]?.options?.extData?.latlng;
|
|
1224
|
+
const latlngTree = rangingMarker[index + 1]?.options?.extData?.latlng;
|
|
1225
|
+
removeLineBetween(rangEndIndex, index - 1, index);
|
|
1226
|
+
removeLineBetween(rangEndIndex, index, index + 1);
|
|
1227
|
+
const latlngs = [
|
|
1228
|
+
[latlngOne.lat, latlngOne.lng],
|
|
1229
|
+
[latlngTree.lat, latlngTree.lng]
|
|
1230
|
+
];
|
|
1231
|
+
const polyline = _this.Polyline(latlngs, {
|
|
1232
|
+
color: options.lineColor || "#2df2ff",
|
|
1233
|
+
weight: 2,
|
|
1234
|
+
extData: {
|
|
1235
|
+
latlngs: "" + latlngs[0][0] + latlngs[0][1] + latlngs[1][0] + latlngs[1][1],
|
|
1236
|
+
index: rangEndIndex
|
|
1237
|
+
}
|
|
1238
|
+
});
|
|
1239
|
+
polyline.addTo(map);
|
|
1240
|
+
rangingPolylines.push(polyline);
|
|
1241
|
+
let changeIndex = index + 1;
|
|
1242
|
+
while (rangingMarker[changeIndex]?.options?.extData?.distance) {
|
|
1243
|
+
const disIndex = changeIndex - 1 === index ? changeIndex - 2 : changeIndex - 1;
|
|
1244
|
+
setPointIcon(
|
|
1245
|
+
changeIndex,
|
|
1246
|
+
calcTotalDistance(changeIndex, disIndex)
|
|
1247
|
+
);
|
|
1248
|
+
changeIndex++;
|
|
1249
|
+
}
|
|
1250
|
+
setTimeout(() => {
|
|
1251
|
+
rangingMarker[index].remove();
|
|
1252
|
+
rangingMarker.splice(index, 1);
|
|
1253
|
+
});
|
|
1254
|
+
} else {
|
|
1255
|
+
const beforeDistance = rangingMarker[index - 1]?.options?.extData?.distance;
|
|
1256
|
+
if (beforeDistance) {
|
|
1257
|
+
removeLineBetween(rangEndIndex, index - 1, index);
|
|
1258
|
+
setPointIcon(
|
|
1259
|
+
index - 1,
|
|
1260
|
+
rangingMarker[index - 1].options.extData.distance,
|
|
1261
|
+
true
|
|
1262
|
+
);
|
|
1263
|
+
setTimeout(() => {
|
|
1264
|
+
rangingMarker[index].remove();
|
|
1265
|
+
rangingMarker.splice(index, 1);
|
|
1266
|
+
});
|
|
1267
|
+
} else {
|
|
1268
|
+
removeLineBetween(rangEndIndex, index - 1, index);
|
|
1269
|
+
setTimeout(() => {
|
|
1270
|
+
rangingMarker[index + 1].remove();
|
|
1271
|
+
rangingMarker[index].remove();
|
|
1272
|
+
rangingMarker.splice(index, 1);
|
|
1273
|
+
rangingMarker.splice(index - 1, 1);
|
|
1274
|
+
});
|
|
1275
|
+
}
|
|
1276
|
+
}
|
|
1277
|
+
}
|
|
1278
|
+
}
|
|
1279
|
+
function deleteAll() {
|
|
1280
|
+
for (let i = 0; i < rangingPolylines.length; i++) {
|
|
1281
|
+
const polygon = rangingPolylines[i];
|
|
1282
|
+
if (polygon?.options?.extData?.index === rangEndIndex) {
|
|
1283
|
+
polygon.remove();
|
|
1284
|
+
rangingPolylines.splice(i, 1);
|
|
1285
|
+
i--;
|
|
1286
|
+
}
|
|
1287
|
+
}
|
|
1288
|
+
setTimeout(() => {
|
|
1289
|
+
let index = rangingMarker.findIndex((v) => {
|
|
1290
|
+
const extData = v?.options?.extData;
|
|
1291
|
+
return extData?.index === rangEndIndex && extData?.latlng?.lat === lat && extData?.latlng?.lng === lng;
|
|
1292
|
+
});
|
|
1293
|
+
while (rangingMarker[index]?.options?.extData?.distance) {
|
|
1294
|
+
rangingMarker[index].remove();
|
|
1295
|
+
rangingMarker.splice(index, 1);
|
|
1296
|
+
index--;
|
|
1297
|
+
}
|
|
1298
|
+
rangingMarker[index].remove();
|
|
1299
|
+
rangingMarker.splice(index, 1);
|
|
1300
|
+
});
|
|
1301
|
+
}
|
|
1302
|
+
}
|
|
1303
|
+
function setRangingTrunEnd() {
|
|
1304
|
+
const lastIndex = rangingMarker.length - 1;
|
|
1305
|
+
const marker = rangingMarker[lastIndex];
|
|
1306
|
+
if (marker) {
|
|
1307
|
+
if (marker.options.extData.distance) {
|
|
1308
|
+
setPointIcon(lastIndex, marker.options.extData.distance, true);
|
|
1309
|
+
} else {
|
|
1310
|
+
marker.remove();
|
|
1311
|
+
rangingMarker.splice(lastIndex, 1);
|
|
1312
|
+
}
|
|
1313
|
+
}
|
|
1314
|
+
rangingPointsEnd.push(rangingPointsIng);
|
|
1315
|
+
rangingPointsIng = [];
|
|
1316
|
+
}
|
|
1317
|
+
const clearRanging = () => {
|
|
1318
|
+
rangingMarker.forEach((marker) => {
|
|
1319
|
+
if (marker?.destroy) {
|
|
1320
|
+
marker.destroy();
|
|
1321
|
+
} else {
|
|
1322
|
+
marker?.remove();
|
|
1323
|
+
}
|
|
1324
|
+
});
|
|
1325
|
+
rangingPolylines.forEach((polygon) => {
|
|
1326
|
+
polygon?.remove();
|
|
1327
|
+
});
|
|
1328
|
+
map.off("click", rangingClick);
|
|
1329
|
+
map.off("contextmenu", setRangingTrunEnd);
|
|
1330
|
+
rangingTrun = false;
|
|
1331
|
+
};
|
|
1332
|
+
const handlers = {
|
|
1333
|
+
turnOn: function() {
|
|
1334
|
+
if (rangingTrun) return;
|
|
1335
|
+
map.on("click", rangingClick);
|
|
1336
|
+
map.on("contextmenu", setRangingTrunEnd);
|
|
1337
|
+
rangingTrun = true;
|
|
1338
|
+
},
|
|
1339
|
+
turnOff: function() {
|
|
1340
|
+
if (!rangingTrun) return;
|
|
1341
|
+
clearRanging();
|
|
1342
|
+
rangingMarker = [];
|
|
1343
|
+
rangingPolylines = [];
|
|
1344
|
+
rangingPointsIng = [];
|
|
1345
|
+
rangingPointsEnd = [];
|
|
1346
|
+
},
|
|
1347
|
+
remove: function() {
|
|
1348
|
+
if (!rangingTrun) return;
|
|
1349
|
+
clearRanging();
|
|
1350
|
+
rangingMarker = null;
|
|
1351
|
+
rangingPolylines = null;
|
|
1352
|
+
rangingPointsIng = null;
|
|
1353
|
+
rangingPointsEnd = null;
|
|
1354
|
+
}
|
|
1355
|
+
};
|
|
1356
|
+
return mapProxy.createMapProxy({}, handlers);
|
|
1357
|
+
}
|
|
1358
|
+
}
|
|
1359
|
+
|
|
1360
|
+
exports.default = Leafletjs;
|