@deepinnet-components/pc 0.0.53 → 0.0.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.
@@ -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,35 @@ 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
+ setArrowLine(undefined);
262
+ }
263
+ } else {
264
+ // console.log('添加layer')
265
+ map.addLayer(lineObj);
266
+ if (isArrow) {
267
+ var _arrowLineObj = {
268
+ id: allowLayerId,
269
+ type: 'symbol',
270
+ source: id,
271
+ layout: {
272
+ 'icon-image': arrowConfig.img || 'custom-arrow',
273
+ // 箭头图标
274
+ 'symbol-placement': 'line',
275
+ 'symbol-spacing': arrowConfig.spacing || 25,
276
+ // 图标间隔,默认为250
277
+ 'icon-size': arrowConfig.size || 1
278
+ },
279
+ metadata: {
280
+ zIndex: zIndex
281
+ }
282
+ };
283
+ map.addLayer(_arrowLineObj);
284
+ setArrowLine(_arrowLineObj);
254
285
  }
255
286
  }
256
287
  setLine(deepClone(lineObj));
@@ -289,20 +320,21 @@ var MapPolyline = function MapPolyline(props) {
289
320
  map.addLayer(outlineObj);
290
321
  map.moveLayer(outlineId, id);
291
322
  }
323
+ setOutline(outlineObj);
292
324
  } else {
293
325
  var _layer = map.getLayer(outlineId);
294
326
  if (_layer) {
295
327
  // console.log('删除outline')
296
328
  map === null || map === void 0 || map.removeLayerAndSource(outlineId);
297
329
  }
330
+ setOutline(undefined);
298
331
  }
299
- setOutline(outlineObj);
300
332
  }
301
333
  useEffect(function () {
302
334
  if (!map || !sourceData) return;
303
335
  drawLine();
304
336
  drawOutLine();
305
- }, [map, sourceData, color, width, opacity, isOutline]);
337
+ }, [map, sourceData, color, width, opacity, isOutline, isArrow]);
306
338
  var flagRef = useRef(false);
307
339
  function onMouseenter(e) {
308
340
  if (flagRef.current) return;
@@ -328,7 +360,7 @@ var MapPolyline = function MapPolyline(props) {
328
360
  var _e$originalEvent, _e$originalEvent$stop;
329
361
  (_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
362
  var features = map.queryRenderedFeatures(e.point);
331
- console.log(features);
363
+ // console.log(features);
332
364
  if (!features.length) return;
333
365
  var item = features.find(function (item) {
334
366
  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.55",
4
4
  "description": "A react library developed with dumi",
5
5
  "license": "MIT",
6
6
  "module": "dist/index.js",