@sword916/vae-map-plus 1.0.0 → 1.0.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.
Files changed (185) hide show
  1. package/lib/index.js +5376 -0
  2. package/lib/style.css +1 -0
  3. package/lib/vae-amap/favicon.ico +0 -0
  4. package/lib/vae-amap/images/game.png +0 -0
  5. package/lib/vae-amap/images/grid.png +0 -0
  6. package/lib/vae-amap/images/marker.png +0 -0
  7. package/lib/vae-amap/index.js +209 -0
  8. package/lib/vae-amap/style.css +1 -0
  9. package/lib/vae-cloudmap/favicon.ico +0 -0
  10. package/lib/vae-cloudmap/images/game.png +0 -0
  11. package/lib/vae-cloudmap/images/grid.png +0 -0
  12. package/lib/vae-cloudmap/images/marker.png +0 -0
  13. package/lib/vae-cloudmap/index.html +30 -0
  14. package/lib/vae-cloudmap/index.js +4085 -0
  15. package/lib/vae-cloudmap/style.css +1 -0
  16. package/lib/vae-map/favicon.ico +0 -0
  17. package/lib/vae-map/images/game.png +0 -0
  18. package/lib/vae-map/images/grid.png +0 -0
  19. package/lib/vae-map/images/marker.png +0 -0
  20. package/lib/vae-map/index.html +30 -0
  21. package/lib/vae-map/index.js +4322 -0
  22. package/lib/vae-map/style.css +1 -0
  23. package/package.json +1 -1
  24. package/plugins/L.AnimatedMarker/favicon.ico +0 -0
  25. package/plugins/L.AnimatedMarker/images/game.png +0 -0
  26. package/plugins/L.AnimatedMarker/images/grid.png +0 -0
  27. package/plugins/L.AnimatedMarker/images/marker.png +0 -0
  28. package/plugins/L.AnimatedMarker/index.html +30 -0
  29. package/plugins/L.AnimatedMarker/index.js +83 -0
  30. package/plugins/L.EchartsLayer/favicon.ico +0 -0
  31. package/plugins/L.EchartsLayer/images/game.png +0 -0
  32. package/plugins/L.EchartsLayer/images/grid.png +0 -0
  33. package/plugins/L.EchartsLayer/images/marker.png +0 -0
  34. package/plugins/L.EchartsLayer/index.html +30 -0
  35. package/plugins/L.EchartsLayer/index.js +176 -0
  36. package/plugins/L.FootageCalculator.Area/favicon.ico +0 -0
  37. package/plugins/L.FootageCalculator.Area/images/game.png +0 -0
  38. package/plugins/L.FootageCalculator.Area/images/grid.png +0 -0
  39. package/plugins/L.FootageCalculator.Area/images/marker.png +0 -0
  40. package/plugins/L.FootageCalculator.Area/index.html +30 -0
  41. package/plugins/L.FootageCalculator.Area/index.js +418 -0
  42. package/plugins/L.FootageCalculator.Line/favicon.ico +0 -0
  43. package/plugins/L.FootageCalculator.Line/images/game.png +0 -0
  44. package/plugins/L.FootageCalculator.Line/images/grid.png +0 -0
  45. package/plugins/L.FootageCalculator.Line/images/marker.png +0 -0
  46. package/plugins/L.FootageCalculator.Line/index.html +30 -0
  47. package/plugins/L.FootageCalculator.Line/index.js +416 -0
  48. package/plugins/L.GeoUtil/favicon.ico +0 -0
  49. package/plugins/L.GeoUtil/images/game.png +0 -0
  50. package/plugins/L.GeoUtil/images/grid.png +0 -0
  51. package/plugins/L.GeoUtil/images/marker.png +0 -0
  52. package/plugins/L.GeoUtil/index.html +30 -0
  53. package/plugins/L.GeoUtil/index.js +279 -0
  54. package/plugins/L.Glyphicon/favicon.ico +0 -0
  55. package/plugins/L.Glyphicon/images/game.png +0 -0
  56. package/plugins/L.Glyphicon/images/grid.png +0 -0
  57. package/plugins/L.Glyphicon/images/marker.png +0 -0
  58. package/plugins/L.Glyphicon/index.html +30 -0
  59. package/plugins/L.Glyphicon/index.js +57 -0
  60. package/plugins/L.Glyphicon/style.css +1 -0
  61. package/plugins/L.MarkerClusterX/favicon.ico +0 -0
  62. package/plugins/L.MarkerClusterX/images/game.png +0 -0
  63. package/plugins/L.MarkerClusterX/images/grid.png +0 -0
  64. package/plugins/L.MarkerClusterX/images/marker.png +0 -0
  65. package/plugins/L.MarkerClusterX/index.html +30 -0
  66. package/plugins/L.MarkerClusterX/index.js +33 -0
  67. package/plugins/L.MarkerClusterX/style.css +1 -0
  68. package/plugins/L.SafeDivOverlay/favicon.ico +0 -0
  69. package/plugins/L.SafeDivOverlay/images/game.png +0 -0
  70. package/plugins/L.SafeDivOverlay/images/grid.png +0 -0
  71. package/plugins/L.SafeDivOverlay/images/marker.png +0 -0
  72. package/plugins/L.SafeDivOverlay/index.html +30 -0
  73. package/plugins/L.SafeDivOverlay/index.js +26 -0
  74. package/plugins/L.TileLayer.ChinaProvider/favicon.ico +0 -0
  75. package/plugins/L.TileLayer.ChinaProvider/images/game.png +0 -0
  76. package/plugins/L.TileLayer.ChinaProvider/images/grid.png +0 -0
  77. package/plugins/L.TileLayer.ChinaProvider/images/marker.png +0 -0
  78. package/plugins/L.TileLayer.ChinaProvider/index.html +30 -0
  79. package/plugins/L.TileLayer.ChinaProvider/index.js +91 -0
  80. package/plugins/L.VuePopup/favicon.ico +0 -0
  81. package/plugins/L.VuePopup/images/game.png +0 -0
  82. package/plugins/L.VuePopup/images/grid.png +0 -0
  83. package/plugins/L.VuePopup/images/marker.png +0 -0
  84. package/plugins/L.VuePopup/index.html +30 -0
  85. package/plugins/L.VuePopup/index.js +68 -0
  86. package/plugins/L.VueTooltip/favicon.ico +0 -0
  87. package/plugins/L.VueTooltip/images/game.png +0 -0
  88. package/plugins/L.VueTooltip/images/grid.png +0 -0
  89. package/plugins/L.VueTooltip/images/marker.png +0 -0
  90. package/plugins/L.VueTooltip/index.html +30 -0
  91. package/plugins/L.VueTooltip/index.js +68 -0
  92. package/plugins/Mixin.Map.Measure/favicon.ico +0 -0
  93. package/plugins/Mixin.Map.Measure/images/game.png +0 -0
  94. package/plugins/Mixin.Map.Measure/images/grid.png +0 -0
  95. package/plugins/Mixin.Map.Measure/images/marker.png +0 -0
  96. package/plugins/Mixin.Map.Measure/index.html +30 -0
  97. package/plugins/Mixin.Map.Measure/index.js +84 -0
  98. package/plugins/globals/favicon.ico +0 -0
  99. package/plugins/globals/images/game.png +0 -0
  100. package/plugins/globals/images/grid.png +0 -0
  101. package/plugins/globals/images/marker.png +0 -0
  102. package/plugins/globals/index.html +30 -0
  103. package/plugins/globals/index.js +4 -0
  104. package/build/index.mjs +0 -113
  105. package/examples/App.vue +0 -18
  106. package/examples/index.js +0 -13
  107. package/examples/router/index.js +0 -35
  108. package/examples/views/amap.vue +0 -29
  109. package/examples/views/amarker.vue +0 -58
  110. package/examples/views/buffer.vue +0 -66
  111. package/examples/views/cluster.vue +0 -74
  112. package/examples/views/cover.vue +0 -85
  113. package/examples/views/draw-line.vue +0 -49
  114. package/examples/views/draw.vue +0 -54
  115. package/examples/views/echarts.vue +0 -142
  116. package/examples/views/emarker.vue +0 -39
  117. package/examples/views/image.vue +0 -182
  118. package/examples/views/index.vue +0 -61
  119. package/examples/views/lrmap.vue +0 -108
  120. package/examples/views/map.vue +0 -82
  121. package/examples/views/measure.vue +0 -86
  122. package/examples/views/parts/popup.vue +0 -39
  123. package/examples/views/parts/tooltip.vue +0 -39
  124. package/examples/views/push-area.vue +0 -52
  125. package/examples/views/push-line.vue +0 -84
  126. package/examples/views/trace.vue +0 -49
  127. package/jsconfig.json +0 -17
  128. package/src/components/resize-listener/component.jsx +0 -30
  129. package/src/components/resize-listener/index.js +0 -3
  130. package/src/composables/useAutoMessage.js +0 -41
  131. package/src/composables/useContextMenu.js +0 -99
  132. package/src/composables/useMapMeasure.js +0 -191
  133. package/src/composables/useResizeObserver.js +0 -81
  134. package/src/mixins/message.js +0 -1
  135. package/src/packages/index.js +0 -16
  136. package/src/packages/vae-amap/index.js +0 -8
  137. package/src/packages/vae-amap/style.less +0 -9
  138. package/src/packages/vae-amap/vae-amap.jsx +0 -98
  139. package/src/packages/vae-cloudmap/ctrl-context-menu/index.vue +0 -74
  140. package/src/packages/vae-cloudmap/ctrl-draw/index.vue +0 -499
  141. package/src/packages/vae-cloudmap/ctrl-draw-line/index.vue +0 -161
  142. package/src/packages/vae-cloudmap/index.js +0 -57
  143. package/src/packages/vae-cloudmap/scripts/L.MarkerCluster/index.js +0 -2690
  144. package/src/packages/vae-cloudmap/scripts/L.MarkerCluster/style.css +0 -14
  145. package/src/packages/vae-cloudmap/scripts/L.Vae.CRS/index.js +0 -212
  146. package/src/packages/vae-cloudmap/scripts/L.Vae.Client/index.js +0 -780
  147. package/src/packages/vae-cloudmap/scripts/Mixin.ContextMenu/index.js +0 -101
  148. package/src/packages/vae-cloudmap/style.less +0 -163
  149. package/src/packages/vae-cloudmap/vae-cloudmap.jsx +0 -272
  150. package/src/packages/vae-map/ctrl-context-menu/index.vue +0 -74
  151. package/src/packages/vae-map/ctrl-draw/index.vue +0 -498
  152. package/src/packages/vae-map/ctrl-draw-line/index.vue +0 -128
  153. package/src/packages/vae-map/index.js +0 -59
  154. package/src/packages/vae-map/scripts/L.MarkerCluster/index.js +0 -2690
  155. package/src/packages/vae-map/scripts/L.MarkerCluster/style.css +0 -14
  156. package/src/packages/vae-map/scripts/L.Vae.CRS/index.js +0 -114
  157. package/src/packages/vae-map/scripts/L.Vae.Client/index.js +0 -548
  158. package/src/packages/vae-map/scripts/Mixin.ContextMenu/index.js +0 -1
  159. package/src/packages/vae-map/style.less +0 -161
  160. package/src/packages/vae-map/vae-lrmap.jsx +0 -237
  161. package/src/packages/vae-map/vae-map.jsx +0 -135
  162. package/src/plugins/L.AnimatedMarker/index.js +0 -158
  163. package/src/plugins/L.EchartsLayer/index.js +0 -339
  164. package/src/plugins/L.ElasticMarker/index.js +0 -162
  165. package/src/plugins/L.FootageCalculator.Area/index.js +0 -263
  166. package/src/plugins/L.FootageCalculator.Line/index.js +0 -273
  167. package/src/plugins/L.GeoUtil/buffer.js +0 -67
  168. package/src/plugins/L.GeoUtil/index.js +0 -284
  169. package/src/plugins/L.Glyphicon/index.js +0 -91
  170. package/src/plugins/L.Glyphicon/style.less +0 -37
  171. package/src/plugins/L.MarkerClusterX/index.js +0 -93
  172. package/src/plugins/L.MarkerClusterX/style.less +0 -162
  173. package/src/plugins/L.SafeDivOverlay/index.js +0 -55
  174. package/src/plugins/L.TileLayer.ChinaProvider/index.js +0 -108
  175. package/src/plugins/L.VuePopup/index.js +0 -67
  176. package/src/plugins/L.VueTooltip/index.js +0 -63
  177. package/src/plugins/Mixin.Map.Measure/index.js +0 -248
  178. package/src/plugins/globals/index.js +0 -7
  179. package/src/utils/index.js +0 -36
  180. package/src/utils/resize-event.js +0 -45
  181. /package/{public → lib}/favicon.ico +0 -0
  182. /package/{public → lib}/images/game.png +0 -0
  183. /package/{public → lib}/images/grid.png +0 -0
  184. /package/{public → lib}/images/marker.png +0 -0
  185. /package/{public → lib/vae-amap}/index.html +0 -0
