@vtx/map 1.2.29 → 6.0.0-beta.1
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/README.md +44 -44
- package/lib/VtxMap/AMap/AMap.js +359 -355
- package/lib/VtxMap/BMap/Map.js +331 -330
- package/lib/VtxMap/BMap/Map1.js +1712 -0
- package/lib/VtxMap/GMap/Map.js +432 -427
- package/lib/VtxMap/Map.js +31 -27
- package/lib/VtxMap/MapToolFunction.js +6 -7
- package/lib/VtxMap/OMap/Map.js +410 -405
- package/lib/VtxMap/OMap/Map.less +70 -70
- package/lib/VtxMap/OlMap/Map.js +450 -440
- package/lib/VtxMap/OlMap/Map.less +230 -230
- package/lib/VtxMap/TMap/TMap.js +321 -318
- package/lib/VtxMap/index.js +10 -11
- package/lib/VtxMap/mapPlayer.js +15 -16
- package/lib/VtxMap/optimizingPointMap.js +35 -33
- package/lib/VtxMap/style/index.js +1 -2
- package/lib/VtxMap/zoomMap.js +24 -23
- package/lib/VtxModal/VtxModal.js +94 -82
- package/lib/VtxModal/VtxModal.less +83 -52
- package/lib/VtxModal/draggableModal.js +35 -33
- package/lib/VtxModal/index.js +6 -7
- package/lib/VtxModal/style/index.js +1 -15
- package/lib/VtxSearchCheckMap/VtxSearchCheckMap.js +265 -244
- package/lib/VtxSearchCheckMap/VtxSearchCheckMap.less +69 -43
- package/lib/VtxSearchCheckMap/index.js +4 -9
- package/lib/VtxSearchCheckMap/mapping.js +1 -2
- package/lib/VtxSearchCheckMap/style/index.js +5 -11
- package/lib/VtxSearchMap/VtxSearchMap.js +326 -288
- package/lib/VtxSearchMap/VtxSearchMap.less +74 -47
- package/lib/VtxSearchMap/VtxSearchMapAntd3.less +1 -1
- package/lib/VtxSearchMap/index.js +4 -9
- package/lib/VtxSearchMap/mapping.js +1 -2
- package/lib/VtxSearchMap/style/index.js +1 -28
- package/lib/default.js +44 -20
- package/lib/index.js +30 -31
- package/lib/utils/util.js +3 -4
- package/package.json +19 -27
- package/lib/VtxMap/AMap/AMap.css +0 -27
- package/lib/VtxMap/AMap/AMap.js.map +0 -1
- package/lib/VtxMap/BMap/Map.css +0 -26
- package/lib/VtxMap/BMap/Map.js.map +0 -1
- package/lib/VtxMap/GMap/Map.css +0 -88
- package/lib/VtxMap/GMap/Map.js.map +0 -1
- package/lib/VtxMap/Map.css +0 -7
- package/lib/VtxMap/Map.js.map +0 -1
- package/lib/VtxMap/MapToolFunction.js.map +0 -1
- package/lib/VtxMap/OMap/Map.css +0 -76
- package/lib/VtxMap/OMap/Map.js.map +0 -1
- package/lib/VtxMap/OlMap/Map.css +0 -229
- package/lib/VtxMap/OlMap/Map.js.map +0 -1
- package/lib/VtxMap/TMap/TMap.css +0 -31
- package/lib/VtxMap/TMap/TMap.js.map +0 -1
- package/lib/VtxMap/index.js.map +0 -1
- package/lib/VtxMap/mapPlayer.js.map +0 -1
- package/lib/VtxMap/optimizingPointMap.js.map +0 -1
- package/lib/VtxMap/style/css.js +0 -10
- package/lib/VtxMap/style/css.js.map +0 -1
- package/lib/VtxMap/style/index.js.map +0 -1
- package/lib/VtxMap/zoomMap.js.map +0 -1
- package/lib/VtxModal/VtxModal.css +0 -62
- package/lib/VtxModal/VtxModal.js.map +0 -1
- package/lib/VtxModal/VtxModalAntd3.css +0 -62
- package/lib/VtxModal/VtxModalAntd3.less +0 -67
- package/lib/VtxModal/draggableModal.js.map +0 -1
- package/lib/VtxModal/index.js.map +0 -1
- package/lib/VtxModal/style/css.js +0 -15
- package/lib/VtxModal/style/css.js.map +0 -1
- package/lib/VtxModal/style/index.js.map +0 -1
- package/lib/VtxSearchCheckMap/VtxSearchCheckMap.css +0 -182
- package/lib/VtxSearchCheckMap/VtxSearchCheckMap.js.map +0 -1
- package/lib/VtxSearchCheckMap/VtxSearchCheckMapAntd3.css +0 -0
- package/lib/VtxSearchCheckMap/VtxSearchCheckMapAntd3.less +0 -1
- package/lib/VtxSearchCheckMap/index.js.map +0 -1
- package/lib/VtxSearchCheckMap/mapping.js.map +0 -1
- package/lib/VtxSearchCheckMap/style/css.js +0 -28
- package/lib/VtxSearchCheckMap/style/css.js.map +0 -1
- package/lib/VtxSearchCheckMap/style/index.js.map +0 -1
- package/lib/VtxSearchMap/VtxSearchMap.css +0 -202
- package/lib/VtxSearchMap/VtxSearchMap.js.map +0 -1
- package/lib/VtxSearchMap/VtxSearchMapAntd3.css +0 -0
- package/lib/VtxSearchMap/index.js.map +0 -1
- package/lib/VtxSearchMap/mapping.js.map +0 -1
- package/lib/VtxSearchMap/style/css.js +0 -28
- package/lib/VtxSearchMap/style/css.js.map +0 -1
- package/lib/VtxSearchMap/style/index.js.map +0 -1
- package/lib/default.js.map +0 -1
- package/lib/index.js.map +0 -1
- package/lib/utils/util.js.map +0 -1
|
@@ -0,0 +1,1712 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); }
|
|
4
|
+
Object.defineProperty(exports, "__esModule", {
|
|
5
|
+
value: true
|
|
6
|
+
});
|
|
7
|
+
exports.default = void 0;
|
|
8
|
+
var _react = _interopRequireWildcard(require("react"));
|
|
9
|
+
var _client = require("react-dom/client");
|
|
10
|
+
var _MapToolFunction = require("../MapToolFunction");
|
|
11
|
+
var _immutable = _interopRequireDefault(require("immutable"));
|
|
12
|
+
var _unionBy = _interopRequireDefault(require("lodash-es/unionBy"));
|
|
13
|
+
var _default2 = _interopRequireWildcard(require("../../default"));
|
|
14
|
+
var _antd = require("antd");
|
|
15
|
+
var _ahooks = require("ahooks");
|
|
16
|
+
var _useDeepCompare = require("use-deep-compare");
|
|
17
|
+
var _jsxRuntime = require("react/jsx-runtime");
|
|
18
|
+
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
19
|
+
function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache = function _getRequireWildcardCache(e) { return e ? t : r; })(e); }
|
|
20
|
+
function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" != _typeof(e) && "function" != typeof e) return { default: e }; var t = _getRequireWildcardCache(r); if (t && t.has(e)) return t.get(e); var n = { __proto__: null }, a = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var u in e) if ("default" !== u && Object.prototype.hasOwnProperty.call(e, u)) { var i = a ? Object.getOwnPropertyDescriptor(e, u) : null; i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u]; } return n.default = e, t && t.set(e, n), n; }
|
|
21
|
+
function _createForOfIteratorHelper(o, allowArrayLike) { var it = typeof Symbol !== "undefined" && o[Symbol.iterator] || o["@@iterator"]; if (!it) { if (Array.isArray(o) || (it = _unsupportedIterableToArray(o)) || allowArrayLike && o && typeof o.length === "number") { if (it) o = it; var i = 0; var F = function F() {}; return { s: F, n: function n() { if (i >= o.length) return { done: true }; return { done: false, value: o[i++] }; }, e: function e(_e) { throw _e; }, f: F }; } throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); } var normalCompletion = true, didErr = false, err; return { s: function s() { it = it.call(o); }, n: function n() { var step = it.next(); normalCompletion = step.done; return step; }, e: function e(_e2) { didErr = true; err = _e2; }, f: function f() { try { if (!normalCompletion && it.return != null) it.return(); } finally { if (didErr) throw err; } } }; }
|
|
22
|
+
function _toConsumableArray(arr) { return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _unsupportedIterableToArray(arr) || _nonIterableSpread(); }
|
|
23
|
+
function _nonIterableSpread() { throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
|
|
24
|
+
function _iterableToArray(iter) { if (typeof Symbol !== "undefined" && iter[Symbol.iterator] != null || iter["@@iterator"] != null) return Array.from(iter); }
|
|
25
|
+
function _arrayWithoutHoles(arr) { if (Array.isArray(arr)) return _arrayLikeToArray(arr); }
|
|
26
|
+
function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
|
|
27
|
+
function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
|
|
28
|
+
function _defineProperty(obj, key, value) { key = _toPropertyKey(key); if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
|
|
29
|
+
function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : String(i); }
|
|
30
|
+
function _toPrimitive(t, r) { if ("object" != _typeof(t) || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != _typeof(i)) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); }
|
|
31
|
+
function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); }
|
|
32
|
+
function _nonIterableRest() { throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
|
|
33
|
+
function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
|
|
34
|
+
function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i]; return arr2; }
|
|
35
|
+
function _iterableToArrayLimit(r, l) { var t = null == r ? null : "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"]; if (null != t) { var e, n, i, u, a = [], f = !0, o = !1; try { if (i = (t = t.call(r)).next, 0 === l) { if (Object(t) !== t) return; f = !1; } else for (; !(f = (e = i.call(t)).done) && (a.push(e.value), a.length !== l); f = !0); } catch (r) { o = !0, n = r; } finally { try { if (!f && null != t.return && (u = t.return(), Object(u) !== u)) return; } finally { if (o) throw n; } } return a; } }
|
|
36
|
+
function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
|
|
37
|
+
var Set = _immutable.default.Set;
|
|
38
|
+
|
|
39
|
+
// 百度地图js文件内做了一些额外的http or https判断
|
|
40
|
+
if (window.location.protocol === "https:") {
|
|
41
|
+
window.BMAP_PROTOCOL = "https";
|
|
42
|
+
window.BMap_loadScriptTime = new Date().getTime();
|
|
43
|
+
}
|
|
44
|
+
var gisMapConstant = {
|
|
45
|
+
circle: "BMAP_POINT_SHAPE_CIRCLE",
|
|
46
|
+
//圆形
|
|
47
|
+
star: 1,
|
|
48
|
+
//星形
|
|
49
|
+
square: 4,
|
|
50
|
+
//方形
|
|
51
|
+
rhombus: 5,
|
|
52
|
+
//菱形
|
|
53
|
+
waterdrop: 2,
|
|
54
|
+
//水滴状,该类型无size和color属性
|
|
55
|
+
tiny: 1,
|
|
56
|
+
//定义点的尺寸为超小,宽高为2px*2px
|
|
57
|
+
smaller: 2,
|
|
58
|
+
//定义点的尺寸为很小,宽高为4px*4px
|
|
59
|
+
small: 3,
|
|
60
|
+
//定义点的尺寸为小,宽高为8px*8px
|
|
61
|
+
normal: 4,
|
|
62
|
+
//定义点的尺寸为正常,宽高为10px*10px,为海量点默认尺寸
|
|
63
|
+
big: 5,
|
|
64
|
+
//定义点的尺寸为大,宽高为16px*16px
|
|
65
|
+
bigger: 6,
|
|
66
|
+
//定义点的尺寸为很大,宽高为20px*20px
|
|
67
|
+
huge: 7 //定义点的尺寸为超大,宽高为30px*30px
|
|
68
|
+
};
|
|
69
|
+
function BaiduMap(props) {
|
|
70
|
+
var _this = this;
|
|
71
|
+
var mapRef = (0, _react.useRef)(null);
|
|
72
|
+
var gisRef = (0, _react.useRef)(null);
|
|
73
|
+
var prevPropsRef = (0, _react.useRef)({});
|
|
74
|
+
|
|
75
|
+
// 状态管理
|
|
76
|
+
var _useState = (0, _react.useState)({
|
|
77
|
+
mapId: props.mapId,
|
|
78
|
+
pointIds: [],
|
|
79
|
+
//地图上点的ids
|
|
80
|
+
lineIds: [],
|
|
81
|
+
//地图上线的ids
|
|
82
|
+
polygonIds: [],
|
|
83
|
+
//地图上面的ids
|
|
84
|
+
circleIds: [],
|
|
85
|
+
//地图上圆的ids
|
|
86
|
+
editId: "",
|
|
87
|
+
//当前编辑的图元id
|
|
88
|
+
editGraphic: "",
|
|
89
|
+
//当前编辑完后图元所有数据
|
|
90
|
+
boundaryInfo: [],
|
|
91
|
+
//当前画出的边界线的id和区域名
|
|
92
|
+
drawIds: {
|
|
93
|
+
//绘制工具id集合
|
|
94
|
+
point: [],
|
|
95
|
+
polyline: [],
|
|
96
|
+
polygon: [],
|
|
97
|
+
circle: [],
|
|
98
|
+
rectangle: []
|
|
99
|
+
}
|
|
100
|
+
}),
|
|
101
|
+
_useState2 = _slicedToArray(_useState, 2),
|
|
102
|
+
state = _useState2[0],
|
|
103
|
+
setState = _useState2[1];
|
|
104
|
+
|
|
105
|
+
// 引用管理
|
|
106
|
+
var GM = (0, _react.useRef)(new _MapToolFunction.graphicManage()); //初始化 图元管理方法
|
|
107
|
+
|
|
108
|
+
var _boundary = (0, _react.useRef)(null); // 获取行政区域数据的对象
|
|
109
|
+
var _cluster = (0, _react.useRef)(null); // 点聚合对象
|
|
110
|
+
var _rangingTool = (0, _react.useRef)(null); // 测距对象
|
|
111
|
+
var _bmar = (0, _react.useRef)(null); // 区域限制对象
|
|
112
|
+
var _drawmanager = (0, _react.useRef)(null); // 图元绘制对象
|
|
113
|
+
var _trafficCtrl = (0, _react.useRef)(null); // 交通对象
|
|
114
|
+
|
|
115
|
+
var moveToTimer = (0, _react.useRef)(null); //moveTo时间对象
|
|
116
|
+
var heatmap = (0, _react.useRef)(null); //热力图对象
|
|
117
|
+
var morepoints = (0, _react.useRef)([]); //海量点数组
|
|
118
|
+
var movePoints = (0, _react.useRef)([]); //移动点的动画集合
|
|
119
|
+
|
|
120
|
+
var frameSelectProps = (0, _react.useRef)({});
|
|
121
|
+
var mapTypeControl = (0, _react.useRef)(null);
|
|
122
|
+
var scaleControl = (0, _react.useRef)(null);
|
|
123
|
+
var navigationControl = (0, _react.useRef)(null);
|
|
124
|
+
var editGraphicChange = (0, _react.useRef)(null);
|
|
125
|
+
|
|
126
|
+
// 常量
|
|
127
|
+
var AnchorConstant = (0, _react.useMemo)(function () {
|
|
128
|
+
return {
|
|
129
|
+
tl: window.BMAP_ANCHOR_TOP_LEFT,
|
|
130
|
+
tr: window.BMAP_ANCHOR_TOP_RIGHT,
|
|
131
|
+
bl: window.BMAP_ANCHOR_BOTTOM_LEFT,
|
|
132
|
+
br: window.BMAP_ANCHOR_BOTTOM_RIGHT
|
|
133
|
+
};
|
|
134
|
+
}, []);
|
|
135
|
+
var NavigationConstant = (0, _react.useMemo)(function () {
|
|
136
|
+
return {
|
|
137
|
+
small: window.BMAP_NAVIGATION_CONTROL_SMALL,
|
|
138
|
+
pan: window.BMAP_NAVIGATION_CONTROL_PAN,
|
|
139
|
+
zoom: window.BMAP_NAVIGATION_CONTROL_ZOOM,
|
|
140
|
+
full: window.BMAP_NAVIGATION_CONTROL_FULL
|
|
141
|
+
};
|
|
142
|
+
}, []);
|
|
143
|
+
|
|
144
|
+
// 深度比较函数
|
|
145
|
+
var deepEqual = (0, _react.useCallback)(function (a, b) {
|
|
146
|
+
return _immutable.default.is(_immutable.default.fromJS(a), _immutable.default.fromJS(b));
|
|
147
|
+
}, []);
|
|
148
|
+
|
|
149
|
+
// 数据匹配函数
|
|
150
|
+
var dataMatch = (0, _react.useCallback)(function (oldData, newData, type) {
|
|
151
|
+
var onlyOldData = Set(oldData).subtract(Set(newData)).toJS();
|
|
152
|
+
var onlyNewData = Set(newData).subtract(Set(oldData)).toJS();
|
|
153
|
+
var onlyOldIDs = onlyOldData.map(function (item) {
|
|
154
|
+
return item[type];
|
|
155
|
+
});
|
|
156
|
+
var onlyNewIDs = onlyNewData.map(function (item) {
|
|
157
|
+
return item[type];
|
|
158
|
+
});
|
|
159
|
+
var updateDataIDs = Set(onlyOldIDs).intersect(Set(onlyNewIDs)).toJS();
|
|
160
|
+
var updatedData = onlyNewData.filter(function (item) {
|
|
161
|
+
return updateDataIDs.indexOf(item[type]) > -1;
|
|
162
|
+
});
|
|
163
|
+
var replacedData = onlyOldData.filter(function (item) {
|
|
164
|
+
return updateDataIDs.indexOf(item[type]) > -1;
|
|
165
|
+
});
|
|
166
|
+
var deletedDataIDs = onlyOldIDs.filter(function (oldID) {
|
|
167
|
+
return updateDataIDs.indexOf(oldID) == -1;
|
|
168
|
+
});
|
|
169
|
+
var addedData = onlyNewData.filter(function (item) {
|
|
170
|
+
return updateDataIDs.indexOf(item[type]) == -1;
|
|
171
|
+
});
|
|
172
|
+
return {
|
|
173
|
+
deletedDataIDs: deletedDataIDs,
|
|
174
|
+
addedData: addedData,
|
|
175
|
+
updatedData: updatedData,
|
|
176
|
+
replacedData: replacedData
|
|
177
|
+
};
|
|
178
|
+
}, []);
|
|
179
|
+
|
|
180
|
+
// 处理需要增加图元的数据
|
|
181
|
+
var dealAdd = (0, _react.useCallback)(function (ary, ids) {
|
|
182
|
+
var ads = [],
|
|
183
|
+
otherupds = [];
|
|
184
|
+
for (var i = 0; i < ary.length; i++) {
|
|
185
|
+
if (ids.indexOf(ary[i].id) > -1) {
|
|
186
|
+
otherupds.push(ary[i]);
|
|
187
|
+
} else {
|
|
188
|
+
ads.push(ary[i]);
|
|
189
|
+
}
|
|
190
|
+
}
|
|
191
|
+
return {
|
|
192
|
+
ads: ads,
|
|
193
|
+
otherupds: otherupds
|
|
194
|
+
};
|
|
195
|
+
}, []);
|
|
196
|
+
|
|
197
|
+
// 处理需要更新图元的数据
|
|
198
|
+
var dealUpdate = (0, _react.useCallback)(function (ary, ids) {
|
|
199
|
+
var upds = [],
|
|
200
|
+
otherads = [];
|
|
201
|
+
for (var i = 0; i < ary.length; i++) {
|
|
202
|
+
if (ids.indexOf(ary[i].id) > -1) {
|
|
203
|
+
upds.push(ary[i]);
|
|
204
|
+
} else {
|
|
205
|
+
otherads.push(ary[i]);
|
|
206
|
+
}
|
|
207
|
+
}
|
|
208
|
+
return {
|
|
209
|
+
upds: upds,
|
|
210
|
+
otherads: otherads
|
|
211
|
+
};
|
|
212
|
+
}, []);
|
|
213
|
+
var ensurejQuery = (0, _react.useCallback)(function () {
|
|
214
|
+
return new Promise(function (resolve) {
|
|
215
|
+
if (window.$) {
|
|
216
|
+
resolve();
|
|
217
|
+
} else {
|
|
218
|
+
(0, _default2.loadScript)("//cdn.bootcss.com/jquery/3.3.1/jquery.min.js", resolve);
|
|
219
|
+
}
|
|
220
|
+
});
|
|
221
|
+
}, []);
|
|
222
|
+
// 加载插件
|
|
223
|
+
var loadPlugin = (0, _react.useCallback)(function () {
|
|
224
|
+
return new Promise(function (resolve) {
|
|
225
|
+
// 加载所需插件
|
|
226
|
+
Promise.all([new Promise(function (resolve) {
|
|
227
|
+
if (window.BMapLib && window.BMapLib.DistanceTool) {
|
|
228
|
+
resolve();
|
|
229
|
+
} else {
|
|
230
|
+
(0, _default2.loadScript)("".concat(_default2.default.mapServerURL, "/DistanceTool_min.js"), resolve);
|
|
231
|
+
}
|
|
232
|
+
}), new Promise(function (resolve) {
|
|
233
|
+
if (window.BMapLib && window.BMapLib.TrafficControl) {
|
|
234
|
+
resolve();
|
|
235
|
+
} else {
|
|
236
|
+
(0, _default2.loadScript)("".concat(_default2.default.mapServerURL, "/TrafficControl_min.js"), function () {
|
|
237
|
+
$("<link>").attr({
|
|
238
|
+
rel: "stylesheet",
|
|
239
|
+
type: "text/css",
|
|
240
|
+
href: "//api.map.baidu.com/library/TrafficControl/1.4/src/TrafficControl_min.css"
|
|
241
|
+
}).appendTo("head");
|
|
242
|
+
resolve();
|
|
243
|
+
});
|
|
244
|
+
}
|
|
245
|
+
}), new Promise(function (resolve) {
|
|
246
|
+
if (window.BMapLib && window.BMapLib.MarkerClusterer) {
|
|
247
|
+
resolve();
|
|
248
|
+
} else {
|
|
249
|
+
(0, _default2.loadScript)("".concat(_default2.default.mapServerURL, "/MarkerClusterer_min.js"), resolve);
|
|
250
|
+
}
|
|
251
|
+
}), new Promise(function (resolve) {
|
|
252
|
+
if (window.BMapLib && window.BMapLib.AreaRestriction) {
|
|
253
|
+
resolve();
|
|
254
|
+
} else {
|
|
255
|
+
(0, _default2.loadScript)("".concat(_default2.default.mapServerURL, "/AreaRestriction_min.js"), resolve);
|
|
256
|
+
}
|
|
257
|
+
}), new Promise(function (resolve) {
|
|
258
|
+
if (window.BMapLib && window.BMapLib.DrawingManager) {
|
|
259
|
+
resolve();
|
|
260
|
+
} else {
|
|
261
|
+
(0, _default2.loadScript)("".concat(_default2.default.mapServerURL, "/DrawingManager_min.js"), function () {
|
|
262
|
+
$("<link>").attr({
|
|
263
|
+
rel: "stylesheet",
|
|
264
|
+
type: "text/css",
|
|
265
|
+
href: "//api.map.baidu.com/library/DrawingManager/1.4/src/DrawingManager_min.css"
|
|
266
|
+
}).appendTo("head");
|
|
267
|
+
resolve();
|
|
268
|
+
});
|
|
269
|
+
}
|
|
270
|
+
}), new Promise(function (resolve) {
|
|
271
|
+
if (window.BMapLib && window.BMapLib.HeatmapOverlay) {
|
|
272
|
+
resolve();
|
|
273
|
+
} else {
|
|
274
|
+
(0, _default2.loadScript)("".concat(_default2.default.mapServerURL, "/Heatmap_min.js"), resolve);
|
|
275
|
+
}
|
|
276
|
+
}), new Promise(function (resolve) {
|
|
277
|
+
if (window.BMapLib && window.BMapLib.GeoUtils) {
|
|
278
|
+
resolve();
|
|
279
|
+
} else {
|
|
280
|
+
(0, _default2.loadScript)("".concat(_default2.default.mapServerURL, "/GeoUtils_min.js"), resolve);
|
|
281
|
+
}
|
|
282
|
+
}), new Promise(function (resolve) {
|
|
283
|
+
if (window.BMapLib && window.BMapLib.TextIconOverlay) {
|
|
284
|
+
resolve();
|
|
285
|
+
} else {
|
|
286
|
+
(0, _default2.loadScript)("".concat(_default2.default.mapServerURL, "/TextIconOverlay_min.js"), resolve);
|
|
287
|
+
}
|
|
288
|
+
}), new Promise(function (resolve) {
|
|
289
|
+
if (window.BMapLib && window.BMapLib.InfoBox) {
|
|
290
|
+
resolve();
|
|
291
|
+
} else {
|
|
292
|
+
(0, _default2.loadScript)("".concat(_default2.default.mapServerURL, "/InfoBox_min.js"), resolve);
|
|
293
|
+
}
|
|
294
|
+
})]).then(function () {
|
|
295
|
+
resolve();
|
|
296
|
+
});
|
|
297
|
+
});
|
|
298
|
+
}, []);
|
|
299
|
+
|
|
300
|
+
// 加载地图JS
|
|
301
|
+
var loadMapJs = (0, _react.useCallback)(function () {
|
|
302
|
+
return new Promise(function (resolve, reject) {
|
|
303
|
+
// 确保 jQuery 可用后再加载地图
|
|
304
|
+
ensurejQuery().then(function () {
|
|
305
|
+
if (window.BMap) {
|
|
306
|
+
resolve(loadPlugin());
|
|
307
|
+
} else {
|
|
308
|
+
(0, _default2.loadScript)(_default2.default.bmapScriptUrl, function () {
|
|
309
|
+
resolve(loadPlugin());
|
|
310
|
+
});
|
|
311
|
+
}
|
|
312
|
+
}).catch(function (error) {
|
|
313
|
+
console.error("Error ensuring jQuery:", error);
|
|
314
|
+
reject(error);
|
|
315
|
+
});
|
|
316
|
+
});
|
|
317
|
+
}, [ensurejQuery, loadPlugin]);
|
|
318
|
+
|
|
319
|
+
// 创建地图
|
|
320
|
+
var createMap = (0, _useDeepCompare.useDeepCompareCallback)(function () {
|
|
321
|
+
var mapCenter = props.mapCenter,
|
|
322
|
+
mapStyle = props.mapStyle,
|
|
323
|
+
mapId = props.mapId,
|
|
324
|
+
mapZoomLevel = props.mapZoomLevel,
|
|
325
|
+
minZoom = props.minZoom,
|
|
326
|
+
maxZoom = props.maxZoom;
|
|
327
|
+
var options = {
|
|
328
|
+
zoom: mapZoomLevel || 10,
|
|
329
|
+
center: mapCenter || [116.404, 39.915],
|
|
330
|
+
minZoom: minZoom,
|
|
331
|
+
maxZoom: maxZoom
|
|
332
|
+
};
|
|
333
|
+
if (window.VtxMap) {
|
|
334
|
+
window.VtxMap[mapId] = null;
|
|
335
|
+
} else {
|
|
336
|
+
window.VtxMap = {};
|
|
337
|
+
}
|
|
338
|
+
setTimeout(function () {
|
|
339
|
+
$("#myCanvasElement").parent().children("svg").css({
|
|
340
|
+
"z-index": 1
|
|
341
|
+
});
|
|
342
|
+
}, 500);
|
|
343
|
+
var map = window.VtxMap[mapId] = gis.current = new BMap.Map(mapRef.current);
|
|
344
|
+
var center = mapCenter && mapCenter.length === 2 ? new BMap.Point(parseFloat(mapCenter[0]), parseFloat(mapCenter[1])) : new BMap.Point(options.center);
|
|
345
|
+
// 初始化地图,设置中心点坐标和地图级别
|
|
346
|
+
map.centerAndZoom(center, mapZoomLevel || options.zoom);
|
|
347
|
+
// 开启鼠标滚轮缩放
|
|
348
|
+
map.enableScrollWheelZoom(true);
|
|
349
|
+
|
|
350
|
+
//添加地图类型控件
|
|
351
|
+
if (props.satelliteSwitch) {
|
|
352
|
+
showMapTypeControl();
|
|
353
|
+
}
|
|
354
|
+
//初始化路况控件
|
|
355
|
+
if (!_trafficCtrl.current) {
|
|
356
|
+
_trafficCtrl.current = new BMapLib.TrafficControl({
|
|
357
|
+
// 是否显示路况提示面板
|
|
358
|
+
showPanel: false
|
|
359
|
+
});
|
|
360
|
+
gis.current.addControl(t._trafficCtrl);
|
|
361
|
+
if (document.getElementById("tcBtn").remove) {
|
|
362
|
+
document.getElementById("tcBtn").remove();
|
|
363
|
+
} else {
|
|
364
|
+
document.getElementById("tcBtn").removeNode();
|
|
365
|
+
}
|
|
366
|
+
}
|
|
367
|
+
|
|
368
|
+
// 初始化获取行政区域数据的对象
|
|
369
|
+
if (!_boundary.current) {
|
|
370
|
+
_boundary.current = new BMap.Boundary();
|
|
371
|
+
}
|
|
372
|
+
// 初始化点聚合对象
|
|
373
|
+
if (!_cluster.current) {
|
|
374
|
+
_cluster.current = new BMapLib.MarkerClusterer(map, {
|
|
375
|
+
maxZoom: 17
|
|
376
|
+
});
|
|
377
|
+
}
|
|
378
|
+
// 初始化测距对象
|
|
379
|
+
if (!_rangingTool.current) {
|
|
380
|
+
_rangingTool.current = new BMapLib.DistanceTool(map);
|
|
381
|
+
}
|
|
382
|
+
// 初始化区域限制对象
|
|
383
|
+
if (!_bmar.current) {
|
|
384
|
+
_bmar.current = new BMapLib.AreaRestriction();
|
|
385
|
+
}
|
|
386
|
+
// 初始化图元绘制对象
|
|
387
|
+
if (!_drawmanager.current) {
|
|
388
|
+
_drawmanager.current = new BMapLib.DrawingManager(map);
|
|
389
|
+
_drawmanager.addEventListener("overlaycomplete", function (e) {
|
|
390
|
+
var _frameSelectProps$cur;
|
|
391
|
+
if (e.label) {
|
|
392
|
+
gis.current.removeOverlay(e.label);
|
|
393
|
+
}
|
|
394
|
+
var drawExtData = e.extData;
|
|
395
|
+
//保存绘制图元的id便于后期比对
|
|
396
|
+
state.drawIds[drawExtData.type].push(drawExtData.id);
|
|
397
|
+
var backobj = {
|
|
398
|
+
id: drawExtData.id,
|
|
399
|
+
attributes: drawExtData.attributes,
|
|
400
|
+
geometryType: drawExtData.type == "rectangle" ? "polygon" : drawExtData.type,
|
|
401
|
+
mapLayer: e.overlay,
|
|
402
|
+
geometry: {
|
|
403
|
+
type: drawExtData.type == "rectangle" ? "polygon" : drawExtData.type
|
|
404
|
+
}
|
|
405
|
+
};
|
|
406
|
+
//点击事件
|
|
407
|
+
e.overlay.addEventListener("click", function (e) {
|
|
408
|
+
clickGraphic(drawExtData.id, e);
|
|
409
|
+
});
|
|
410
|
+
//鼠标移入事件
|
|
411
|
+
e.overlay.addEventListener("mouseover", function (e) {
|
|
412
|
+
mouseOverGraphic(drawExtData.id, e);
|
|
413
|
+
});
|
|
414
|
+
//鼠标移出事件
|
|
415
|
+
e.overlay.addEventListener("mouseout", function (e) {
|
|
416
|
+
mouseOutGraphic(drawExtData.id, e);
|
|
417
|
+
});
|
|
418
|
+
//缓存绘制的图元信息
|
|
419
|
+
t.GM.setGraphic(drawExtData.id, e.overlay);
|
|
420
|
+
|
|
421
|
+
//区别点和圆的经纬度数据处理
|
|
422
|
+
var _t$dealData = t.dealData(e.overlay),
|
|
423
|
+
lnglatAry = _t$dealData.lnglatAry,
|
|
424
|
+
_extent = _t$dealData._extent,
|
|
425
|
+
path = _t$dealData.path;
|
|
426
|
+
//处理返回数据
|
|
427
|
+
switch (drawExtData.type) {
|
|
428
|
+
case "point":
|
|
429
|
+
backobj.geometry.x = e.overlay.getPosition().lng;
|
|
430
|
+
backobj.geometry.y = e.overlay.getPosition().lat;
|
|
431
|
+
break;
|
|
432
|
+
case "polyline":
|
|
433
|
+
backobj.distance = e.calculate;
|
|
434
|
+
backobj.lnglatAry = lnglatAry;
|
|
435
|
+
backobj.geometry.paths = path;
|
|
436
|
+
backobj.geometry._extent = _extent;
|
|
437
|
+
break;
|
|
438
|
+
case "polygon":
|
|
439
|
+
backobj.area = e.calculate;
|
|
440
|
+
backobj.lnglatAry = lnglatAry;
|
|
441
|
+
backobj.geometry.rings = path;
|
|
442
|
+
backobj.geometry._extent = _extent;
|
|
443
|
+
break;
|
|
444
|
+
case "rectangle":
|
|
445
|
+
backobj.area = e.calculate;
|
|
446
|
+
backobj.lnglatAry = lnglatAry;
|
|
447
|
+
backobj.geometry.rings = path;
|
|
448
|
+
backobj.geometry._extent = _extent;
|
|
449
|
+
break;
|
|
450
|
+
case "circle":
|
|
451
|
+
backobj.geometry.x = e.overlay.getCenter().lng;
|
|
452
|
+
backobj.geometry.y = e.overlay.getCenter().lat;
|
|
453
|
+
backobj.geometry.radius = e.overlay.getRadius();
|
|
454
|
+
backobj.area = e.calculate;
|
|
455
|
+
break;
|
|
456
|
+
}
|
|
457
|
+
t.GM.setGraphicParam(drawExtData.id, backobj);
|
|
458
|
+
_drawmanager.close();
|
|
459
|
+
if ("drawEnd" in props) {
|
|
460
|
+
props.drawEnd(backobj);
|
|
461
|
+
}
|
|
462
|
+
if (((_frameSelectProps$cur = frameSelectProps.current[backobj.id]) === null || _frameSelectProps$cur === void 0 ? void 0 : _frameSelectProps$cur.callback) instanceof Function) {
|
|
463
|
+
frameSelectProps.current[backobj.id].callback(backobj);
|
|
464
|
+
}
|
|
465
|
+
});
|
|
466
|
+
}
|
|
467
|
+
|
|
468
|
+
// 初始化路况控件
|
|
469
|
+
if (!trafficCtrl.current) {
|
|
470
|
+
trafficCtrl.current = new BMapLib.TrafficControl({
|
|
471
|
+
showPanel: false
|
|
472
|
+
});
|
|
473
|
+
map.addControl(trafficCtrl.current);
|
|
474
|
+
}
|
|
475
|
+
return map;
|
|
476
|
+
}, [props]);
|
|
477
|
+
|
|
478
|
+
// 获取图形
|
|
479
|
+
var getGraphic = (0, _react.useCallback)(function (id) {
|
|
480
|
+
if (GM.current.getGraphic(id)) {
|
|
481
|
+
var param = GM.current.getGraphicParam(id);
|
|
482
|
+
var attributes = param.attributes;
|
|
483
|
+
return _objectSpread(_objectSpread({}, attributes), {}, {
|
|
484
|
+
geometry: param.geometry
|
|
485
|
+
});
|
|
486
|
+
} else {
|
|
487
|
+
return false;
|
|
488
|
+
}
|
|
489
|
+
}, []);
|
|
490
|
+
|
|
491
|
+
// 删除图形
|
|
492
|
+
var removeGraphic = (0, _react.useCallback)(function (id) {
|
|
493
|
+
var type = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : "point";
|
|
494
|
+
var gc = GM.current.getGraphic(id);
|
|
495
|
+
if (gc) {
|
|
496
|
+
var _gisRef$current;
|
|
497
|
+
(_gisRef$current = gisRef.current) === null || _gisRef$current === void 0 || _gisRef$current.removeOverlay(gc);
|
|
498
|
+
GM.current.removeGraphic(id);
|
|
499
|
+
}
|
|
500
|
+
if (id == state.editId) {
|
|
501
|
+
setState(function (prev) {
|
|
502
|
+
return _objectSpread(_objectSpread({}, prev), {}, {
|
|
503
|
+
editId: ""
|
|
504
|
+
});
|
|
505
|
+
});
|
|
506
|
+
}
|
|
507
|
+
setState(function (prev) {
|
|
508
|
+
var newIds = _toConsumableArray(prev["".concat(type, "Ids")]);
|
|
509
|
+
if (newIds.indexOf(id) != -1) {
|
|
510
|
+
newIds.splice(newIds.indexOf(id), 1);
|
|
511
|
+
}
|
|
512
|
+
return _objectSpread(_objectSpread({}, prev), {}, _defineProperty({}, "".concat(type, "Ids"), newIds));
|
|
513
|
+
});
|
|
514
|
+
}, [state.editId]);
|
|
515
|
+
|
|
516
|
+
// 添加点
|
|
517
|
+
var addPoint = (0, _react.useCallback)(function (mapPoints) {
|
|
518
|
+
var psids = _toConsumableArray(state.pointIds);
|
|
519
|
+
mapPoints.map(function (item, index) {
|
|
520
|
+
var _gisRef$current2;
|
|
521
|
+
if (GM.current.isRepetition(item.id)) {
|
|
522
|
+
console.warn("\u52A0\u70B9id: ".concat(item.id, " \u91CD\u590D"));
|
|
523
|
+
return false;
|
|
524
|
+
}
|
|
525
|
+
if (!item.longitude || !item.latitude) {
|
|
526
|
+
console.warn("\u70B9 \u7ECF\u7EAC\u5EA6 \u6570\u636E\u9519\u8BEF");
|
|
527
|
+
return false;
|
|
528
|
+
}
|
|
529
|
+
var cg = {
|
|
530
|
+
width: 30,
|
|
531
|
+
height: 30,
|
|
532
|
+
labelContent: "",
|
|
533
|
+
labelPixelX: 0,
|
|
534
|
+
labelPixelY: 34,
|
|
535
|
+
BAnimationType: 3,
|
|
536
|
+
markerContentX: -15,
|
|
537
|
+
markerContentY: -30,
|
|
538
|
+
deg: 0
|
|
539
|
+
};
|
|
540
|
+
if (item.markerContent) {
|
|
541
|
+
cg = _objectSpread(_objectSpread({}, cg), {}, {
|
|
542
|
+
markerContentX: 0,
|
|
543
|
+
markerContentY: 0,
|
|
544
|
+
width: 100,
|
|
545
|
+
height: 30
|
|
546
|
+
});
|
|
547
|
+
}
|
|
548
|
+
if (item.config) {
|
|
549
|
+
cg = _objectSpread(_objectSpread({}, cg), item.config);
|
|
550
|
+
}
|
|
551
|
+
var position = new BMap.Point(item.longitude, item.latitude);
|
|
552
|
+
var marker = null;
|
|
553
|
+
if (item.markerContent) {
|
|
554
|
+
var markerOption = {
|
|
555
|
+
offset: new BMap.Size(cg.markerContentX + cg.width / 2, cg.markerContentY + cg.height / 2),
|
|
556
|
+
icon: null
|
|
557
|
+
};
|
|
558
|
+
var icon = new BMap.Icon("".concat(_default2.default.mapServerURL, "/images/touming.png"), new BMap.Size(cg.width, cg.height));
|
|
559
|
+
icon.setImageSize(new BMap.Size(cg.width, cg.height));
|
|
560
|
+
markerOption = _objectSpread(_objectSpread({}, markerOption), {}, {
|
|
561
|
+
icon: icon
|
|
562
|
+
});
|
|
563
|
+
marker = new BMap.Marker(position, markerOption);
|
|
564
|
+
var markerLOption = {
|
|
565
|
+
offset: new BMap.Size(0, 0)
|
|
566
|
+
};
|
|
567
|
+
var markerL = new BMap.Label(item.markerContent, markerLOption);
|
|
568
|
+
markerL.setStyle({
|
|
569
|
+
backgroundColor: "",
|
|
570
|
+
border: "0"
|
|
571
|
+
});
|
|
572
|
+
marker.setLabel(markerL);
|
|
573
|
+
} else {
|
|
574
|
+
var _markerOption = {
|
|
575
|
+
offset: new BMap.Size(cg.markerContentX + cg.width / 2, cg.markerContentY + cg.height / 2),
|
|
576
|
+
icon: null
|
|
577
|
+
};
|
|
578
|
+
var _icon = new BMap.Icon(item.url || "".concat(_default2.default.mapServerURL, "/images/defaultMarker.png"), new BMap.Size(cg.width, cg.height));
|
|
579
|
+
_icon.setImageSize(new BMap.Size(cg.width, cg.height));
|
|
580
|
+
_markerOption = _objectSpread(_objectSpread({}, _markerOption), {}, {
|
|
581
|
+
icon: _icon
|
|
582
|
+
});
|
|
583
|
+
marker = new BMap.Marker(position, _markerOption);
|
|
584
|
+
marker.setRotation(cg.deg);
|
|
585
|
+
if (item.canShowLabel && cg.labelContent) {
|
|
586
|
+
var labelClass = "label-content";
|
|
587
|
+
if (item.labelClass) {
|
|
588
|
+
labelClass = item.labelClass.split(",").join(" ");
|
|
589
|
+
}
|
|
590
|
+
var markerLabel = new BMap.Label("<div class='" + labelClass + '\' style="margin-left: 0;">' + cg.labelContent + "</div>", {
|
|
591
|
+
offset: new BMap.Size(cg.labelPixelX, cg.labelPixelY)
|
|
592
|
+
});
|
|
593
|
+
markerLabel.setStyle({
|
|
594
|
+
border: "0",
|
|
595
|
+
backgroundColor: ""
|
|
596
|
+
});
|
|
597
|
+
marker.setLabel(markerLabel);
|
|
598
|
+
}
|
|
599
|
+
}
|
|
600
|
+
if (cg.zIndex || cg.zIndex === 0) {
|
|
601
|
+
marker.setZIndex(cg.zIndex);
|
|
602
|
+
}
|
|
603
|
+
(_gisRef$current2 = gisRef.current) === null || _gisRef$current2 === void 0 || _gisRef$current2.addOverlay(marker);
|
|
604
|
+
if (!item.markerContent && cg.BAnimationType == 0) {
|
|
605
|
+
marker.setAnimation(BMAP_ANIMATION_BOUNCE);
|
|
606
|
+
} else if (!item.markerContent && cg.BAnimationType == 1) {
|
|
607
|
+
marker.setAnimation(BMAP_ANIMATION_DROP);
|
|
608
|
+
}
|
|
609
|
+
marker.addEventListener("click", function (e) {
|
|
610
|
+
clickGraphic(item.id, e);
|
|
611
|
+
});
|
|
612
|
+
marker.addEventListener("mouseover", function (e) {
|
|
613
|
+
mouseOverGraphic(item.id, e);
|
|
614
|
+
});
|
|
615
|
+
marker.addEventListener("mouseout", function (e) {
|
|
616
|
+
mouseOutGraphic(item.id, e);
|
|
617
|
+
});
|
|
618
|
+
GM.current.setGraphic(item.id, marker);
|
|
619
|
+
psids.push(item.id);
|
|
620
|
+
GM.current.setGraphicParam(item.id, {
|
|
621
|
+
attributes: _objectSpread(_objectSpread({}, item), {}, {
|
|
622
|
+
other: item
|
|
623
|
+
}),
|
|
624
|
+
geometryType: "point",
|
|
625
|
+
geometry: {
|
|
626
|
+
type: "point",
|
|
627
|
+
x: item.longitude,
|
|
628
|
+
y: item.latitude
|
|
629
|
+
}
|
|
630
|
+
});
|
|
631
|
+
});
|
|
632
|
+
setState(function (prev) {
|
|
633
|
+
return _objectSpread(_objectSpread({}, prev), {}, {
|
|
634
|
+
pointIds: psids
|
|
635
|
+
});
|
|
636
|
+
});
|
|
637
|
+
}, [state.pointIds]);
|
|
638
|
+
|
|
639
|
+
// 添加线
|
|
640
|
+
var addLine = (0, _react.useCallback)(function (mapLines, type) {
|
|
641
|
+
var lsids = _toConsumableArray(state.lineIds);
|
|
642
|
+
mapLines.map(function (item, index) {
|
|
643
|
+
var _gisRef$current3;
|
|
644
|
+
if (GM.current.isRepetition(item.id)) {
|
|
645
|
+
console.warn("\u591A\u6298\u7EBFid: ".concat(item.id, " \u91CD\u590D"));
|
|
646
|
+
return false;
|
|
647
|
+
}
|
|
648
|
+
if (!(item.paths && item.paths.length >= 2)) {
|
|
649
|
+
console.warn("\u591A\u6298\u7EBFpaths\u6570\u636E\u9519\u8BEF");
|
|
650
|
+
return false;
|
|
651
|
+
}
|
|
652
|
+
var cg = {
|
|
653
|
+
color: "#277ffa",
|
|
654
|
+
pellucidity: 0.9,
|
|
655
|
+
lineWidth: 5,
|
|
656
|
+
lineType: "solid",
|
|
657
|
+
isHidden: false
|
|
658
|
+
};
|
|
659
|
+
if (item.config) {
|
|
660
|
+
cg = _objectSpread(_objectSpread({}, cg), item.config);
|
|
661
|
+
}
|
|
662
|
+
var linePath = item.paths.map(function (item, index) {
|
|
663
|
+
return new BMap.Point(item[0], item[1]);
|
|
664
|
+
});
|
|
665
|
+
var polyline = new BMap.Polyline(linePath, {
|
|
666
|
+
strokeColor: cg.color,
|
|
667
|
+
strokeOpacity: cg.pellucidity,
|
|
668
|
+
strokeWeight: cg.lineWidth,
|
|
669
|
+
strokeStyle: cg.lineType
|
|
670
|
+
});
|
|
671
|
+
if (cg.isHidden) {
|
|
672
|
+
polyline.hide();
|
|
673
|
+
} else {
|
|
674
|
+
polyline.show();
|
|
675
|
+
}
|
|
676
|
+
(_gisRef$current3 = gisRef.current) === null || _gisRef$current3 === void 0 || _gisRef$current3.addOverlay(polyline);
|
|
677
|
+
polyline.addEventListener("click", function (e) {
|
|
678
|
+
clickGraphic(item.id, e);
|
|
679
|
+
});
|
|
680
|
+
polyline.addEventListener("mouseover", function (e) {
|
|
681
|
+
mouseOverGraphic(item.id, e);
|
|
682
|
+
});
|
|
683
|
+
polyline.addEventListener("mouseout", function (e) {
|
|
684
|
+
mouseOutGraphic(item.id, e);
|
|
685
|
+
});
|
|
686
|
+
GM.current.setGraphic(item.id, polyline);
|
|
687
|
+
lsids.push(item.id);
|
|
688
|
+
GM.current.setGraphicParam(item.id, {
|
|
689
|
+
attributes: _objectSpread(_objectSpread({}, item), {}, {
|
|
690
|
+
paths: item.paths,
|
|
691
|
+
other: item
|
|
692
|
+
}),
|
|
693
|
+
geometryType: "polyline",
|
|
694
|
+
geometry: {
|
|
695
|
+
type: "polyline",
|
|
696
|
+
paths: item.paths
|
|
697
|
+
}
|
|
698
|
+
});
|
|
699
|
+
});
|
|
700
|
+
if (type !== "defined") {
|
|
701
|
+
setState(function (prev) {
|
|
702
|
+
return _objectSpread(_objectSpread({}, prev), {}, {
|
|
703
|
+
lineIds: lsids
|
|
704
|
+
});
|
|
705
|
+
});
|
|
706
|
+
}
|
|
707
|
+
}, [state.lineIds]);
|
|
708
|
+
|
|
709
|
+
// 添加面
|
|
710
|
+
var addPolygon = (0, _react.useCallback)(function (mapPolygons) {
|
|
711
|
+
var pgsids = _toConsumableArray(state.polygonIds);
|
|
712
|
+
mapPolygons.map(function (item, index) {
|
|
713
|
+
var _gisRef$current4;
|
|
714
|
+
if (GM.current.isRepetition(item.id)) {
|
|
715
|
+
console.warn("\u591A\u8FB9\u5F62id: ".concat(item.id, " \u91CD\u590D"));
|
|
716
|
+
return false;
|
|
717
|
+
}
|
|
718
|
+
if (!(item.rings && item.rings.length >= 3)) {
|
|
719
|
+
console.warn("\u591A\u8FB9\u5F62rings\u6570\u636E\u9519\u8BEF");
|
|
720
|
+
return false;
|
|
721
|
+
}
|
|
722
|
+
var cg = {
|
|
723
|
+
lineType: "solid",
|
|
724
|
+
lineWidth: 5,
|
|
725
|
+
lineColor: "#277ffa",
|
|
726
|
+
lineOpacity: 1,
|
|
727
|
+
color: "#fff",
|
|
728
|
+
pellucidity: 0.5
|
|
729
|
+
};
|
|
730
|
+
if (item.config) {
|
|
731
|
+
cg = _objectSpread(_objectSpread({}, cg), item.config);
|
|
732
|
+
}
|
|
733
|
+
var polygonPath = item.rings.map(function (item, index) {
|
|
734
|
+
return new BMap.Point(item[0], item[1]);
|
|
735
|
+
});
|
|
736
|
+
var polygon = new BMap.Polygon(polygonPath, {
|
|
737
|
+
strokeColor: cg.lineColor,
|
|
738
|
+
strokeOpacity: cg.lineOpacity,
|
|
739
|
+
strokeWeight: cg.lineWidth,
|
|
740
|
+
strokeStyle: cg.lineType,
|
|
741
|
+
fillColor: cg.color,
|
|
742
|
+
fillOpacity: cg.pellucidity
|
|
743
|
+
});
|
|
744
|
+
(_gisRef$current4 = gisRef.current) === null || _gisRef$current4 === void 0 || _gisRef$current4.addOverlay(polygon);
|
|
745
|
+
polygon.addEventListener("click", function (e) {
|
|
746
|
+
clickGraphic(item.id, e);
|
|
747
|
+
});
|
|
748
|
+
polygon.addEventListener("mouseover", function (e) {
|
|
749
|
+
mouseOverGraphic(item.id, e);
|
|
750
|
+
});
|
|
751
|
+
polygon.addEventListener("mouseout", function (e) {
|
|
752
|
+
mouseOutGraphic(item.id, e);
|
|
753
|
+
});
|
|
754
|
+
GM.current.setGraphic(item.id, polygon);
|
|
755
|
+
pgsids.push(item.id);
|
|
756
|
+
GM.current.setGraphicParam(item.id, {
|
|
757
|
+
attributes: _objectSpread(_objectSpread({}, item), {}, {
|
|
758
|
+
rings: item.rings,
|
|
759
|
+
other: item
|
|
760
|
+
}),
|
|
761
|
+
geometryType: "polygon",
|
|
762
|
+
geometry: {
|
|
763
|
+
type: "polygon",
|
|
764
|
+
rings: item.rings
|
|
765
|
+
}
|
|
766
|
+
});
|
|
767
|
+
});
|
|
768
|
+
setState(function (prev) {
|
|
769
|
+
return _objectSpread(_objectSpread({}, prev), {}, {
|
|
770
|
+
polygonIds: pgsids
|
|
771
|
+
});
|
|
772
|
+
});
|
|
773
|
+
}, [state.polygonIds]);
|
|
774
|
+
|
|
775
|
+
// 添加圆
|
|
776
|
+
var addCircle = (0, _react.useCallback)(function (mapCircles) {
|
|
777
|
+
var ccsids = _toConsumableArray(state.circleIds);
|
|
778
|
+
mapCircles.map(function (item, index) {
|
|
779
|
+
var _gisRef$current5;
|
|
780
|
+
if (GM.current.isRepetition(item.id)) {
|
|
781
|
+
console.warn("\u5706id: ".concat(item.id, " \u91CD\u590D"));
|
|
782
|
+
return false;
|
|
783
|
+
}
|
|
784
|
+
if (!item.longitude || !item.latitude) {
|
|
785
|
+
console.warn("\u5706 \u7ECF\u7EAC\u5EA6 \u6570\u636E\u9519\u8BEF");
|
|
786
|
+
return false;
|
|
787
|
+
}
|
|
788
|
+
var cg = {
|
|
789
|
+
lineType: "solid",
|
|
790
|
+
lineWidth: 5,
|
|
791
|
+
lineColor: "#277ffa",
|
|
792
|
+
lineOpacity: 1,
|
|
793
|
+
color: "#fff",
|
|
794
|
+
pellucidity: 0.5
|
|
795
|
+
};
|
|
796
|
+
if (item.config) {
|
|
797
|
+
cg = _objectSpread(_objectSpread({}, cg), item.config);
|
|
798
|
+
}
|
|
799
|
+
var centerPoint = new BMap.Point(item.longitude, item.latitude);
|
|
800
|
+
var circle = new BMap.Circle(centerPoint, item.radius, {
|
|
801
|
+
strokeColor: cg.lineColor,
|
|
802
|
+
strokeOpacity: cg.lineOpacity,
|
|
803
|
+
strokeWeight: cg.lineWidth,
|
|
804
|
+
strokeStyle: cg.lineType,
|
|
805
|
+
fillColor: cg.color,
|
|
806
|
+
fillOpacity: cg.pellucidity
|
|
807
|
+
});
|
|
808
|
+
(_gisRef$current5 = gisRef.current) === null || _gisRef$current5 === void 0 || _gisRef$current5.addOverlay(circle);
|
|
809
|
+
circle.addEventListener("click", function (e) {
|
|
810
|
+
clickGraphic(item.id, e);
|
|
811
|
+
});
|
|
812
|
+
circle.addEventListener("mouseover", function (e) {
|
|
813
|
+
mouseOverGraphic(item.id, e);
|
|
814
|
+
});
|
|
815
|
+
circle.addEventListener("mouseout", function (e) {
|
|
816
|
+
mouseOutGraphic(item.id, e);
|
|
817
|
+
});
|
|
818
|
+
GM.current.setGraphic(item.id, circle);
|
|
819
|
+
ccsids.push(item.id);
|
|
820
|
+
GM.current.setGraphicParam(item.id, {
|
|
821
|
+
attributes: _objectSpread(_objectSpread({}, item), {}, {
|
|
822
|
+
other: item
|
|
823
|
+
}),
|
|
824
|
+
geometryType: "circle",
|
|
825
|
+
geometry: {
|
|
826
|
+
type: "circle",
|
|
827
|
+
x: item.longitude,
|
|
828
|
+
y: item.latitude,
|
|
829
|
+
radius: item.radius
|
|
830
|
+
}
|
|
831
|
+
});
|
|
832
|
+
});
|
|
833
|
+
setState(function (prev) {
|
|
834
|
+
return _objectSpread(_objectSpread({}, prev), {}, {
|
|
835
|
+
circleIds: ccsids
|
|
836
|
+
});
|
|
837
|
+
});
|
|
838
|
+
}, [state.circleIds]);
|
|
839
|
+
|
|
840
|
+
// 更新点
|
|
841
|
+
var updatePoint = (0, _react.useCallback)(function (mapPoints) {
|
|
842
|
+
mapPoints.map(function (item, index) {
|
|
843
|
+
if (GM.current.isRepetition(item.id)) {
|
|
844
|
+
if (!item.longitude || !item.latitude) {
|
|
845
|
+
console.warn("\u70B9 \u7ECF\u7EAC\u5EA6 \u6570\u636E\u9519\u8BEF");
|
|
846
|
+
return false;
|
|
847
|
+
}
|
|
848
|
+
var gc = GM.current.getGraphic(item.id);
|
|
849
|
+
var cg = {
|
|
850
|
+
width: 30,
|
|
851
|
+
height: 30,
|
|
852
|
+
labelContent: "",
|
|
853
|
+
labelPixelX: 0,
|
|
854
|
+
labelPixelY: 34,
|
|
855
|
+
BAnimationType: 3,
|
|
856
|
+
markerContentX: -15,
|
|
857
|
+
markerContentY: -30,
|
|
858
|
+
deg: 0
|
|
859
|
+
};
|
|
860
|
+
if (item.markerContent) {
|
|
861
|
+
cg = _objectSpread(_objectSpread({}, cg), {}, {
|
|
862
|
+
markerContentX: 0,
|
|
863
|
+
markerContentY: 0,
|
|
864
|
+
width: 100,
|
|
865
|
+
height: 30
|
|
866
|
+
});
|
|
867
|
+
}
|
|
868
|
+
if (item.config) {
|
|
869
|
+
cg = _objectSpread(_objectSpread({}, cg), item.config);
|
|
870
|
+
}
|
|
871
|
+
if (item.markerContent) {
|
|
872
|
+
var markerLOption = {
|
|
873
|
+
offset: new BMap.Size(0, 0)
|
|
874
|
+
};
|
|
875
|
+
var markerL = new BMap.Label(item.markerContent, markerLOption);
|
|
876
|
+
markerL.setStyle({
|
|
877
|
+
backgroundColor: "",
|
|
878
|
+
border: "0"
|
|
879
|
+
});
|
|
880
|
+
gc.setLabel(markerL);
|
|
881
|
+
} else {
|
|
882
|
+
cg.width = cg.width || gc.getIcon().size.width;
|
|
883
|
+
cg.height = cg.height || gc.getIcon().size.height;
|
|
884
|
+
var icon = new BMap.Icon(item.url || "".concat(_default2.default.mapServerURL, "/images/defaultMarker.png"), new BMap.Size(cg.width, cg.height));
|
|
885
|
+
icon.setImageSize(new BMap.Size(cg.width, cg.height));
|
|
886
|
+
gc.setIcon(icon);
|
|
887
|
+
gc.setOffset(new BMap.Size((cg.markerContentX || -15) + cg.width / 2, (cg.markerContentY || -30) + cg.height / 2));
|
|
888
|
+
gc.setRotation(cg.deg || 0);
|
|
889
|
+
if (item.canShowLabel && cg.labelContent) {
|
|
890
|
+
var markerLabel = gc.getLabel();
|
|
891
|
+
var labelClass = "label-content";
|
|
892
|
+
if (item.labelClass) {
|
|
893
|
+
labelClass = item.labelClass.split(",").join(" ");
|
|
894
|
+
}
|
|
895
|
+
var labelContent = "<div class='" + labelClass + '\' style="margin-left: 0;">' + cg.labelContent + "</div>";
|
|
896
|
+
var labelOffset = new BMap.Size(cg.labelPixelX, cg.labelPixelY);
|
|
897
|
+
if (markerLabel) {
|
|
898
|
+
markerLabel.setContent(labelContent);
|
|
899
|
+
markerLabel.setOffset(labelOffset);
|
|
900
|
+
} else {
|
|
901
|
+
markerLabel = new BMap.Label(labelContent, {
|
|
902
|
+
offset: labelOffset
|
|
903
|
+
});
|
|
904
|
+
markerLabel.setStyle({
|
|
905
|
+
border: "0",
|
|
906
|
+
backgroundColor: ""
|
|
907
|
+
});
|
|
908
|
+
gc.setLabel(markerLabel);
|
|
909
|
+
}
|
|
910
|
+
} else {
|
|
911
|
+
if (!!gc.getLabel()) {
|
|
912
|
+
gc.getLabel().setContent("");
|
|
913
|
+
}
|
|
914
|
+
}
|
|
915
|
+
if (cg.BAnimationType == 0) {
|
|
916
|
+
gc.setAnimation(BMAP_ANIMATION_BOUNCE);
|
|
917
|
+
} else if (cg.BAnimationType == 1) {
|
|
918
|
+
gc.setAnimation(BMAP_ANIMATION_DROP);
|
|
919
|
+
} else {
|
|
920
|
+
gc.setAnimation(null);
|
|
921
|
+
}
|
|
922
|
+
}
|
|
923
|
+
if (cg.zIndex || cg.zIndex === 0) {
|
|
924
|
+
gc.setZIndex(cg.zIndex);
|
|
925
|
+
}
|
|
926
|
+
GM.current.setGraphicParam(item.id, {
|
|
927
|
+
attributes: _objectSpread(_objectSpread({}, item), {}, {
|
|
928
|
+
other: item
|
|
929
|
+
}),
|
|
930
|
+
geometryType: "point",
|
|
931
|
+
geometry: {
|
|
932
|
+
type: "point",
|
|
933
|
+
x: item.longitude,
|
|
934
|
+
y: item.latitude
|
|
935
|
+
}
|
|
936
|
+
});
|
|
937
|
+
} else {
|
|
938
|
+
console.warn("\u66F4\u65B0\u7684\u70B9\u4F4Did\u4E0D\u5B58\u5728!");
|
|
939
|
+
return false;
|
|
940
|
+
}
|
|
941
|
+
});
|
|
942
|
+
moveAnimation();
|
|
943
|
+
}, []);
|
|
944
|
+
|
|
945
|
+
// 更新线
|
|
946
|
+
var updateLine = (0, _react.useCallback)(function (mapLines) {
|
|
947
|
+
mapLines.map(function (item, index) {
|
|
948
|
+
if (GM.current.isRepetition(item.id)) {
|
|
949
|
+
if (!(item.paths && item.paths.length >= 2)) {
|
|
950
|
+
console.warn("\u591A\u6298\u7EBFpaths\u6570\u636E\u9519\u8BEF");
|
|
951
|
+
return false;
|
|
952
|
+
}
|
|
953
|
+
var gc = GM.current.getGraphic(item.id);
|
|
954
|
+
var cg = {
|
|
955
|
+
color: "#277ffa",
|
|
956
|
+
pellucidity: 0.9,
|
|
957
|
+
lineWidth: 5,
|
|
958
|
+
lineType: "solid",
|
|
959
|
+
isHidden: false
|
|
960
|
+
};
|
|
961
|
+
if (item.config) {
|
|
962
|
+
cg = _objectSpread(_objectSpread({}, cg), item.config);
|
|
963
|
+
}
|
|
964
|
+
var linePath = item.paths.map(function (item, index) {
|
|
965
|
+
return new BMap.Point(item[0], item[1]);
|
|
966
|
+
});
|
|
967
|
+
gc.setPath(linePath);
|
|
968
|
+
gc.setStrokeColor(cg.color);
|
|
969
|
+
gc.setStrokeOpacity(cg.pellucidity);
|
|
970
|
+
gc.setStrokeWeight(cg.lineWidth);
|
|
971
|
+
gc.setStrokeStyle(cg.lineType);
|
|
972
|
+
if (cg.isHidden) {
|
|
973
|
+
gc.hide();
|
|
974
|
+
} else {
|
|
975
|
+
gc.show();
|
|
976
|
+
}
|
|
977
|
+
GM.current.setGraphicParam(item.id, {
|
|
978
|
+
attributes: _objectSpread(_objectSpread({}, item), {}, {
|
|
979
|
+
paths: item.paths,
|
|
980
|
+
other: item
|
|
981
|
+
}),
|
|
982
|
+
geometryType: "polyline",
|
|
983
|
+
geometry: {
|
|
984
|
+
type: "polyline",
|
|
985
|
+
paths: item.paths
|
|
986
|
+
}
|
|
987
|
+
});
|
|
988
|
+
} else {
|
|
989
|
+
console.warn("\u66F4\u65B0\u7684\u591A\u6298\u7EBFid\u4E0D\u5B58\u5728!");
|
|
990
|
+
return false;
|
|
991
|
+
}
|
|
992
|
+
});
|
|
993
|
+
}, []);
|
|
994
|
+
|
|
995
|
+
// 更新面
|
|
996
|
+
var updatePolygon = (0, _react.useCallback)(function (mapPolygons) {
|
|
997
|
+
mapPolygons.map(function (item, index) {
|
|
998
|
+
if (GM.current.isRepetition(item.id)) {
|
|
999
|
+
if (!(item.rings && item.rings.length >= 3)) {
|
|
1000
|
+
console.warn("\u591A\u8FB9\u5F62rings\u6570\u636E\u9519\u8BEF");
|
|
1001
|
+
return false;
|
|
1002
|
+
}
|
|
1003
|
+
var gc = GM.current.getGraphic(item.id);
|
|
1004
|
+
var cg = {
|
|
1005
|
+
lineType: "solid",
|
|
1006
|
+
lineWidth: 5,
|
|
1007
|
+
lineColor: "#277ffa",
|
|
1008
|
+
lineOpacity: 1,
|
|
1009
|
+
color: "#fff",
|
|
1010
|
+
pellucidity: 0.5
|
|
1011
|
+
};
|
|
1012
|
+
if (item.config) {
|
|
1013
|
+
cg = _objectSpread(_objectSpread({}, cg), item.config);
|
|
1014
|
+
}
|
|
1015
|
+
var polygonPath = item.rings.map(function (item, index) {
|
|
1016
|
+
return new BMap.Point(item[0], item[1]);
|
|
1017
|
+
});
|
|
1018
|
+
gc.setPath(polygonPath);
|
|
1019
|
+
gc.setStrokeColor(cg.lineColor);
|
|
1020
|
+
gc.setFillColor(cg.color);
|
|
1021
|
+
gc.setStrokeOpacity(cg.lineOpacity);
|
|
1022
|
+
gc.setFillOpacity(cg.pellucidity);
|
|
1023
|
+
gc.setStrokeWeight(cg.lineWidth);
|
|
1024
|
+
gc.setStrokeStyle(cg.lineType);
|
|
1025
|
+
GM.current.setGraphicParam(item.id, {
|
|
1026
|
+
attributes: _objectSpread(_objectSpread({}, item), {}, {
|
|
1027
|
+
rings: item.rings,
|
|
1028
|
+
other: item
|
|
1029
|
+
}),
|
|
1030
|
+
geometryType: "polygon",
|
|
1031
|
+
geometry: {
|
|
1032
|
+
type: "polygon",
|
|
1033
|
+
rings: item.rings
|
|
1034
|
+
}
|
|
1035
|
+
});
|
|
1036
|
+
} else {
|
|
1037
|
+
console.warn("\u66F4\u65B0\u7684\u591A\u8FB9\u5F62id\u4E0D\u5B58\u5728!");
|
|
1038
|
+
return false;
|
|
1039
|
+
}
|
|
1040
|
+
});
|
|
1041
|
+
}, []);
|
|
1042
|
+
|
|
1043
|
+
// 更新圆
|
|
1044
|
+
var updateCircle = (0, _react.useCallback)(function (mapCircles) {
|
|
1045
|
+
mapCircles.map(function (item, index) {
|
|
1046
|
+
if (GM.current.isRepetition(item.id)) {
|
|
1047
|
+
if (!item.longitude || !item.latitude) {
|
|
1048
|
+
console.warn("\u5706 \u7ECF\u7EAC\u5EA6 \u6570\u636E\u9519\u8BEF");
|
|
1049
|
+
return false;
|
|
1050
|
+
}
|
|
1051
|
+
var gc = GM.current.getGraphic(item.id);
|
|
1052
|
+
var cg = {
|
|
1053
|
+
lineType: "solid",
|
|
1054
|
+
lineWidth: 5,
|
|
1055
|
+
lineColor: "#277ffa",
|
|
1056
|
+
lineOpacity: 1,
|
|
1057
|
+
color: "#fff",
|
|
1058
|
+
pellucidity: 0.5
|
|
1059
|
+
};
|
|
1060
|
+
if (item.config) {
|
|
1061
|
+
cg = _objectSpread(_objectSpread({}, cg), item.config);
|
|
1062
|
+
}
|
|
1063
|
+
var centerPoint = new BMap.Point(item.longitude, item.latitude);
|
|
1064
|
+
gc.setCenter(centerPoint);
|
|
1065
|
+
gc.setRadius(item.radius);
|
|
1066
|
+
gc.setStrokeColor(cg.lineColor);
|
|
1067
|
+
gc.setFillColor(cg.color);
|
|
1068
|
+
gc.setStrokeOpacity(cg.lineOpacity);
|
|
1069
|
+
gc.setFillOpacity(cg.pellucidity);
|
|
1070
|
+
gc.setStrokeWeight(cg.lineWidth);
|
|
1071
|
+
gc.setStrokeStyle(cg.lineType);
|
|
1072
|
+
GM.current.setGraphicParam(item.id, {
|
|
1073
|
+
attributes: _objectSpread(_objectSpread({}, item), {}, {
|
|
1074
|
+
other: item
|
|
1075
|
+
}),
|
|
1076
|
+
geometryType: "circle",
|
|
1077
|
+
geometry: {
|
|
1078
|
+
type: "circle",
|
|
1079
|
+
x: item.longitude,
|
|
1080
|
+
y: item.latitude,
|
|
1081
|
+
radius: item.radius
|
|
1082
|
+
}
|
|
1083
|
+
});
|
|
1084
|
+
} else {
|
|
1085
|
+
console.warn("\u66F4\u65B0\u7684\u5706id\u4E0D\u5B58\u5728!");
|
|
1086
|
+
return false;
|
|
1087
|
+
}
|
|
1088
|
+
});
|
|
1089
|
+
}, []);
|
|
1090
|
+
|
|
1091
|
+
//添加海量点
|
|
1092
|
+
var addPointCollection = (0, _react.useCallback)(function () {
|
|
1093
|
+
var data = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : [];
|
|
1094
|
+
var t = _this;
|
|
1095
|
+
data.map(function (item, index) {
|
|
1096
|
+
var d = item || {};
|
|
1097
|
+
var points = [];
|
|
1098
|
+
(d.points || []).map(function (d, i) {
|
|
1099
|
+
var p = new BMap.Point(d.lng, d.lat);
|
|
1100
|
+
p.attributes = d;
|
|
1101
|
+
points.push(p);
|
|
1102
|
+
});
|
|
1103
|
+
var options = {
|
|
1104
|
+
size: gisMapConstant[d.size] || gisMapConstant["normal"],
|
|
1105
|
+
shape: gisMapConstant[d.shape] || gisMapConstant["circle"],
|
|
1106
|
+
color: d.color || "#d340c3"
|
|
1107
|
+
};
|
|
1108
|
+
// 初始化PointCollection
|
|
1109
|
+
var VotexpointCollection = new BMap.PointCollection(points, options);
|
|
1110
|
+
gis.current.addOverlay(VotexpointCollection); // 添加Overlay
|
|
1111
|
+
morepoints.current.push({
|
|
1112
|
+
id: d.id,
|
|
1113
|
+
value: VotexpointCollection
|
|
1114
|
+
});
|
|
1115
|
+
VotexpointCollection.addEventListener("click", function (e) {
|
|
1116
|
+
if ("clickPointCollection" in t.props && typeof t.props.clickPointCollection == "function") {
|
|
1117
|
+
var obj = _objectSpread(_objectSpread({
|
|
1118
|
+
id: d.id
|
|
1119
|
+
}, e.point), {}, {
|
|
1120
|
+
mapLayer: VotexpointCollection
|
|
1121
|
+
});
|
|
1122
|
+
t.props.clickPointCollection(obj);
|
|
1123
|
+
}
|
|
1124
|
+
});
|
|
1125
|
+
});
|
|
1126
|
+
}, []);
|
|
1127
|
+
//更新海量点
|
|
1128
|
+
var updatePointCollection = (0, _react.useCallback)(function () {
|
|
1129
|
+
var data = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : [];
|
|
1130
|
+
var t = _this;
|
|
1131
|
+
data.map(function (ds, i) {
|
|
1132
|
+
morepoints.current.map(function (item, index) {
|
|
1133
|
+
if (item.id == ds.id) {
|
|
1134
|
+
var points = [];
|
|
1135
|
+
ds.points.map(function (d, i) {
|
|
1136
|
+
var p = new BMap.Point(d.lng, d.lat);
|
|
1137
|
+
p.attributes = d;
|
|
1138
|
+
points.push(p);
|
|
1139
|
+
});
|
|
1140
|
+
item.value.setPoints(points);
|
|
1141
|
+
item.value.setStyles({
|
|
1142
|
+
size: gisMapConstant[ds.size] || gisMapConstant["normal"],
|
|
1143
|
+
shape: gisMapConstant[ds.shape] || gisMapConstant["circle"],
|
|
1144
|
+
color: ds.color || "#d340c3"
|
|
1145
|
+
});
|
|
1146
|
+
}
|
|
1147
|
+
});
|
|
1148
|
+
});
|
|
1149
|
+
}, []);
|
|
1150
|
+
//清空单个海量点
|
|
1151
|
+
var clearPointCollection = (0, _react.useCallback)(function (ids) {
|
|
1152
|
+
ids.map(function (id, ind) {
|
|
1153
|
+
morepoints.current.map(function (item, index) {
|
|
1154
|
+
if (id == item.id) {
|
|
1155
|
+
item.value.clear();
|
|
1156
|
+
}
|
|
1157
|
+
});
|
|
1158
|
+
});
|
|
1159
|
+
}, []);
|
|
1160
|
+
//清空海量点
|
|
1161
|
+
var clearAllPointCollection = (0, _react.useCallback)(function () {
|
|
1162
|
+
morepoints.current.map(function (item, index) {
|
|
1163
|
+
item.value.clear();
|
|
1164
|
+
});
|
|
1165
|
+
}, []);
|
|
1166
|
+
// 图元点击事件
|
|
1167
|
+
var clickGraphic = (0, _react.useCallback)(function (id, e) {
|
|
1168
|
+
if (state.editId == id) return false;
|
|
1169
|
+
if (typeof props.clickGraphic === "function") {
|
|
1170
|
+
var obj = {
|
|
1171
|
+
id: id,
|
|
1172
|
+
param: getGraphic(id),
|
|
1173
|
+
top: e.clientY,
|
|
1174
|
+
left: e.clientX,
|
|
1175
|
+
e: e
|
|
1176
|
+
};
|
|
1177
|
+
props.clickGraphic(obj);
|
|
1178
|
+
}
|
|
1179
|
+
}, [props.clickGraphic, state.editId, getGraphic]);
|
|
1180
|
+
// 图元鼠标悬浮事件
|
|
1181
|
+
var mouseOverGraphic = (0, _react.useCallback)(function (id, e) {
|
|
1182
|
+
if (state.editId == id) return false;
|
|
1183
|
+
if (typeof props.mouseOverGraphic === "function") {
|
|
1184
|
+
var obj = {
|
|
1185
|
+
e: e,
|
|
1186
|
+
id: id,
|
|
1187
|
+
param: getGraphic(id),
|
|
1188
|
+
top: e.clientY,
|
|
1189
|
+
left: e.clientX
|
|
1190
|
+
};
|
|
1191
|
+
props.mouseOverGraphic(obj);
|
|
1192
|
+
}
|
|
1193
|
+
}, [props.mouseOverGraphic, state.editId, getGraphic]);
|
|
1194
|
+
|
|
1195
|
+
// 图元鼠标移开事件
|
|
1196
|
+
var mouseOutGraphic = (0, _react.useCallback)(function (id, e) {
|
|
1197
|
+
if (state.editId == id) return false;
|
|
1198
|
+
if (typeof props.mouseOutGraphic === "function") {
|
|
1199
|
+
var obj = {
|
|
1200
|
+
e: e,
|
|
1201
|
+
id: id,
|
|
1202
|
+
param: getGraphic(id),
|
|
1203
|
+
top: e.clientY,
|
|
1204
|
+
left: e.clientX
|
|
1205
|
+
};
|
|
1206
|
+
props.mouseOutGraphic(obj);
|
|
1207
|
+
}
|
|
1208
|
+
}, [props.mouseOutGraphic, state.editId, getGraphic]);
|
|
1209
|
+
// 添加点聚合功能
|
|
1210
|
+
var setCluster = (0, _react.useCallback)(function () {
|
|
1211
|
+
var mapCluster = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : [];
|
|
1212
|
+
if (cluster.current && mapCluster instanceof Array) {
|
|
1213
|
+
// 清除之前的聚合
|
|
1214
|
+
cluster.current.clearMarkers();
|
|
1215
|
+
|
|
1216
|
+
// 获取所有点图形
|
|
1217
|
+
var markers = [];
|
|
1218
|
+
mapCluster.forEach(function (id) {
|
|
1219
|
+
var graphic = GM.current.getGraphic(id);
|
|
1220
|
+
if (graphic) {
|
|
1221
|
+
markers.push(graphic);
|
|
1222
|
+
}
|
|
1223
|
+
});
|
|
1224
|
+
|
|
1225
|
+
// 设置新的聚合
|
|
1226
|
+
if (markers.length > 0) {
|
|
1227
|
+
cluster.current.addMarkers(markers);
|
|
1228
|
+
}
|
|
1229
|
+
}
|
|
1230
|
+
}, []);
|
|
1231
|
+
|
|
1232
|
+
// 设置地图类型
|
|
1233
|
+
var setMapType = (0, _react.useCallback)(function (type) {
|
|
1234
|
+
var _gisRef$current6, _gisRef$current7;
|
|
1235
|
+
switch (type) {
|
|
1236
|
+
case "sl":
|
|
1237
|
+
(_gisRef$current6 = gisRef.current) === null || _gisRef$current6 === void 0 || _gisRef$current6.setMapType(BMAP_NORMAL_MAP);
|
|
1238
|
+
break;
|
|
1239
|
+
case "wx":
|
|
1240
|
+
(_gisRef$current7 = gisRef.current) === null || _gisRef$current7 === void 0 || _gisRef$current7.setMapType(BMAP_SATELLITE_MAP);
|
|
1241
|
+
break;
|
|
1242
|
+
}
|
|
1243
|
+
}, []);
|
|
1244
|
+
//展示地图切换控件
|
|
1245
|
+
var showMapTypeControl = (0, _react.useCallback)(function (props) {
|
|
1246
|
+
var location = AnchorConstant["br"],
|
|
1247
|
+
offset = null;
|
|
1248
|
+
var config = props;
|
|
1249
|
+
if (mapTypeControl.current) {
|
|
1250
|
+
gis.current.removeControl(mapTypeControl.current);
|
|
1251
|
+
}
|
|
1252
|
+
if (config.satelliteSwitch.location) {
|
|
1253
|
+
location = AnchorConstant[config.satelliteSwitch.location];
|
|
1254
|
+
}
|
|
1255
|
+
if (config.satelliteSwitch.offset && config.satelliteSwitch.offset.length > 0) {
|
|
1256
|
+
offset = new BMap.Size(config.satelliteSwitch.offset[0], config.satelliteSwitch.offset[1]);
|
|
1257
|
+
}
|
|
1258
|
+
var mapTypes = [BMAP_NORMAL_MAP, BMAP_SATELLITE_MAP, BMAP_HYBRID_MAP];
|
|
1259
|
+
// 地图切换控件
|
|
1260
|
+
var control = new BMap.MapTypeControl({
|
|
1261
|
+
mapTypes: mapTypes,
|
|
1262
|
+
anchor: location,
|
|
1263
|
+
type: BMAP_MAPTYPE_CONTROL_HORIZONTAL,
|
|
1264
|
+
offset: offset
|
|
1265
|
+
});
|
|
1266
|
+
gis.current.addControl(control);
|
|
1267
|
+
mapTypeControl.current = control;
|
|
1268
|
+
}, []);
|
|
1269
|
+
|
|
1270
|
+
// 设置区域限制
|
|
1271
|
+
var setAreaRestriction = (0, _react.useCallback)(function (sw_ne) {
|
|
1272
|
+
var bounds = new BMap.Bounds(new BMap.Point(sw_ne[0][0], sw_ne[0][1]), new BMap.Point(sw_ne[1][0], sw_ne[1][1]));
|
|
1273
|
+
bmar.current.setBounds(gisRef.current, bounds);
|
|
1274
|
+
}, []);
|
|
1275
|
+
|
|
1276
|
+
// 取消显示区域
|
|
1277
|
+
var clearAreaRestriction = (0, _react.useCallback)(function () {
|
|
1278
|
+
bmar.current.clearBounds();
|
|
1279
|
+
}, []);
|
|
1280
|
+
|
|
1281
|
+
// 移动动画
|
|
1282
|
+
var moveAnimation = (0, _react.useCallback)(function () {
|
|
1283
|
+
if (moveToTimer.current) {
|
|
1284
|
+
clearInterval(moveToTimer.current);
|
|
1285
|
+
}
|
|
1286
|
+
moveToTimer.current = setInterval(function () {
|
|
1287
|
+
var nowMovePoints = _toConsumableArray(movePoints.current);
|
|
1288
|
+
var deleteIndex = [];
|
|
1289
|
+
for (var i = 0; i < nowMovePoints.length; i++) {
|
|
1290
|
+
nowMovePoints[i].waitTime += 10;
|
|
1291
|
+
if (nowMovePoints[i].waitTime >= nowMovePoints[i].deleteTime) {
|
|
1292
|
+
deleteIndex.push(i);
|
|
1293
|
+
} else {
|
|
1294
|
+
var gc = GM.current.getGraphic(nowMovePoints[i].id);
|
|
1295
|
+
var p = gc.getPosition();
|
|
1296
|
+
gc.setPosition(new BMap.Point(p.lng + nowMovePoints[i].rx, p.lat + nowMovePoints[i].ry));
|
|
1297
|
+
}
|
|
1298
|
+
}
|
|
1299
|
+
for (var _i = deleteIndex.length - 1; _i >= 0; _i--) {
|
|
1300
|
+
movePoints.current.splice(deleteIndex[_i], 1);
|
|
1301
|
+
}
|
|
1302
|
+
if (nowMovePoints.length == 0) {
|
|
1303
|
+
clearInterval(moveToTimer.current);
|
|
1304
|
+
}
|
|
1305
|
+
}, 10);
|
|
1306
|
+
}, []);
|
|
1307
|
+
|
|
1308
|
+
// 移动到指定位置
|
|
1309
|
+
var moveTo = (0, _react.useCallback)(function (id, lnglat, delay, autoRotation, urlright, urlleft) {
|
|
1310
|
+
delay = delay || 3;
|
|
1311
|
+
var timer = 10;
|
|
1312
|
+
var gc = GM.current.getGraphic(id);
|
|
1313
|
+
delay = eval(delay) * 1000;
|
|
1314
|
+
var count = delay / timer;
|
|
1315
|
+
var s = gc.getPosition(),
|
|
1316
|
+
e = new BMap.Point(lnglat[0], lnglat[1]);
|
|
1317
|
+
if (s.equals(e)) {
|
|
1318
|
+
return false;
|
|
1319
|
+
} else {
|
|
1320
|
+
var url = null;
|
|
1321
|
+
if (autoRotation) {
|
|
1322
|
+
var ddeg = rotateDeg(gc.getPosition(), lnglat);
|
|
1323
|
+
if (urlleft && ddeg < -90 && ddeg > -270) {
|
|
1324
|
+
ddeg += 180;
|
|
1325
|
+
url = urlleft;
|
|
1326
|
+
} else {
|
|
1327
|
+
url = urlright;
|
|
1328
|
+
}
|
|
1329
|
+
var gcicon = gc.getIcon();
|
|
1330
|
+
gcicon.setImageUrl(url);
|
|
1331
|
+
gc.setIcon(gcicon);
|
|
1332
|
+
gc.setRotation(ddeg);
|
|
1333
|
+
}
|
|
1334
|
+
var rx = (e.lng - s.lng) / count,
|
|
1335
|
+
ry = (e.lat - s.lat) / count;
|
|
1336
|
+
var isHave = false;
|
|
1337
|
+
for (var i = 0; i < movePoints.current.length; i++) {
|
|
1338
|
+
if (movePoints.current[i].id == id) {
|
|
1339
|
+
movePoints.current.splice(i, 1, {
|
|
1340
|
+
id: id,
|
|
1341
|
+
rx: rx,
|
|
1342
|
+
ry: ry,
|
|
1343
|
+
waitTime: 0,
|
|
1344
|
+
deleteTime: delay
|
|
1345
|
+
});
|
|
1346
|
+
isHave = true;
|
|
1347
|
+
}
|
|
1348
|
+
}
|
|
1349
|
+
if (!isHave) {
|
|
1350
|
+
movePoints.current.push({
|
|
1351
|
+
id: id,
|
|
1352
|
+
rx: rx,
|
|
1353
|
+
ry: ry,
|
|
1354
|
+
waitTime: 0,
|
|
1355
|
+
deleteTime: delay
|
|
1356
|
+
});
|
|
1357
|
+
}
|
|
1358
|
+
}
|
|
1359
|
+
}, []);
|
|
1360
|
+
|
|
1361
|
+
// 点位角度旋转
|
|
1362
|
+
var rotateDeg = (0, _react.useCallback)(function (sp, ep) {
|
|
1363
|
+
var spLngLat = sp;
|
|
1364
|
+
if (Array.isArray(sp)) {
|
|
1365
|
+
spLngLat = new BMap.Point(sp[0], sp[1]);
|
|
1366
|
+
}
|
|
1367
|
+
var epLngLat = ep;
|
|
1368
|
+
if (Array.isArray(ep)) {
|
|
1369
|
+
epLngLat = new BMap.Point(ep[0], ep[1]);
|
|
1370
|
+
}
|
|
1371
|
+
var disx = epLngLat.lng - spLngLat.lng;
|
|
1372
|
+
var disy = epLngLat.lat - spLngLat.lat;
|
|
1373
|
+
var deg = 0;
|
|
1374
|
+
if (disx != 0) {
|
|
1375
|
+
var _bias = Math.atan(disy / disx) / (Math.PI / 180);
|
|
1376
|
+
deg = -_bias;
|
|
1377
|
+
if (disx > 0) {
|
|
1378
|
+
deg -= 90;
|
|
1379
|
+
} else {
|
|
1380
|
+
deg += 90;
|
|
1381
|
+
}
|
|
1382
|
+
} else {
|
|
1383
|
+
if (disy == 0) deg = 0;
|
|
1384
|
+
deg = -bias * 90;
|
|
1385
|
+
}
|
|
1386
|
+
return deg;
|
|
1387
|
+
}, []);
|
|
1388
|
+
|
|
1389
|
+
// 开启路况
|
|
1390
|
+
var openTrafficInfo = (0, _react.useCallback)(function () {
|
|
1391
|
+
trafficCtrl.current.showTraffic();
|
|
1392
|
+
}, []);
|
|
1393
|
+
|
|
1394
|
+
// 关闭路况
|
|
1395
|
+
var hideTrafficInfo = (0, _react.useCallback)(function () {
|
|
1396
|
+
trafficCtrl.current.hideTraffic();
|
|
1397
|
+
}, []);
|
|
1398
|
+
|
|
1399
|
+
// 处理点数据变化
|
|
1400
|
+
var handlePointsChange = (0, _react.useCallback)(function () {
|
|
1401
|
+
var prevPoints = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : [];
|
|
1402
|
+
var currentPoints = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : [];
|
|
1403
|
+
console.log("handlePointsChange", prevPoints, currentPoints, deepEqual(prevPoints, currentPoints));
|
|
1404
|
+
if (!deepEqual(prevPoints, currentPoints)) {
|
|
1405
|
+
var _dataMatch = dataMatch(prevPoints, currentPoints, "id"),
|
|
1406
|
+
deletedDataIDs = _dataMatch.deletedDataIDs,
|
|
1407
|
+
addedData = _dataMatch.addedData,
|
|
1408
|
+
updatedData = _dataMatch.updatedData;
|
|
1409
|
+
var _dealAdd = dealAdd(addedData, _toConsumableArray(state.pointIds)),
|
|
1410
|
+
ads = _dealAdd.ads,
|
|
1411
|
+
otherupds = _dealAdd.otherupds;
|
|
1412
|
+
var _dealUpdate = dealUpdate(updatedData, _toConsumableArray(state.pointIds)),
|
|
1413
|
+
upds = _dealUpdate.upds,
|
|
1414
|
+
otherads = _dealUpdate.otherads;
|
|
1415
|
+
console.log("handlePointsChange", deletedDataIDs);
|
|
1416
|
+
// 删除
|
|
1417
|
+
var _iterator = _createForOfIteratorHelper(deletedDataIDs),
|
|
1418
|
+
_step;
|
|
1419
|
+
try {
|
|
1420
|
+
for (_iterator.s(); !(_step = _iterator.n()).done;) {
|
|
1421
|
+
var id = _step.value;
|
|
1422
|
+
removeGraphic(id, "point");
|
|
1423
|
+
}
|
|
1424
|
+
|
|
1425
|
+
// 增加
|
|
1426
|
+
} catch (err) {
|
|
1427
|
+
_iterator.e(err);
|
|
1428
|
+
} finally {
|
|
1429
|
+
_iterator.f();
|
|
1430
|
+
}
|
|
1431
|
+
addPoint([].concat(_toConsumableArray(ads), _toConsumableArray(otherads)));
|
|
1432
|
+
|
|
1433
|
+
// 更新
|
|
1434
|
+
updatePoint([].concat(_toConsumableArray(upds), _toConsumableArray(otherupds)));
|
|
1435
|
+
}
|
|
1436
|
+
}, [state.pointIds, dataMatch, dealAdd, dealUpdate, removeGraphic, addPoint, updatePoint, deepEqual]);
|
|
1437
|
+
|
|
1438
|
+
// 处理线数据变化
|
|
1439
|
+
var handleLinesChange = (0, _react.useCallback)(function () {
|
|
1440
|
+
var prevLines = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : [];
|
|
1441
|
+
var currentLines = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : [];
|
|
1442
|
+
if (!deepEqual(prevLines, currentLines)) {
|
|
1443
|
+
var _dataMatch2 = dataMatch(prevLines, currentLines, "id"),
|
|
1444
|
+
deletedDataIDs = _dataMatch2.deletedDataIDs,
|
|
1445
|
+
addedData = _dataMatch2.addedData,
|
|
1446
|
+
updatedData = _dataMatch2.updatedData;
|
|
1447
|
+
var _dealAdd2 = dealAdd(addedData, _toConsumableArray(state.lineIds)),
|
|
1448
|
+
ads = _dealAdd2.ads,
|
|
1449
|
+
otherupds = _dealAdd2.otherupds;
|
|
1450
|
+
var _dealUpdate2 = dealUpdate(updatedData, _toConsumableArray(state.lineIds)),
|
|
1451
|
+
upds = _dealUpdate2.upds,
|
|
1452
|
+
otherads = _dealUpdate2.otherads;
|
|
1453
|
+
|
|
1454
|
+
// 删除
|
|
1455
|
+
var _iterator2 = _createForOfIteratorHelper(deletedDataIDs),
|
|
1456
|
+
_step2;
|
|
1457
|
+
try {
|
|
1458
|
+
for (_iterator2.s(); !(_step2 = _iterator2.n()).done;) {
|
|
1459
|
+
var id = _step2.value;
|
|
1460
|
+
removeGraphic(id, "line");
|
|
1461
|
+
}
|
|
1462
|
+
|
|
1463
|
+
// 增加
|
|
1464
|
+
} catch (err) {
|
|
1465
|
+
_iterator2.e(err);
|
|
1466
|
+
} finally {
|
|
1467
|
+
_iterator2.f();
|
|
1468
|
+
}
|
|
1469
|
+
addLine([].concat(_toConsumableArray(ads), _toConsumableArray(otherads)));
|
|
1470
|
+
|
|
1471
|
+
// 更新
|
|
1472
|
+
updateLine([].concat(_toConsumableArray(upds), _toConsumableArray(otherads)));
|
|
1473
|
+
}
|
|
1474
|
+
}, [state.lineIds, dataMatch, dealAdd, dealUpdate, removeGraphic, addLine, updateLine, deepEqual]);
|
|
1475
|
+
|
|
1476
|
+
// 处理面数据变化
|
|
1477
|
+
var handlePolygonsChange = (0, _react.useCallback)(function () {
|
|
1478
|
+
var prevPolygons = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : [];
|
|
1479
|
+
var currentPolygons = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : [];
|
|
1480
|
+
if (!deepEqual(prevPolygons, currentPolygons)) {
|
|
1481
|
+
var _dataMatch3 = dataMatch(prevPolygons, currentPolygons, "id"),
|
|
1482
|
+
deletedDataIDs = _dataMatch3.deletedDataIDs,
|
|
1483
|
+
addedData = _dataMatch3.addedData,
|
|
1484
|
+
updatedData = _dataMatch3.updatedData;
|
|
1485
|
+
var _dealAdd3 = dealAdd(addedData, _toConsumableArray(state.polygonIds)),
|
|
1486
|
+
ads = _dealAdd3.ads,
|
|
1487
|
+
otherupds = _dealAdd3.otherupds;
|
|
1488
|
+
var _dealUpdate3 = dealUpdate(updatedData, _toConsumableArray(state.polygonIds)),
|
|
1489
|
+
upds = _dealUpdate3.upds,
|
|
1490
|
+
otherads = _dealUpdate3.otherads;
|
|
1491
|
+
|
|
1492
|
+
// 删除
|
|
1493
|
+
var _iterator3 = _createForOfIteratorHelper(deletedDataIDs),
|
|
1494
|
+
_step3;
|
|
1495
|
+
try {
|
|
1496
|
+
for (_iterator3.s(); !(_step3 = _iterator3.n()).done;) {
|
|
1497
|
+
var id = _step3.value;
|
|
1498
|
+
removeGraphic(id, "polygon");
|
|
1499
|
+
}
|
|
1500
|
+
|
|
1501
|
+
// 增加
|
|
1502
|
+
} catch (err) {
|
|
1503
|
+
_iterator3.e(err);
|
|
1504
|
+
} finally {
|
|
1505
|
+
_iterator3.f();
|
|
1506
|
+
}
|
|
1507
|
+
addPolygon([].concat(_toConsumableArray(ads), _toConsumableArray(otherads)));
|
|
1508
|
+
|
|
1509
|
+
// 更新
|
|
1510
|
+
updatePolygon([].concat(_toConsumableArray(upds), _toConsumableArray(otherads)));
|
|
1511
|
+
}
|
|
1512
|
+
}, [state.polygonIds, dataMatch, dealAdd, dealUpdate, removeGraphic, addPolygon, updatePolygon, deepEqual]);
|
|
1513
|
+
|
|
1514
|
+
// 处理圆数据变化
|
|
1515
|
+
var handleCirclesChange = (0, _react.useCallback)(function () {
|
|
1516
|
+
var prevCircles = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : [];
|
|
1517
|
+
var currentCircles = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : [];
|
|
1518
|
+
if (!deepEqual(prevCircles, currentCircles)) {
|
|
1519
|
+
var _dataMatch4 = dataMatch(prevCircles, currentCircles, "id"),
|
|
1520
|
+
deletedDataIDs = _dataMatch4.deletedDataIDs,
|
|
1521
|
+
addedData = _dataMatch4.addedData,
|
|
1522
|
+
updatedData = _dataMatch4.updatedData;
|
|
1523
|
+
var _dealAdd4 = dealAdd(addedData, _toConsumableArray(state.circleIds)),
|
|
1524
|
+
ads = _dealAdd4.ads,
|
|
1525
|
+
otherupds = _dealAdd4.otherupds;
|
|
1526
|
+
var _dealUpdate4 = dealUpdate(updatedData, _toConsumableArray(state.circleIds)),
|
|
1527
|
+
upds = _dealUpdate4.upds,
|
|
1528
|
+
otherads = _dealUpdate4.otherads;
|
|
1529
|
+
|
|
1530
|
+
// 删除
|
|
1531
|
+
var _iterator4 = _createForOfIteratorHelper(deletedDataIDs),
|
|
1532
|
+
_step4;
|
|
1533
|
+
try {
|
|
1534
|
+
for (_iterator4.s(); !(_step4 = _iterator4.n()).done;) {
|
|
1535
|
+
var id = _step4.value;
|
|
1536
|
+
removeGraphic(id, "circle");
|
|
1537
|
+
}
|
|
1538
|
+
|
|
1539
|
+
// 增加
|
|
1540
|
+
} catch (err) {
|
|
1541
|
+
_iterator4.e(err);
|
|
1542
|
+
} finally {
|
|
1543
|
+
_iterator4.f();
|
|
1544
|
+
}
|
|
1545
|
+
addCircle([].concat(_toConsumableArray(ads), _toConsumableArray(otherads)));
|
|
1546
|
+
|
|
1547
|
+
// 更新
|
|
1548
|
+
updateCircle([].concat(_toConsumableArray(upds), _toConsumableArray(otherads)));
|
|
1549
|
+
}
|
|
1550
|
+
}, [state.circleIds, dataMatch, dealAdd, dealUpdate, removeGraphic, addCircle, updateCircle, deepEqual]);
|
|
1551
|
+
var handleClusterChange = (0, _react.useCallback)(function (prevCluster, currentCluster) {
|
|
1552
|
+
if (!deepEqual(prevCluster, currentCluster)) {
|
|
1553
|
+
setCluster(currentCluster);
|
|
1554
|
+
}
|
|
1555
|
+
}, [deepEqual]);
|
|
1556
|
+
var setMapStyle = (0, _react.useCallback)(function (prevMapStyle, currentMapStyle) {
|
|
1557
|
+
if (currentMapStyle && !deepEqual(prevMapStyle, currentMapStyle)) {
|
|
1558
|
+
if (typeof currentMapStyle === "string") {
|
|
1559
|
+
gisRef.current.setMapStyle({
|
|
1560
|
+
style: currentMapStyle
|
|
1561
|
+
});
|
|
1562
|
+
}
|
|
1563
|
+
if (mapStyle instanceof Array) {
|
|
1564
|
+
gisRef.current.setMapStyle({
|
|
1565
|
+
styleJson: currentMapStyle
|
|
1566
|
+
});
|
|
1567
|
+
}
|
|
1568
|
+
}
|
|
1569
|
+
}, [deepEqual]);
|
|
1570
|
+
var handlePointsCollectionChange = (0, _react.useCallback)(function (prevPointsCollection, currentPointsCollection) {
|
|
1571
|
+
if (!deepEqual(prevPointsCollection, currentPointsCollection)) {
|
|
1572
|
+
var _dataMatch5 = dataMatch(prevPointsCollection, currentPointsCollection, "id"),
|
|
1573
|
+
deletedDataIDs = _dataMatch5.deletedDataIDs,
|
|
1574
|
+
addedData = _dataMatch5.addedData,
|
|
1575
|
+
updatedData = _dataMatch5.updatedData;
|
|
1576
|
+
clearPointCollection(deletedDataIDs);
|
|
1577
|
+
addPointCollection(addedData);
|
|
1578
|
+
updatePointCollection(updatedData);
|
|
1579
|
+
}
|
|
1580
|
+
}, [deepEqual, dataMatch, clearPointCollection, addPointCollection, updatePointCollection]);
|
|
1581
|
+
|
|
1582
|
+
// 初始化
|
|
1583
|
+
var init = (0, _react.useCallback)(function () {
|
|
1584
|
+
var map = createMap();
|
|
1585
|
+
gisRef.current = map;
|
|
1586
|
+
var mapPoints = props.mapPoints,
|
|
1587
|
+
mapLines = props.mapLines,
|
|
1588
|
+
mapPolygons = props.mapPolygons,
|
|
1589
|
+
mapCircles = props.mapCircles,
|
|
1590
|
+
coverageType = props.coverageType,
|
|
1591
|
+
mapCluster = props.mapCluster;
|
|
1592
|
+
|
|
1593
|
+
// 添加点
|
|
1594
|
+
if (mapPoints instanceof Array) {
|
|
1595
|
+
addPoint(mapPoints);
|
|
1596
|
+
}
|
|
1597
|
+
|
|
1598
|
+
// 添加线
|
|
1599
|
+
if (mapLines instanceof Array) {
|
|
1600
|
+
addLine(mapLines);
|
|
1601
|
+
}
|
|
1602
|
+
|
|
1603
|
+
// 添加面
|
|
1604
|
+
if (mapPolygons instanceof Array) {
|
|
1605
|
+
addPolygon(mapPolygons);
|
|
1606
|
+
}
|
|
1607
|
+
|
|
1608
|
+
// 添加圆
|
|
1609
|
+
if (mapCircles instanceof Array) {
|
|
1610
|
+
addCircle(mapCircles);
|
|
1611
|
+
}
|
|
1612
|
+
|
|
1613
|
+
// 设置点聚合
|
|
1614
|
+
if (mapCluster instanceof Array) {
|
|
1615
|
+
cluster(mapCluster);
|
|
1616
|
+
}
|
|
1617
|
+
// 切换地图类型
|
|
1618
|
+
if (coverageType) {
|
|
1619
|
+
setMapType(coverageType);
|
|
1620
|
+
}
|
|
1621
|
+
|
|
1622
|
+
// 保存当前props作为下一次比较的基准
|
|
1623
|
+
prevPropsRef.current = _objectSpread({}, props);
|
|
1624
|
+
}, [createMap, props, addPoint, addLine, addPolygon, addCircle, cluster, setMapType]);
|
|
1625
|
+
|
|
1626
|
+
// 组件挂载
|
|
1627
|
+
(0, _ahooks.useMount)(function () {
|
|
1628
|
+
loadMapJs().then(function () {
|
|
1629
|
+
init();
|
|
1630
|
+
}).catch(function (error) {
|
|
1631
|
+
console.error("Failed to load map:", error);
|
|
1632
|
+
});
|
|
1633
|
+
}, []);
|
|
1634
|
+
|
|
1635
|
+
// 设置地图地图样式
|
|
1636
|
+
(0, _ahooks.useDeepCompareEffect)(function () {
|
|
1637
|
+
if (!gisRef.current) return;
|
|
1638
|
+
var prevProps = prevPropsRef.current;
|
|
1639
|
+
if (props.mapStyle !== prevProps.mapStyle) {
|
|
1640
|
+
setMapStyle(prevProps.mapStyle, props.mapStyle);
|
|
1641
|
+
}
|
|
1642
|
+
prevPropsRef.current.mapStyle = props.mapStyle;
|
|
1643
|
+
}, [props.mapStyle]);
|
|
1644
|
+
|
|
1645
|
+
// 切换地图矢量图和卫星图背景
|
|
1646
|
+
(0, _ahooks.useDeepCompareEffect)(function () {
|
|
1647
|
+
if (!gisRef.current) return;
|
|
1648
|
+
var prevProps = prevPropsRef.current;
|
|
1649
|
+
if (props.coverageType !== prevProps.coverageType) {
|
|
1650
|
+
setMapType(props.coverageType);
|
|
1651
|
+
}
|
|
1652
|
+
prevPropsRef.current.coverageType = props.coverageType;
|
|
1653
|
+
}, [props.coverageType]);
|
|
1654
|
+
|
|
1655
|
+
// 添加海量点
|
|
1656
|
+
(0, _ahooks.useDeepCompareEffect)(function () {
|
|
1657
|
+
if (!gisRef.current) return;
|
|
1658
|
+
var prevProps = prevPropsRef.current;
|
|
1659
|
+
if (props.mapPointCollection !== prevProps.mapPointCollection) {
|
|
1660
|
+
handlePointsCollectionChange(prevProps.mapPointCollection, props.mapPointCollection);
|
|
1661
|
+
}
|
|
1662
|
+
prevPropsRef.current.mapPointCollection = props.mapPointCollection;
|
|
1663
|
+
}, [props.mapPointCollection]);
|
|
1664
|
+
|
|
1665
|
+
// 点数据变化
|
|
1666
|
+
(0, _ahooks.useDeepCompareEffect)(function () {
|
|
1667
|
+
if (!gisRef.current) return;
|
|
1668
|
+
var prevProps = prevPropsRef.current;
|
|
1669
|
+
if (props.mapPoints !== prevProps.mapPoints) {
|
|
1670
|
+
handlePointsChange(prevProps.mapPoints, props.mapPoints);
|
|
1671
|
+
}
|
|
1672
|
+
prevPropsRef.current.mapPoints = props.mapPoints;
|
|
1673
|
+
}, [props.mapPoints]);
|
|
1674
|
+
// 线数据变化
|
|
1675
|
+
(0, _ahooks.useDeepCompareEffect)(function () {
|
|
1676
|
+
if (!gisRef.current) return;
|
|
1677
|
+
var prevProps = prevPropsRef.current;
|
|
1678
|
+
if (props.mapLines !== prevProps.mapLines) {
|
|
1679
|
+
handleLinesChange(prevProps.mapLines, props.mapLines);
|
|
1680
|
+
}
|
|
1681
|
+
prevPropsRef.current.mapLines = props.mapLines;
|
|
1682
|
+
}, [props.mapLines]);
|
|
1683
|
+
// 面数据变化
|
|
1684
|
+
(0, _ahooks.useDeepCompareEffect)(function () {
|
|
1685
|
+
if (!gisRef.current) return;
|
|
1686
|
+
var prevProps = prevPropsRef.current;
|
|
1687
|
+
if (props.mapPolygons !== prevProps.mapPolygons) {
|
|
1688
|
+
handlePolygonsChange(prevProps.mapPolygons, props.mapPolygons);
|
|
1689
|
+
}
|
|
1690
|
+
prevPropsRef.current.mapPolygons = props.mapPolygons;
|
|
1691
|
+
}, [props.mapPolygons]);
|
|
1692
|
+
// 圆数据变化
|
|
1693
|
+
(0, _ahooks.useDeepCompareEffect)(function () {
|
|
1694
|
+
if (!gisRef.current) return;
|
|
1695
|
+
var prevProps = prevPropsRef.current;
|
|
1696
|
+
if (props.mapCircles !== prevProps.mapCircles) {
|
|
1697
|
+
handleCirclesChange(prevProps.mapCircles, props.mapCircles);
|
|
1698
|
+
}
|
|
1699
|
+
prevPropsRef.current.mapCircles = props.mapCircles;
|
|
1700
|
+
}, [props.mapCircles]);
|
|
1701
|
+
|
|
1702
|
+
// 渲染
|
|
1703
|
+
return /*#__PURE__*/(0, _jsxRuntime.jsx)("div", {
|
|
1704
|
+
id: props.mapId,
|
|
1705
|
+
ref: mapRef,
|
|
1706
|
+
style: {
|
|
1707
|
+
width: "100%",
|
|
1708
|
+
height: "100%"
|
|
1709
|
+
}
|
|
1710
|
+
});
|
|
1711
|
+
}
|
|
1712
|
+
var _default = exports.default = BaiduMap;
|