@deepinnet-components/pc 0.0.53 → 0.0.54

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -15,7 +15,9 @@ function _iterableToArrayLimit(r, l) { var t = null == r ? null : "undefined" !=
15
15
  function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
16
16
  // @ts-nocheck
17
17
  import { useEffect, useRef, useState } from 'react';
18
+ import arrowImg from "../demo/imgs/\u7BAD\u5934\u65B9\u5411.png";
18
19
  import "../index.less";
20
+ import { getBase64FromLocalImage } from "../utils";
19
21
  var Map = function Map(props) {
20
22
  var id = props.id,
21
23
  _props$opts = props.opts,
@@ -96,6 +98,26 @@ var Map = function Map(props) {
96
98
  if (props.onRightClick) {
97
99
  map === null || map === void 0 || map.on('contextmenu', mapRightClick);
98
100
  }
101
+ _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee2() {
102
+ var base64, image;
103
+ return _regeneratorRuntime().wrap(function _callee2$(_context2) {
104
+ while (1) switch (_context2.prev = _context2.next) {
105
+ case 0:
106
+ _context2.next = 2;
107
+ return getBase64FromLocalImage(arrowImg);
108
+ case 2:
109
+ base64 = _context2.sent;
110
+ _context2.next = 5;
111
+ return map.loadImage(base64);
112
+ case 5:
113
+ image = _context2.sent;
114
+ map.addImage('custom-arrow', image.data);
115
+ case 7:
116
+ case "end":
117
+ return _context2.stop();
118
+ }
119
+ }, _callee2);
120
+ }))();
99
121
  }
100
122
  }, [map]);
101
123
  return /*#__PURE__*/React.createElement("div", {
@@ -164,23 +164,25 @@ var MapPolyline = function MapPolyline(props) {
164
164
  obj[item.id] = (_item$metadata = item.metadata) === null || _item$metadata === void 0 ? void 0 : _item$metadata.zIndex;
165
165
  });
166
166
  var fKey = findKeyWithMinValueGreaterThan(obj, zIndex, [id]);
167
- if (fKey) {
168
- map.moveLayer(id, fKey);
169
- if (getOutline()) {
170
- map.moveLayer(outlineId, fKey);
171
- }
172
- if (getArrowLine()) {
173
- map.moveLayer(allowLayerId, fKey);
174
- }
175
- } else {
176
- map.moveLayer(id);
177
- if (getOutline()) {
178
- map.moveLayer(outlineId);
179
- }
180
- if (getArrowLine()) {
181
- map.moveLayer(allowLayerId);
167
+ try {
168
+ if (fKey) {
169
+ map.moveLayer(id, fKey);
170
+ if (getOutline()) {
171
+ map.moveLayer(outlineId, fKey);
172
+ }
173
+ if (getArrowLine()) {
174
+ map.moveLayer(allowLayerId, fKey);
175
+ }
176
+ } else {
177
+ map.moveLayer(id);
178
+ if (getOutline()) {
179
+ map.moveLayer(outlineId);
180
+ }
181
+ if (getArrowLine()) {
182
+ map.moveLayer(allowLayerId);
183
+ }
182
184
  }
183
- }
185
+ } catch (error) {}
184
186
  }
185
187
  }, [zIndex, map, line]);
186
188
  useEffect(function () {
@@ -209,7 +211,8 @@ var MapPolyline = function MapPolyline(props) {
209
211
  },
210
212
  zIndex: zIndex,
211
213
  metadata: {
212
- zIndex: zIndex
214
+ zIndex: zIndex,
215
+ isArrow: isArrow
213
216
  }
214
217
  };
215
218
  if (multi && isGetColor) {
@@ -229,10 +232,9 @@ var MapPolyline = function MapPolyline(props) {
229
232
  map.setPaintProperty(id, 'line-color', lineColor);
230
233
  map.setPaintProperty(id, 'line-width', width);
231
234
  map.setPaintProperty(id, 'line-opacity', opacity);
232
- } else {
233
- // console.log('添加layer')
234
- map.addLayer(lineObj);
235
235
  if (isArrow) {
236
+ var arrowLayer = map.getLayer(allowLayerId);
237
+ if (arrowLayer) return;
236
238
  var arrowLineObj = {
237
239
  id: allowLayerId,
238
240
  type: 'symbol',
@@ -251,6 +253,34 @@ var MapPolyline = function MapPolyline(props) {
251
253
  };
252
254
  map.addLayer(arrowLineObj);
253
255
  setArrowLine(arrowLineObj);
256
+ } else {
257
+ var _arrowLayer = map.getLayer(allowLayerId);
258
+ if (_arrowLayer) {
259
+ map === null || map === void 0 || map.removeLayer(allowLayerId);
260
+ }
261
+ }
262
+ } else {
263
+ // console.log('添加layer')
264
+ map.addLayer(lineObj);
265
+ if (isArrow) {
266
+ var _arrowLineObj = {
267
+ id: allowLayerId,
268
+ type: 'symbol',
269
+ source: id,
270
+ layout: {
271
+ 'icon-image': arrowConfig.img || 'custom-arrow',
272
+ // 箭头图标
273
+ 'symbol-placement': 'line',
274
+ 'symbol-spacing': arrowConfig.spacing || 25,
275
+ // 图标间隔,默认为250
276
+ 'icon-size': arrowConfig.size || 1
277
+ },
278
+ metadata: {
279
+ zIndex: zIndex
280
+ }
281
+ };
282
+ map.addLayer(_arrowLineObj);
283
+ setArrowLine(_arrowLineObj);
254
284
  }
255
285
  }
256
286
  setLine(deepClone(lineObj));
@@ -302,7 +332,7 @@ var MapPolyline = function MapPolyline(props) {
302
332
  if (!map || !sourceData) return;
303
333
  drawLine();
304
334
  drawOutLine();
305
- }, [map, sourceData, color, width, opacity, isOutline]);
335
+ }, [map, sourceData, color, width, opacity, isOutline, isArrow]);
306
336
  var flagRef = useRef(false);
307
337
  function onMouseenter(e) {
308
338
  if (flagRef.current) return;
@@ -328,7 +358,7 @@ var MapPolyline = function MapPolyline(props) {
328
358
  var _e$originalEvent, _e$originalEvent$stop;
329
359
  (_e$originalEvent = e.originalEvent) === null || _e$originalEvent === void 0 || (_e$originalEvent$stop = _e$originalEvent.stopPropagation) === null || _e$originalEvent$stop === void 0 || _e$originalEvent$stop.call(_e$originalEvent);
330
360
  var features = map.queryRenderedFeatures(e.point);
331
- console.log(features);
361
+ // console.log(features);
332
362
  if (!features.length) return;
333
363
  var item = features.find(function (item) {
334
364
  return item.source.includes('customPolyline::');
@@ -61,8 +61,7 @@ var App = function App() {
61
61
  color: '#f00',
62
62
  onClick: function onClick(feature, e) {
63
63
  console.log(feature, e);
64
- },
65
- isArrow: true
64
+ }
66
65
  }), /*#__PURE__*/React.createElement(MapPolyline, {
67
66
  map: map,
68
67
  path: path2,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@deepinnet-components/pc",
3
- "version": "0.0.53",
3
+ "version": "0.0.54",
4
4
  "description": "A react library developed with dumi",
5
5
  "license": "MIT",
6
6
  "module": "dist/index.js",