@wenle_2523097/agri-map 1.0.0

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.en.md ADDED
@@ -0,0 +1,36 @@
1
+ # agri-map
2
+
3
+ #### Description
4
+ 农业地图组件库 - 基于React-Leaflet的农业专用地图组件
5
+
6
+ #### Software Architecture
7
+ Software architecture description
8
+
9
+ #### Installation
10
+
11
+ 1. xxxx
12
+ 2. xxxx
13
+ 3. xxxx
14
+
15
+ #### Instructions
16
+
17
+ 1. xxxx
18
+ 2. xxxx
19
+ 3. xxxx
20
+
21
+ #### Contribution
22
+
23
+ 1. Fork the repository
24
+ 2. Create Feat_xxx branch
25
+ 3. Commit your code
26
+ 4. Create Pull Request
27
+
28
+
29
+ #### Gitee Feature
30
+
31
+ 1. You can use Readme\_XXX.md to support different languages, such as Readme\_en.md, Readme\_zh.md
32
+ 2. Gitee blog [blog.gitee.com](https://blog.gitee.com)
33
+ 3. Explore open source project [https://gitee.com/explore](https://gitee.com/explore)
34
+ 4. The most valuable open source project [GVP](https://gitee.com/gvp)
35
+ 5. The manual of Gitee [https://gitee.com/help](https://gitee.com/help)
36
+ 6. The most popular members [https://gitee.com/gitee-stars/](https://gitee.com/gitee-stars/)
package/README.md ADDED
@@ -0,0 +1,407 @@
1
+ # agri-map-components
2
+
3
+ 基于 React-Leaflet 的农业专用地图组件库,提供地块管理、标注点、道路、灌溉渠等农业场景常用组件。
4
+
5
+ ## 特性
6
+
7
+ - 🗺️ **地块管理** - 支持大规模地块数据渲染,提供绘制、剪辑、移动等编辑功能
8
+ - 📍 **标注点** - 多种预设图标,支持自定义 SVG 图标,提供新建、移动、删除编辑模式
9
+ - 🛤️ **道路绘制** - 田间道路绘制与管理,支持距离显示
10
+ - 💧 **灌溉渠** - 灌溉渠绘制与流向箭头显示
11
+ - 🌍 **天地图** - 内置天地图图层支持
12
+ - 📐 **双向标尺** - 地图比例尺组件
13
+ - ⚡ **高性能** - 支持上万条地块数据渲染
14
+
15
+ ## 安装
16
+
17
+ ```bash
18
+ npm install agri-map
19
+ # 或
20
+ yarn add agri-map
21
+ ```
22
+
23
+ ## 依赖
24
+
25
+ 确保项目已安装以下 peerDependencies:
26
+
27
+ ```bash
28
+ npm install leaflet react react-dom react-leaflet
29
+ ```
30
+
31
+ ## 快速开始
32
+
33
+ ```tsx
34
+ import { MapContainer } from 'react-leaflet';
35
+ import { TianDiTuLayer, PlotLayer, Marker } from 'agri-map';
36
+ import 'leaflet/dist/leaflet.css';
37
+ import 'agri-map/dist/index.css';
38
+
39
+ function App() {
40
+ const plotData = [
41
+ {
42
+ id: 1,
43
+ name: '地块A',
44
+ type: 'farmland',
45
+ status: 'planting',
46
+ boundaries: [[30.0, 120.0], [30.0, 120.1], [30.1, 120.1], [30.1, 120.0]],
47
+ area: 1000,
48
+ crop: '水稻',
49
+ },
50
+ ];
51
+
52
+ const markers = [
53
+ { id: 1, position: [30.05, 120.05], title: '标注点1' },
54
+ ];
55
+
56
+ return (
57
+ <MapContainer center={[30.0, 120.0]} zoom={12} style={{ height: '100vh' }}>
58
+ <TianDiTuLayer apiKey="your-tianditu-key" />
59
+ <PlotLayer dataSource={plotData} />
60
+ <Marker dataSource={markers} />
61
+ </MapContainer>
62
+ );
63
+ }
64
+ ```
65
+
66
+ ## 组件列表
67
+
68
+ ### PlotLayer 地块图层
69
+
70
+ 高性能地块渲染组件,支持大规模数据。
71
+
72
+ ```tsx
73
+ import { PlotLayer, PlotData } from 'agri-map';
74
+
75
+ const plots: PlotData[] = [
76
+ {
77
+ id: 'plot-1',
78
+ name: '农田A',
79
+ type: 'farmland',
80
+ status: 'planting',
81
+ boundaries: [[30.0, 120.0], [30.0, 120.1], [30.1, 120.1], [30.1, 120.0]],
82
+ area: 1000,
83
+ crop: '水稻',
84
+ },
85
+ ];
86
+
87
+ <PlotLayer
88
+ dataSource={plots}
89
+ onClick={(data, layer) => console.log('点击地块:', data)}
90
+ onContextMenu={(data, layer, e) => console.log('右键菜单:', data)}
91
+ style={(data) => ({
92
+ color: data.status === 'planting' ? '#4CAF50' : '#9E9E9E',
93
+ fillColor: data.status === 'planting' ? '#81C784' : '#BDBDBD',
94
+ fillOpacity: 0.6,
95
+ })}
96
+ editMode={['create', 'delete']}
97
+ onCreate={(result) => console.log('新建地块:', result)}
98
+ onDelete={(result) => console.log('删除地块:', result)}
99
+ showLabel={true}
100
+ labelFields={['name', 'area']}
101
+ />
102
+ ```
103
+
104
+ #### PlotLayer Props
105
+
106
+ | 属性 | 类型 | 默认值 | 说明 |
107
+ |------|------|--------|------|
108
+ | `dataSource` | `PlotData[]` | `[]` | 地块数据数组 |
109
+ | `onClick` | `(data, layer) => void` | - | 点击回调 |
110
+ | `onContextMenu` | `(data, layer, event) => void` | - | 右键菜单回调 |
111
+ | `style` | `(data) => PlotStyle` | - | 动态样式函数 |
112
+ | `path` | `PathOptions` | - | 默认路径样式 |
113
+ | `selectedPath` | `PathOptions` | - | 选中样式 |
114
+ | `editMode` | `boolean \| string[]` | `false` | 编辑模式 |
115
+ | `onCreate` | `(result) => void` | - | 新建回调 |
116
+ | `onRedraw` | `(result) => void` | - | 重绘回调 |
117
+ | `onClip` | `(result) => void` | - | 剪辑回调 |
118
+ | `onMove` | `(result) => void` | - | 移动回调 |
119
+ | `onDelete` | `(result) => void` | - | 删除回调 |
120
+ | `showLabel` | `boolean \| 'all'` | `false` | 显示标签 |
121
+ | `labelFields` | `string[]` | `['name']` | 标签字段 |
122
+
123
+ ---
124
+
125
+ ### Marker 标注点
126
+
127
+ 地图标注点组件,支持多种图标和编辑功能。
128
+
129
+ ```tsx
130
+ import { Marker, MarkerData } from 'agri-map';
131
+
132
+ const markers: MarkerData[] = [
133
+ { id: 1, position: [30.0, 120.0], title: '标注点1', description: '描述信息' },
134
+ { id: 2, position: [30.1, 120.1], title: '标注点2', icon: 'drone' },
135
+ ];
136
+
137
+ <Marker
138
+ dataSource={markers}
139
+ icon="point"
140
+ iconSize={[48, 48]}
141
+ animated={false}
142
+ onClick={(item) => console.log('点击:', item)}
143
+ editMode={['create', 'move', 'delete']}
144
+ onCreate={(result) => console.log('新建:', result)}
145
+ />
146
+ ```
147
+
148
+ #### 预设图标
149
+
150
+ - `point` - 默认点位图标
151
+ - `position` - 定位图标
152
+ - `position-red` - 红色定位图标
153
+ - `drone` - 无人机图标
154
+ - `down` - 下载图标
155
+ - `marker-red/blue/green/orange/yellow` - 彩色标记图标
156
+
157
+ #### 自定义 SVG 图标
158
+
159
+ ```tsx
160
+ // 使用 SVG 字符串
161
+ <Marker svgIcon="<svg>...</svg>" />
162
+
163
+ // 使用 SVG 配置对象
164
+ <Marker svgIcon={{
165
+ path: 'M12 2C8.13 2 5 5.13 5 9c0 5.25 7 13 7 13s7-7.75 7-13c0-3.87-3.13-7-7-7z',
166
+ viewBox: '0 0 24 24',
167
+ fill: '#e53935',
168
+ }} />
169
+
170
+ // 使用远程图标 URL
171
+ <Marker icon="https://example.com/icon.png" />
172
+ ```
173
+
174
+ #### Marker Props
175
+
176
+ | 属性 | 类型 | 默认值 | 说明 |
177
+ |------|------|--------|------|
178
+ | `dataSource` | `MarkerData[]` | `[]` | 标注数据 |
179
+ | `icon` | `string \| SvgIconConfig` | `'point'` | 图标类型 |
180
+ | `iconSize` | `[number, number]` | `[48, 48]` | 图标尺寸 |
181
+ | `animated` | `boolean` | `false` | 是否动画 |
182
+ | `permanent` | `boolean` | `false` | 永久显示提示 |
183
+ | `editMode` | `boolean \| string[]` | `false` | 编辑模式 |
184
+ | `onCreate` | `(result) => void` | - | 新建回调 |
185
+ | `onMove` | `(result) => void` | - | 移动回调 |
186
+ | `onDelete` | `(result) => void` | - | 删除回调 |
187
+
188
+ ---
189
+
190
+ ### Road 道路组件
191
+
192
+ 田间道路绘制与管理组件。
193
+
194
+ ```tsx
195
+ import { Road, RoadData } from 'agri-map';
196
+
197
+ const roads: RoadData[] = [
198
+ {
199
+ id: 1,
200
+ name: '田间道1号',
201
+ points: [[30.0, 120.0], [30.1, 120.1], [30.2, 120.2]],
202
+ },
203
+ ];
204
+
205
+ <Road
206
+ dataSource={roads}
207
+ path={{ color: '#795548', weight: 3 }}
208
+ showDistance={true}
209
+ editMode={['create', 'edit', 'delete']}
210
+ onCreate={(result) => console.log('新建道路:', result)}
211
+ />
212
+ ```
213
+
214
+ #### Road Props
215
+
216
+ | 属性 | 类型 | 默认值 | 说明 |
217
+ |------|------|--------|------|
218
+ | `dataSource` | `RoadData[]` | `[]` | 道路数据 |
219
+ | `path` | `PathOptions` | - | 路径样式 |
220
+ | `showDistance` | `boolean` | `false` | 显示距离 |
221
+ | `editMode` | `boolean \| string[]` | `false` | 编辑模式 |
222
+
223
+ ---
224
+
225
+ ### Irrigation 灌溉渠组件
226
+
227
+ 灌溉渠绘制与流向显示组件。
228
+
229
+ ```tsx
230
+ import { Irrigation, IrrigationData } from 'agri-map';
231
+
232
+ const channels: IrrigationData[] = [
233
+ {
234
+ id: 1,
235
+ name: '主干渠',
236
+ points: [[30.0, 120.0], [30.1, 120.1]],
237
+ inlet: true,
238
+ outlet: false,
239
+ },
240
+ ];
241
+
242
+ <Irrigation
243
+ dataSource={channels}
244
+ path={{ color: '#2196F3', weight: 4 }}
245
+ editMode={['create', 'edit', 'delete', 'reverse']}
246
+ onCreate={(result) => console.log('新建渠道:', result)}
247
+ onReverse={(result) => console.log('反转流向:', result)}
248
+ />
249
+ ```
250
+
251
+ #### Irrigation Props
252
+
253
+ | 属性 | 类型 | 默认值 | 说明 |
254
+ |------|------|--------|------|
255
+ | `dataSource` | `IrrigationData[]` | `[]` | 灌溉渠数据 |
256
+ | `path` | `PathOptions` | - | 路径样式 |
257
+ | `editMode` | `boolean \| string[]` | `false` | 编辑模式 |
258
+ | `onReverse` | `(result) => void` | - | 反转流向回调 |
259
+
260
+ ---
261
+
262
+ ### TianDiTuLayer 天地图图层
263
+
264
+ 天地图底图组件。
265
+
266
+ ```tsx
267
+ import { TianDiTuLayer, LAYER_TYPES } from 'agri-map';
268
+
269
+ // 矢量底图 + 标注
270
+ <TianDiTuLayer
271
+ apiKey="your-tianditu-key"
272
+ layerType="vector"
273
+ showAnnotation={true}
274
+ />
275
+
276
+ // 卫星影像
277
+ <TianDiTuLayer
278
+ apiKey="your-tianditu-key"
279
+ layerType="satellite"
280
+ />
281
+
282
+ // 地形图
283
+ <TianDiTuLayer
284
+ apiKey="your-tianditu-key"
285
+ layerType="terrain"
286
+ />
287
+
288
+ // 自定义叠加层
289
+ <TianDiTuLayer
290
+ apiKey="your-tianditu-key"
291
+ overlayUrl="https://your-server.com/overlay/{z}/{x}/{y}.png"
292
+ overlayOpacity={0.5}
293
+ />
294
+ ```
295
+
296
+ #### TianDiTuLayer Props
297
+
298
+ | 属性 | 类型 | 默认值 | 说明 |
299
+ |------|------|--------|------|
300
+ | `apiKey` | `string` | - | 天地图 API Key(必填) |
301
+ | `layerType` | `'vector' \| 'satellite' \| 'terrain'` | `'vector'` | 图层类型 |
302
+ | `showAnnotation` | `boolean` | `true` | 显示标注 |
303
+ | `overlayUrl` | `string` | - | 叠加瓦片 URL |
304
+ | `overlayOpacity` | `number` | `1` | 叠加层透明度 |
305
+
306
+ ---
307
+
308
+ ### DualScaleControl 双向标尺
309
+
310
+ 地图比例尺组件,缩放控件固定在左下角。
311
+
312
+ ```tsx
313
+ import { DualScaleControl } from 'agri-map';
314
+
315
+ <DualScaleControl
316
+ metric={true}
317
+ imperial={false}
318
+ showZoomControl={true}
319
+ theme="light"
320
+ />
321
+ ```
322
+
323
+ ---
324
+
325
+ ### ConfigProvider 全局配置
326
+
327
+ 提供主题等全局配置。
328
+
329
+ ```tsx
330
+ import { ConfigProvider } from 'agri-map';
331
+
332
+ <ConfigProvider theme="dark">
333
+ <MapContainer>...</MapContainer>
334
+ </ConfigProvider>
335
+ ```
336
+
337
+ ---
338
+
339
+ ### Icons 图标组件
340
+
341
+ 内置 SVG 图标组件库。
342
+
343
+ ```tsx
344
+ import {
345
+ Icons,
346
+ RedrawIcon,
347
+ ClipIcon,
348
+ MoveIcon,
349
+ DeleteIcon,
350
+ CancelIcon,
351
+ SaveIcon,
352
+ CreateIcon
353
+ } from 'agri-map';
354
+
355
+ // 使用方式一
356
+ <CreateIcon />
357
+
358
+ // 使用方式二
359
+ <Icons.Create />
360
+ ```
361
+
362
+ ## 类型定义
363
+
364
+ ```typescript
365
+ // 坐标点 [lat, lng]
366
+ type Coordinate = [number, number];
367
+
368
+ // 地块类型
369
+ type PlotType = 'farmland' | 'vegetable' | 'orchard' | 'forest' | 'grassland' | 'paddy' | 'greenhouse';
370
+
371
+ // 地块状态
372
+ type PlotStatus = 'cultivating' | 'fallow' | 'harvesting' | 'planting' | 'irrigating';
373
+
374
+ // 编辑模式
375
+ type PlotEditMode = 'idle' | 'redraw' | 'clip' | 'move' | 'create';
376
+
377
+ // 路径样式
378
+ interface PathOptions {
379
+ color?: string;
380
+ fillColor?: string;
381
+ weight?: number;
382
+ opacity?: number;
383
+ fillOpacity?: number;
384
+ dashArray?: string | number[];
385
+ className?: string;
386
+ }
387
+ ```
388
+
389
+ ## 开发
390
+
391
+ ```bash
392
+ # 安装依赖
393
+ npm install
394
+
395
+ # 开发模式
396
+ npm run dev
397
+
398
+ # 构建
399
+ npm run build
400
+
401
+ # 类型检查
402
+ npm run type-check
403
+ ```
404
+
405
+ ## 许可证
406
+
407
+ MIT
Binary file
Binary file
Binary file
Binary file