@@ -1,263 +0,0 @@
1
- import './../L.GeoUtil'
2
-
3
- L.FootageCalculator = L.FootageCalculator || {}
4
-
5
- // 工作面推进计算器
6
- L.FootageCalculator.Area = L.Evented.extend({
7
-
8
- options: {
9
- crs: L.CRS.EPSG3857, // 坐标转换类
10
- latlngs: [], // 边界经纬度
11
- headStart: null, // 机头经纬度
12
- headEnd: null, // 机头终点经纬度
13
- tailStart: null, // 机尾经纬度
14
- tailEnd: null, /// 机尾终点经纬度
15
- },
16
-
17
- initialize(opts) {
18
- L.setOptions(this, opts)
19
-
20
- // 校验参数
21
- const { crs, latlngs, headStart, headEnd, tailStart, tailEnd } = this.options
22
- if (crs && crs.project && crs.unproject) {
23
- this.crs = crs
24
- } else {
25
- throw new Error('请传入正确的crs参数')
26
- }
27
- if (Array.isArray(latlngs) && latlngs.length > 2) {
28
- this.latlngs = latlngs
29
- } else {
30
- throw new Error('请传入正确的latlngs参数')
31
- }
32
- // 校验机头机尾参数
33
- function assetVertex(value, property) {
34
- if (value < 0) {
35
- throw new Error(`请传入正确的${property}参数,此参数必须是latlngs的某个节点`)
36
- }
37
- }
38
- this.hsIndex = _.findIndex(latlngs, o => _.isEqual(o, headStart))
39
- assetVertex(this.hsIndex, 'headStart')
40
- this.heIndex = _.findIndex(latlngs, o => _.isEqual(o, headEnd))
41
- assetVertex(this.heIndex, 'headEnd')
42
- this.tsIndex = _.findIndex(latlngs, o => _.isEqual(o, tailStart))
43
- assetVertex(this.tsIndex, 'tailStart')
44
- this.teIndex = _.findIndex(latlngs, o => _.isEqual(o, tailEnd))
45
- assetVertex(this.teIndex, 'tailEnd')
46
- // 查重
47
- if (_.uniq([this.hsIndex, this.heIndex, this.tsIndex, this.teIndex]).length < 4) {
48
- throw new Error('机头机尾坐标不允许重复')
49
- }
50
- // 起点
51
- const differIndex = Math.abs(this.hsIndex - this.tsIndex)
52
- if (differIndex != 1 && differIndex != latlngs.length - 1) {
53
- throw new Error('机头和机尾起点必须相邻')
54
- }
55
-
56
- this.initParams()
57
- },
58
-
59
- // 初始化参数
60
- initParams() {
61
- // 经纬度转坐标
62
- this.points = this.latlngs.map(latlng => {
63
- return this.crs.project(toLatLng(latlng))
64
- })
65
-
66
- // 计算预设路径
67
- // 条件:机头机尾起点相邻,推进方向相反
68
- // 1. 主方向:hs0 ts1视为正向,hs1 ts0视为反向
69
- // 2. 主方向为正:机头推进方向为反,否则路径交叉
70
- // 3. 主方向为反:同2,机头推进方向为正,机尾推进方向为反
71
- const length = this.latlngs.length
72
- let headPoints = []
73
- let tailPoints = []
74
- let dirPositive = this.hsIndex < this.tsIndex
75
- if (Math.abs(this.hsIndex - this.tsIndex) == length - 1) {
76
- dirPositive = this.tsIndex == 0
77
- }
78
- if (dirPositive) {
79
- // 机头路径
80
- // hs小于he时,机头路径过起点,提升后再循环
81
- let tempHsIndex = this.hsIndex
82
- if (this.heIndex > this.hsIndex) {
83
- tempHsIndex += length
84
- }
85
- for (let i = this.heIndex; i <= tempHsIndex; i++) {
86
- headPoints.push(this.points[i >= length ? i - length : i])
87
- }
88
- headPoints.reverse()
89
- // 机尾路径
90
- let tempTeIndex = this.teIndex
91
- if (this.tsIndex > this.teIndex) {
92
- tempTeIndex += length
93
- }
94
- for (let i = this.tsIndex; i <= tempTeIndex; i++) {
95
- tailPoints.push(this.points[i >= length ? i - length : i])
96
- }
97
- } else {
98
- // 机头路径
99
- let tempHeIndex = this.heIndex
100
- if (this.hsIndex > this.heIndex) {
101
- tempHeIndex += length
102
- }
103
- for (let i = this.hsIndex; i <= tempHeIndex; i++) {
104
- headPoints.push(this.points[i >= length ? i - length : i])
105
- }
106
- // 机尾路径
107
- let tempTsIndex = this.tsIndex
108
- if (this.teIndex > this.tsIndex) {
109
- tempTsIndex += length
110
- }
111
- for (let i = this.teIndex; i <= tempTsIndex; i++) {
112
- tailPoints.push(this.points[i >= length ? i - length : i])
113
- }
114
- tailPoints.reverse()
115
- }
116
-
117
- // 处理线段
118
- this.headSegments = []
119
- headPoints.forEach((point, i) => {
120
- if (i > 0) {
121
- this.headSegments.push({ start: headPoints[i - 1], end: point })
122
- }
123
- })
124
- this.tailSegments = []
125
- tailPoints.forEach((point, i) => {
126
- if (i > 0) {
127
- this.tailSegments.push({ start: tailPoints[i - 1], end: point })
128
- }
129
- })
130
- },
131
-
132
- /**
133
- * 执行计算
134
- * @param {L.LatLng} headStart 机头起点
135
- * @param {L.LatLng} tailStart 机尾起点
136
- * @param {Number} headDistance 机头推进距离
137
- * @param {Number} tailDistance 机尾推进距离
138
- * @returns {L.LatLng} headEnd 推进后机头的经纬度
139
- * @returns {L.LatLng} tailEnd 推进后机尾的经纬度
140
- * @returns {Array<L.LatLng>} latlngs 推进的区域范围
141
- */
142
- doCalculate({ headStart, tailStart, headDistance, tailDistance }) {
143
- const headStartPoint = this.crs.project(toLatLng(headStart))
144
- const tailStartPoint = this.crs.project(toLatLng(tailStart))
145
- const headResult = this.calcWorkPath(headStartPoint, this.headSegments, headDistance)
146
- const tailResult = this.calcWorkPath(tailStartPoint, this.tailSegments, tailDistance)
147
-
148
- // 拼装计算结果
149
- const headEnd = this.crs.unproject(_.last(headResult.path))
150
- const tailEnd = this.crs.unproject(_.last(tailResult.path))
151
- let latlngs = []
152
- let headPath = headResult.path
153
- let tailPath = tailResult.path
154
- tailPath.reverse()
155
- // 推进范围
156
- new Array(headPath, tailPath).forEach(path => {
157
- path.forEach(v => {
158
- latlngs.push(this.crs.unproject(v))
159
- })
160
- })
161
-
162
- return { headEnd, tailEnd, latlngs }
163
- },
164
-
165
- /**
166
- * 计算一次推进的结果
167
- * @param {L.Point} start 起点
168
- * @param {Array} segments 线段
169
- * @param {Number} distance 推进距离
170
- */
171
- calcWorkPath(start, segments, distance) {
172
- let sumDistance = 0 // 累计计算的距离
173
- let startIndex = -1 // 起点所在线段的序号
174
- let endIndex = -1 // 终点所在线段的序号
175
- let end // 终点坐标
176
-
177
- segments.forEach((segment, i) => {
178
- // 终点确认后终止计算
179
- if (endIndex < 0) {
180
- // 当前段上的起点
181
- let curStart = segment.start
182
- // 确定起点序号,若起点距离线段小于0.01,视为在该段上
183
- if (startIndex < 0 && L.LineUtil.pointToSegmentDistance(start, segment.start, segment.end) < 0.01) {
184
- startIndex = i
185
- curStart = start
186
- }
187
- // 当前段提供的距离
188
- let curDistance = 0
189
- if (startIndex >= 0) {
190
- curDistance = curStart.distanceTo(segment.end)
191
- }
192
- // 确定终点序号,若累计距离超过推进距离,即可在当前段上确认终点
193
- if (sumDistance + curDistance >= distance) {
194
- endIndex = i
195
- end = this.calcEndPointOnLine(curStart, segment.end, distance - sumDistance)
196
- }
197
- sumDistance += curDistance
198
- }
199
- })
200
-
201
- // 距离过长无法确认终点时,使用末点作为临时终点
202
- let tempEndIndex = endIndex
203
- if (endIndex < 0) {
204
- tempEndIndex = segments.length - 1
205
- end = _.last(segments).end
206
- }
207
-
208
- // 拼装推进路径
209
- let path = [start]
210
- for (let i = startIndex; i < tempEndIndex; i++) {
211
- path.push(segments[i].end)
212
- }
213
- path.push(end)
214
-
215
- // 挤压点偏移
216
- if (path.length == 2 && path[0].x == path[1].x && path[0].y == path[1].y) {
217
- const lastSegment = _.last(segments)
218
- const rad = L.GeoUtil.computeRad(lastSegment.start, lastSegment.end)
219
- path[0] = path[1].subtract(L.point(0.01 * Math.cos(rad), 0.01 * Math.sin(rad)))
220
- }
221
-
222
- // 拼装剩余路径
223
- let remainingPath = []
224
- if (tempEndIndex == endIndex) {
225
- remainingPath = [end]
226
- for (let i = tempEndIndex; i < segments.length - 1; i++) {
227
- remainingPath.push(segments[i].end)
228
- }
229
- remainingPath.push(_.last(segments).end)
230
- }
231
-
232
- // 尾段方向弧度
233
- let endSegment = segments[endIndex]
234
- if (endIndex < 0) {
235
- endSegment = _.last(segments)
236
- }
237
- let endRad = L.GeoUtil.computeRad(endSegment.start, endSegment.end)
238
-
239
- return { path, remainingPath, endRad }
240
- },
241
-
242
- // 获取a点向b点方向延伸distance后的坐标
243
- calcEndPointOnLine(a, b, distance) {
244
- const rad = L.GeoUtil.computeRad(a, b)
245
- const dx = distance * Math.cos(rad)
246
- const dy = distance * Math.sin(rad)
247
-
248
- return a.add(L.point(dx, dy))
249
- }
250
-
251
- })
252
-
253
- function toLatLng(value) {
254
- if (!(value instanceof L.LatLng)) {
255
- value = L.latLng(value)
256
- }
257
- return value
258
- }
259
-
260
- L.footageCalculator = L.footageCalculator || {}
261
- L.footageCalculator.area = function(options) {
262
- return new L.FootageCalculator.Area(options)
263
- }
@@ -1,273 +0,0 @@
1
- import './../L.GeoUtil'
2
-
3
- L.FootageCalculator = L.FootageCalculator || {}
4
-
5
- // 巷道进尺计算器
6
- L.FootageCalculator.Line = L.Evented.extend({
7
-
8
- options: {
9
- crs: L.CRS.EPSG3857, // 坐标转换类
10
- latlngs: [], // 中心线
11
- width: 0, // 巷道宽度
12
- },
13
-
14
- initialize(opts) {
15
- L.setOptions(this, opts)
16
-
17
- // 校验参数
18
- const crs = this.options.crs
19
- if (crs && crs.project && crs.unproject) {
20
- this.crs = crs
21
- } else {
22
- throw new Error('请传入正确的crs参数')
23
- }
24
- const latlngs = this.options.latlngs
25
- const width = this.options.width
26
- if (Array.isArray(latlngs) && latlngs.length > 1 && width > 0) {
27
- this.latlngs = latlngs
28
- this.width = width
29
- } else {
30
- throw new Error('请传入正确的latlngs和width参数')
31
- }
32
-
33
- this.initParams()
34
- },
35
-
36
- // 初始化参数
37
- initParams() {
38
- // 格式化点
39
- this.points = this.latlngs.map(latlng => {
40
- if (!(latlng instanceof L.LatLng)) {
41
- latlng = L.latLng(latlng)
42
- }
43
- return this.crs.project(latlng)
44
- })
45
- // 格式化线段
46
- this.segments = []
47
- this.points.forEach((point, i) => {
48
- if (i > 0) {
49
- let offsetDistance = 0
50
- if (i > 1) {
51
- offsetDistance = this.calcOffsetDistance(
52
- this.points[i - 2],
53
- this.points[i - 1],
54
- this.points[i],
55
- this.width / 2
56
- )
57
- }
58
- this.segments.push({
59
- start: this.points[i - 1],
60
- end: point,
61
- offsetDistance
62
- })
63
- }
64
- })
65
- },
66
-
67
- /**
68
- * 执行计算
69
- * @param {L.LatLng} start 起点
70
- * @param {Number} distance 推进距离,米
71
- */
72
- doCalculate({ start, distance }) {
73
- if (distance > 0) {
74
- if (!(start instanceof L.LatLng)) {
75
- start = L.latLng(start)
76
- }
77
- const startPoint = this.crs.project(start)
78
- const { path, remainingPath, endRad } = this.calcWorkPath(startPoint, this.segments, distance)
79
- const area = this.calcWorkArea({ path, width: this.width / 2 })
80
-
81
- const latlngPath = path.map(v => {
82
- return this.crs.unproject(v)
83
- })
84
- const latlngArea = area.map(v => {
85
- return this.crs.unproject(v)
86
- })
87
- const latlngRemainingPath = remainingPath.map(v => {
88
- return this.crs.unproject(v)
89
- })
90
- const endAngle = L.GeoUtil.toClockwiseAngle(L.GeoUtil.radToAngle(endRad))
91
-
92
- return { path: latlngPath, remainingPath: latlngRemainingPath, area: latlngArea, endAngle }
93
-
94
- } else {
95
- throw new Error('distance参数必须大于0')
96
- }
97
- },
98
-
99
- /**
100
- * 计算一次推进的结果
101
- * @param {L.Point} start 起点
102
- * @param {Array} segments 线段
103
- * @param {Number} distance 推进距离
104
- */
105
- calcWorkPath(start, segments, distance) {
106
- let sumDistance = 0 // 累计计算的距离
107
- let startIndex = -1 // 起点所在线段的序号
108
- let endIndex = -1 // 终点所在线段的序号
109
- let end // 终点坐标
110
-
111
- segments.forEach((segment, i) => {
112
- // 终点确认后终止计算
113
- if (endIndex < 0) {
114
- // 斜角补足
115
- distance += segment.offsetDistance
116
- // 当前段上的起点
117
- let curStart = segment.start
118
- // 确定起点序号,若起点距离线段小于0.01,视为在该段上
119
- if (startIndex < 0 && L.LineUtil.pointToSegmentDistance(start, segment.start, segment.end) < 0.01) {
120
- startIndex = i
121
- curStart = start
122
- }
123
- // 当前段提供的距离
124
- let curDistance = 0
125
- if (startIndex >= 0) {
126
- curDistance = curStart.distanceTo(segment.end)
127
- }
128
- // 确定终点序号,若累计距离超过推进距离,即可在当前段上确认终点
129
- if (sumDistance + curDistance >= distance) {
130
- endIndex = i
131
- end = this.calcEndPointOnLine(curStart, segment.end, distance - sumDistance)
132
- }
133
- sumDistance += curDistance
134
- }
135
- })
136
-
137
- // 距离过长无法确认终点时,使用末点作为临时终点
138
- let tempEndIndex = endIndex
139
- if (endIndex < 0) {
140
- tempEndIndex = segments.length - 1
141
- end = _.last(segments).end
142
- }
143
-
144
- // 拼装推进路径
145
- let path = [start]
146
- for (let i = startIndex; i < tempEndIndex; i++) {
147
- path.push(segments[i].end)
148
- }
149
- path.push(end)
150
-
151
- // 挤压点偏移
152
- if (path.length == 2 && path[0].x == path[1].x && path[0].y == path[1].y) {
153
- const lastSegment = _.last(segments)
154
- const rad = L.GeoUtil.computeRad(lastSegment.start, lastSegment.end)
155
- path[0] = path[1].subtract(L.point(0.01 * Math.cos(rad), 0.01 * Math.sin(rad)))
156
- }
157
-
158
- // 拼装剩余路径
159
- let remainingPath = []
160
- if (tempEndIndex == endIndex) {
161
- remainingPath = [end]
162
- for (let i = tempEndIndex; i < segments.length - 1; i++) {
163
- remainingPath.push(segments[i].end)
164
- }
165
- remainingPath.push(_.last(segments).end)
166
- }
167
-
168
- // 尾段方向弧度
169
- let endSegment = segments[endIndex]
170
- if (endIndex < 0) {
171
- endSegment = _.last(segments)
172
- }
173
- let endRad = L.GeoUtil.computeRad(endSegment.start, endSegment.end)
174
-
175
- return { path, remainingPath, endRad }
176
- },
177
-
178
- /**
179
- * 根据中心线路径和法线长度,计算推进范围
180
- * @param {Array<L.Point>} path 推进路径
181
- * @param {Number} width 法线长度
182
- */
183
- calcWorkArea({ path, width }) {
184
- let forwardPath = []
185
- let backwardPath = []
186
- let array = path.map((v, i) => {
187
- // 起点
188
- if (i == 0) {
189
- const rad = L.GeoUtil.computeRad(path[i], path[i + 1])
190
- return this.calcVerticalOffestPoints(v, rad, width)
191
- }
192
- // 终点
193
- else if (i == path.length - 1) {
194
- const rad = L.GeoUtil.computeRad(path[i - 1], path[i])
195
- return this.calcVerticalOffestPoints(v, rad, width)
196
- }
197
- // 中段
198
- else {
199
- // 上一段角度
200
- const preRad = L.GeoUtil.computeRad(path[i - 1], path[i])
201
- // 当前段角度
202
- const curRad = L.GeoUtil.computeRad(path[i], path[i + 1])
203
- // 八个偏移点
204
- const ps1 = this.calcVerticalOffestPoints(path[i - 1], preRad, width)
205
- const ps2 = this.calcVerticalOffestPoints(path[i], preRad, width)
206
- const ps3 = this.calcVerticalOffestPoints(path[i], curRad, width)
207
- const ps4 = this.calcVerticalOffestPoints(path[i + 1], curRad, width)
208
- // 交点
209
- const intersection1 = L.GeoUtil.linesIntersection(ps1[0], ps2[0], ps3[0], ps4[0])
210
- const intersection2 = L.GeoUtil.linesIntersection(ps1[1], ps2[1], ps3[1], ps4[1])
211
-
212
- if (intersection1 && intersection2) {
213
- return [intersection1, intersection2]
214
- }
215
- }
216
- })
217
- array.forEach(v => {
218
- if (v) {
219
- forwardPath.push(v[0])
220
- backwardPath.push(v[1])
221
- }
222
- })
223
-
224
- return _.concat(forwardPath, _.reverse(backwardPath))
225
- },
226
-
227
- // 获取a点向b点方向延伸distance后的坐标
228
- calcEndPointOnLine(a, b, distance) {
229
- const rad = L.GeoUtil.computeRad(a, b)
230
- const dx = distance * Math.cos(rad)
231
- const dy = distance * Math.sin(rad)
232
-
233
- return a.add(L.point(dx, dy))
234
- },
235
-
236
- // 计算补足距离
237
- calcOffsetDistance(p1, p2, p3, width) {
238
- const segRad = L.GeoUtil.segmentsRad(p2, p1, p3, width)
239
- const preLineRad = L.GeoUtil.computeRad(p1, p2)
240
- const curLineRad = L.GeoUtil.computeRad(p2, p3)
241
- const ps1 = this.calcVerticalOffestPoints(p1, preLineRad, width)
242
- const ps2 = this.calcVerticalOffestPoints(p2, preLineRad, width)
243
- const ps3 = this.calcVerticalOffestPoints(p2, curLineRad, width)
244
- const ps4 = this.calcVerticalOffestPoints(p3, curLineRad, width)
245
-
246
- let intersection = null
247
- if (segRad > 0) {
248
- intersection = L.GeoUtil.linesIntersection(ps1[1], ps2[1], ps3[1], ps4[1])
249
- } else {
250
- intersection = L.GeoUtil.linesIntersection(ps1[0], ps2[0], ps3[0], ps4[0])
251
- }
252
- if (intersection) {
253
- const foot = L.GeoUtil.footPointOnLine(intersection, p2, p3)
254
- return foot.distanceTo(p2)
255
- } else {
256
- return 0
257
- }
258
- },
259
-
260
- // 获取目标点的在给定方向的法线上的两个偏移点
261
- calcVerticalOffestPoints(point, rad, distance) {
262
- const vertRad = rad - Math.PI / 2
263
- const offset = L.point(distance * Math.cos(vertRad), distance * Math.sin(vertRad))
264
-
265
- return [point.add(offset), point.subtract(offset)]
266
- }
267
-
268
- })
269
-
270
- L.footageCalculator = L.footageCalculator || {}
271
- L.footageCalculator.line = function (options) {
272
- return new L.FootageCalculator(options)
273
- }
@@ -1,67 +0,0 @@
1
- import * as turf from '@turf/helpers'
2
- import buffer from '@turf/buffer'
3
-
4
- // 转换为L.LatLng数组
5
- const geoJSONTolatLngs = json => {
6
- let result = []
7
- const coordinates = json.geometry.coordinates
8
- coordinates.forEach(coords => {
9
- result.push(coords.map(e => {
10
- return {
11
- lat: e[1],
12
- lng: e[0]
13
- }
14
- }))
15
- })
16
- return result
17
- }
18
-
19
- export default {
20
-
21
-
22
- /**
23
- * 点缓冲分析
24
- * @param {L.LatLng} center 中心点
25
- * @param {Number} distance 缓冲距离
26
- * @param {String} units 单位
27
- * @returns {Array<Array<L.LatLng>>} 缓冲区经纬度序列
28
- */
29
- bufferPoint(center, distance, units = 'meters') {
30
- const turfLatLng = [center.lng, center.lat]
31
- const geoJSONData = buffer(turf.point(turfLatLng), distance, { units })
32
- return geoJSONTolatLngs(geoJSONData)
33
- },
34
-
35
- /**
36
- * 路径缓冲分析
37
- * @param {Array<L.LatLng>} latLngs 路径经纬度序列
38
- * @param {Number} distance 缓冲距离
39
- * @param {String} units 单位
40
- * @returns {Array<Array<L.LatLng>>} 缓冲区经纬度序列
41
- */
42
- bufferLine(latLngs, distance, units = 'meters') {
43
- const turfLatLngs = latLngs.map(e => {
44
- return [e.lng, e.lat]
45
- })
46
- const geoJSONData = buffer(turf.lineString(turfLatLngs), distance, { units })
47
- return geoJSONTolatLngs(geoJSONData)
48
- },
49
-
50
- /**
51
- * 区域缓冲分析
52
- * @param {Array<L.LatLng>} latLngs 区域经纬度序列
53
- * @param {Number} distance 缓冲距离
54
- * @param {String} units 单位
55
- * @returns {Array<Array<L.LatLng>>} 缓冲区经纬度序列
56
- */
57
- bufferArea(latLngs, distance, units = 'meters') {
58
- let turfLatLngs = latLngs.map(e => {
59
- return [e.lng, e.lat]
60
- })
61
- turfLatLngs.push(turfLatLngs[0])
62
- const geoJSONData = buffer(turf.polygon([turfLatLngs]), distance, { units })
63
- return geoJSONTolatLngs(geoJSONData)
64
- }
65
-
66
-
67
- }