@deepinnet-components/pc 0.0.51 → 0.0.53

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.
@@ -50,6 +50,12 @@ var MapPolyline = function MapPolyline(props) {
50
50
  zIndex = _props$zIndex === void 0 ? 12 : _props$zIndex,
51
51
  _props$isArrow = props.isArrow,
52
52
  isArrow = _props$isArrow === void 0 ? false : _props$isArrow,
53
+ _props$arrowConfig = props.arrowConfig,
54
+ arrowConfig = _props$arrowConfig === void 0 ? {
55
+ img: 'custom-arrow',
56
+ spacing: 25,
57
+ size: 1
58
+ } : _props$arrowConfig,
53
59
  _props$multi = props.multi,
54
60
  multi = _props$multi === void 0 ? false : _props$multi,
55
61
  _props$isGetColor = props.isGetColor,
@@ -232,12 +238,12 @@ var MapPolyline = function MapPolyline(props) {
232
238
  type: 'symbol',
233
239
  source: id,
234
240
  layout: {
235
- 'icon-image': 'custom-arrow',
241
+ 'icon-image': arrowConfig.img || 'custom-arrow',
236
242
  // 箭头图标
237
243
  'symbol-placement': 'line',
238
- 'symbol-spacing': 25,
244
+ 'symbol-spacing': arrowConfig.spacing || 25,
239
245
  // 图标间隔,默认为250
240
- 'icon-size': 1
246
+ 'icon-size': arrowConfig.size || 1
241
247
  },
242
248
  metadata: {
243
249
  zIndex: zIndex
Binary file
@@ -61,7 +61,8 @@ var App = function App() {
61
61
  color: '#f00',
62
62
  onClick: function onClick(feature, e) {
63
63
  console.log(feature, e);
64
- }
64
+ },
65
+ isArrow: true
65
66
  }), /*#__PURE__*/React.createElement(MapPolyline, {
66
67
  map: map,
67
68
  path: path2,
@@ -0,0 +1,3 @@
1
+ import React from 'react';
2
+ declare const App: () => React.JSX.Element;
3
+ export default App;
@@ -0,0 +1,168 @@
1
+ function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); }
2
+ 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."); }
3
+ 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); }
4
+ 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; }
5
+ 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; } }
6
+ function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
7
+ import { Map2D } from "../../..";
8
+ import { Button, message } from 'antd';
9
+ import React, { useEffect, useState } from 'react';
10
+ var Map = Map2D.Map,
11
+ MapMarker = Map2D.MapMarker,
12
+ MapPolygon = Map2D.MapPolygon,
13
+ Utils = Map2D.Utils;
14
+ var App = function App() {
15
+ var _useState = useState('map' + Math.random()),
16
+ _useState2 = _slicedToArray(_useState, 1),
17
+ mapId = _useState2[0];
18
+ var _useState3 = useState(),
19
+ _useState4 = _slicedToArray(_useState3, 2),
20
+ map = _useState4[0],
21
+ setMap = _useState4[1];
22
+ var _useState5 = useState(),
23
+ _useState6 = _slicedToArray(_useState5, 2),
24
+ polygon1 = _useState6[0],
25
+ setPolygon1 = _useState6[1];
26
+ var _useState7 = useState({}),
27
+ _useState8 = _slicedToArray(_useState7, 2),
28
+ polygon1Center = _useState8[0],
29
+ setPolygon1Center = _useState8[1];
30
+ useEffect(function () {
31
+ var polygon1 = [[118.822923, 28.985346], [118.832193, 28.985271], [118.832107, 28.976862], [118.823266, 28.977087], [118.822923, 28.985346]];
32
+ setPolygon1(polygon1);
33
+ setPolygon1Center({
34
+ centroid: Utils.getPolygonCenter(polygon1, 'centroid'),
35
+ center: Utils.getPolygonCenter(polygon1, 'center'),
36
+ centerOfMass: Utils.getPolygonCenter(polygon1, 'centerOfMass')
37
+ });
38
+ }, []);
39
+ var _useState9 = useState(),
40
+ _useState10 = _slicedToArray(_useState9, 2),
41
+ polygon2 = _useState10[0],
42
+ setPolygon2 = _useState10[1];
43
+ var _useState11 = useState({}),
44
+ _useState12 = _slicedToArray(_useState11, 2),
45
+ polygon2Center = _useState12[0],
46
+ setPolygon2Center = _useState12[1];
47
+ useEffect(function () {
48
+ var polygon2 = [[118.862233, 28.982493], [118.873477, 28.982793], [118.883176, 28.982643], [118.889356, 28.979114], [118.889442, 28.976636], [118.888498, 28.965823], [118.886609, 28.961543], [118.877425, 28.960792], [118.861289, 28.960792], [118.870902, 28.96312], [118.879056, 28.963571], [118.882919, 28.973408], [118.882404, 28.978589], [118.872361, 28.980315], [118.862233, 28.982493]];
49
+ setPolygon2(polygon2);
50
+ setPolygon2Center({
51
+ centroid: Utils.getPolygonCenter(polygon2, 'centroid'),
52
+ pointOnFeature: Utils.getPolygonCenter(polygon2, 'pointOnFeature'),
53
+ centerOfMass: Utils.getPolygonCenter(polygon2, 'centerOfMass')
54
+ });
55
+ }, []);
56
+ var _useState13 = useState(false),
57
+ _useState14 = _slicedToArray(_useState13, 2),
58
+ show = _useState14[0],
59
+ setShow = _useState14[1]; // 这是测试代码
60
+
61
+ if (!show) {
62
+ return /*#__PURE__*/React.createElement(Button, {
63
+ onClick: function onClick() {
64
+ setShow(true);
65
+ }
66
+ }, "\u5C55\u793A\u6848\u4F8B");
67
+ }
68
+ return /*#__PURE__*/React.createElement("div", null, /*#__PURE__*/React.createElement("div", {
69
+ style: {
70
+ width: '100%',
71
+ height: 500
72
+ }
73
+ }, /*#__PURE__*/React.createElement(Map, {
74
+ setMap: setMap,
75
+ id: mapId
76
+ // onClick={(e: any) => {
77
+ // console.log([
78
+ // Number(e.lngLat.lng.toFixed(6)),
79
+ // Number(e.lngLat.lat.toFixed(6)),
80
+ // ]);
81
+ // }}
82
+ }), !!map && /*#__PURE__*/React.createElement(React.Fragment, null, /*#__PURE__*/React.createElement(MapPolygon, {
83
+ map: map,
84
+ path: polygon1
85
+ }), /*#__PURE__*/React.createElement(MapMarker, {
86
+ map: map,
87
+ position: polygon1Center.centroid
88
+ }, /*#__PURE__*/React.createElement("div", {
89
+ style: {
90
+ width: 4,
91
+ height: 4,
92
+ background: '#f00',
93
+ borderRadius: '50%'
94
+ },
95
+ onClick: function onClick() {
96
+ message.info('centroid中心');
97
+ }
98
+ })), /*#__PURE__*/React.createElement(MapMarker, {
99
+ map: map,
100
+ position: polygon1Center.center
101
+ }, /*#__PURE__*/React.createElement("div", {
102
+ style: {
103
+ width: 4,
104
+ height: 4,
105
+ background: '#f00',
106
+ borderRadius: '50%'
107
+ },
108
+ onClick: function onClick() {
109
+ message.info('center中心');
110
+ }
111
+ })), /*#__PURE__*/React.createElement(MapMarker, {
112
+ map: map,
113
+ position: polygon1Center.centerOfMass
114
+ }, /*#__PURE__*/React.createElement("div", {
115
+ style: {
116
+ width: 4,
117
+ height: 4,
118
+ background: '#f00',
119
+ borderRadius: '50%'
120
+ },
121
+ onClick: function onClick() {
122
+ message.info('centerOfMass中心');
123
+ }
124
+ })), /*#__PURE__*/React.createElement(MapPolygon, {
125
+ map: map,
126
+ path: polygon2
127
+ }), /*#__PURE__*/React.createElement(MapMarker, {
128
+ map: map,
129
+ position: polygon2Center.centroid
130
+ }, /*#__PURE__*/React.createElement("div", {
131
+ style: {
132
+ width: 4,
133
+ height: 4,
134
+ background: '#f00',
135
+ borderRadius: '50%'
136
+ },
137
+ onClick: function onClick() {
138
+ message.info('centroid中心');
139
+ }
140
+ })), /*#__PURE__*/React.createElement(MapMarker, {
141
+ map: map,
142
+ position: polygon2Center.pointOnFeature
143
+ }, /*#__PURE__*/React.createElement("div", {
144
+ style: {
145
+ width: 4,
146
+ height: 4,
147
+ background: '#f00',
148
+ borderRadius: '50%'
149
+ },
150
+ onClick: function onClick() {
151
+ message.info('pointOnFeature中心');
152
+ }
153
+ })), /*#__PURE__*/React.createElement(MapMarker, {
154
+ map: map,
155
+ position: polygon2Center.centerOfMass
156
+ }, /*#__PURE__*/React.createElement("div", {
157
+ style: {
158
+ width: 4,
159
+ height: 4,
160
+ background: '#f00',
161
+ borderRadius: '50%'
162
+ },
163
+ onClick: function onClick() {
164
+ message.info('centerOfMass中心');
165
+ }
166
+ })))));
167
+ };
168
+ export default App;
@@ -10,3 +10,4 @@ export declare const deepClone: (obj: any) => any;
10
10
  export declare const getBase64FromLocalImage: (url: any) => Promise<unknown>;
11
11
  export declare const getPolylineLength: (params: any) => number | Error;
12
12
  export declare const getPolygonArea: (params: any) => number | Error;
13
+ export declare const getPolygonCenter: (params: any, type?: string) => any;
@@ -309,4 +309,19 @@ export var getPolygonArea = function getPolygonArea(params) {
309
309
  return _area;
310
310
  }
311
311
  return new Error('参数错误');
312
+ };
313
+
314
+ // 计算面的中心点
315
+ export var getPolygonCenter = function getPolygonCenter(params) {
316
+ var type = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 'centroid';
317
+ var turfPolygon;
318
+ if (Array.isArray(params)) {
319
+ turfPolygon = turf.polygon([params]);
320
+ }
321
+ if (typeof params === 'string' && params.startsWith('POLYGON')) {
322
+ var geojson = wellknown.parse(params);
323
+ var path = geojson.coordinates[0];
324
+ turfPolygon = turf.polygon([path]);
325
+ }
326
+ return turf[type](turfPolygon).geometry.coordinates;
312
327
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@deepinnet-components/pc",
3
- "version": "0.0.51",
3
+ "version": "0.0.53",
4
4
  "description": "A react library developed with dumi",
5
5
  "license": "MIT",
6
6
  "module": "dist/index.js",