xy-map 1.0.60 → 1.1.2
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/demo.html +1 -0
- package/{src/image/marker.png → img/marker.42b5782a.png} +0 -0
- package/package.json +11 -47
- package/xy-map.common.js +67654 -0
- package/xy-map.css +1 -0
- package/xy-map.umd.js +67673 -0
- package/xy-map.umd.min.js +20 -0
- package/.browserslistrc +0 -3
- package/.eslintignore +0 -1
- package/.eslintrc.js +0 -29
- package/README.md +0 -36
- package/babel.config.js +0 -3
- package/jsconfig.json +0 -12
- package/lint-staged.config.js +0 -3
- package/public/draco/README.md +0 -32
- package/public/draco/draco_decoder.js +0 -52
- package/public/draco/draco_decoder.wasm +0 -0
- package/public/draco/draco_encoder.js +0 -33
- package/public/draco/draco_wasm_wrapper.js +0 -104
- package/public/draco/gltf/draco_decoder.js +0 -48
- package/public/draco/gltf/draco_decoder.wasm +0 -0
- package/public/draco/gltf/draco_encoder.js +0 -33
- package/public/draco/gltf/draco_wasm_wrapper.js +0 -104
- package/public/favicon.ico +0 -0
- package/public/img/MM.png +0 -0
- package/public/img/MM_D.png +0 -0
- package/public/img/MM_W.png +0 -0
- package/public/img/loading.gif +0 -0
- package/public/img/waternormals.jpg +0 -0
- package/public/index.html +0 -29
- package/src/App.vue +0 -13
- package/src/image/arrow_white.png +0 -0
- package/src/image/map_end.png +0 -0
- package/src/image/map_start.png +0 -0
- package/src/index.js +0 -154
- package/src/layers/Line.js +0 -203
- package/src/layers/Point.js +0 -384
- package/src/layers/Polygon.js +0 -119
- package/src/layers/Text.js +0 -53
- package/src/layers/circle.js +0 -148
- package/src/layers/circleAnimate.js +0 -147
- package/src/layers/index.js +0 -128
- package/src/layers/model copy.js +0 -314
- package/src/layers/model.js +0 -341
- package/src/layers/scene.js +0 -314
- package/src/layers/water.js +0 -239
- package/src/map.js +0 -486
- package/src/package/draw/index.vue +0 -239
- package/src/package/draw/line.vue +0 -172
- package/src/package/draw/point.vue +0 -152
- package/src/package/draw/polygon.vue +0 -172
- package/src/package/draw/shpFile.vue +0 -49
- package/src/package/draw/styles.js +0 -162
- package/src/package/mapFullScreen.vue +0 -105
- package/src/package/mapLoad.vue +0 -120
- package/src/package/mapMarker.vue +0 -50
- package/src/package/mapModel.vue +0 -69
- package/src/package/mapRain.vue +0 -110
- package/src/style/hoverHtml.css +0 -29
- package/src/style/main.scss +0 -186
- package/src/style/map.css +0 -7
- package/src/util/gaodeApi.js +0 -67
- package/src/util/mapEvent.js +0 -111
- package/src/util/mapHoverHtml.js +0 -59
- package/src/util/mapTools.js +0 -169
- package/src/util/measure-area.js +0 -215
- package/src/util/measure-distance.js +0 -600
- package/vue.config.js +0 -32
package/src/util/mapTools.js
DELETED
|
@@ -1,169 +0,0 @@
|
|
|
1
|
-
import mapSdk from '../map'
|
|
2
|
-
import * as turf from '@turf/turf'
|
|
3
|
-
|
|
4
|
-
// 工具
|
|
5
|
-
import {
|
|
6
|
-
measureLineLength,
|
|
7
|
-
closeMeasureLine
|
|
8
|
-
} from './measure-distance.js'
|
|
9
|
-
import {
|
|
10
|
-
measureArea,
|
|
11
|
-
closeMeasureArea
|
|
12
|
-
} from './measure-area.js'
|
|
13
|
-
|
|
14
|
-
// list转geoJson
|
|
15
|
-
export const toGeoJson = (list, type, props = 'position') => {
|
|
16
|
-
let pointsData = list.map((item, index) => {
|
|
17
|
-
return {
|
|
18
|
-
id: item.id || '',
|
|
19
|
-
type: 'Feature',
|
|
20
|
-
geometry: {
|
|
21
|
-
type: type,
|
|
22
|
-
coordinates: item[props]
|
|
23
|
-
},
|
|
24
|
-
properties: item
|
|
25
|
-
}
|
|
26
|
-
})
|
|
27
|
-
|
|
28
|
-
let data = {
|
|
29
|
-
type: 'FeatureCollection',
|
|
30
|
-
features: pointsData
|
|
31
|
-
}
|
|
32
|
-
return data
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
/**
|
|
36
|
-
* 加载图片
|
|
37
|
-
*/
|
|
38
|
-
export const loadImage = (src, width = 24, height = 24) => {
|
|
39
|
-
return new Promise((resolve) => {
|
|
40
|
-
let image = new Image(width, height)
|
|
41
|
-
image.src = src
|
|
42
|
-
image.onload = () => {
|
|
43
|
-
resolve(image)
|
|
44
|
-
}
|
|
45
|
-
})
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
// 测距
|
|
49
|
-
export const ranging = () => {
|
|
50
|
-
let {
|
|
51
|
-
map
|
|
52
|
-
} = mapSdk
|
|
53
|
-
measureLineLength(map)
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
// 测面积
|
|
57
|
-
export const drawArea = () => {
|
|
58
|
-
let {
|
|
59
|
-
map
|
|
60
|
-
} = mapSdk
|
|
61
|
-
measureArea(map)
|
|
62
|
-
}
|
|
63
|
-
|
|
64
|
-
// 清除测量
|
|
65
|
-
export const clearDraw = () => {
|
|
66
|
-
let {
|
|
67
|
-
map
|
|
68
|
-
} = mapSdk
|
|
69
|
-
closeMeasureLine(map)
|
|
70
|
-
closeMeasureArea(map)
|
|
71
|
-
}
|
|
72
|
-
|
|
73
|
-
// 判断点是否在区域内
|
|
74
|
-
export const pointInPolygon = (point, area) => {
|
|
75
|
-
// point = [-77, 44]
|
|
76
|
-
/* area = [
|
|
77
|
-
[
|
|
78
|
-
[-81, 41],
|
|
79
|
-
[-81, 47],
|
|
80
|
-
[-72, 47],
|
|
81
|
-
[-72, 41],
|
|
82
|
-
[-81, 41]
|
|
83
|
-
]
|
|
84
|
-
]*/
|
|
85
|
-
|
|
86
|
-
let pt = turf.point(point)
|
|
87
|
-
let poly = turf.polygon(area)
|
|
88
|
-
return turf.booleanPointInPolygon(pt, poly)
|
|
89
|
-
}
|
|
90
|
-
|
|
91
|
-
// 计算两点间的距离
|
|
92
|
-
export const distance = (fromLngLat, toLngLat) => {
|
|
93
|
-
// from = [-75.343, 39.984]
|
|
94
|
-
// to = [-75.534, 39.123]
|
|
95
|
-
|
|
96
|
-
let from = turf.point(fromLngLat)
|
|
97
|
-
let to = turf.point(toLngLat)
|
|
98
|
-
let distance = turf.distance(from, to, {
|
|
99
|
-
units: 'miles'
|
|
100
|
-
})
|
|
101
|
-
return distance
|
|
102
|
-
}
|
|
103
|
-
|
|
104
|
-
// 两点间中点坐标
|
|
105
|
-
export const lineCenter = (LngLat1, LngLat2) => {
|
|
106
|
-
// LngLat1 = [-75.343, 39.984]
|
|
107
|
-
// LngLat2 = [-75.534, 39.123]
|
|
108
|
-
|
|
109
|
-
var point1 = turf.point(LngLat1)
|
|
110
|
-
var point2 = turf.point(LngLat2)
|
|
111
|
-
|
|
112
|
-
var midpoint = turf.midpoint(point1, point2)
|
|
113
|
-
return midpoint
|
|
114
|
-
}
|
|
115
|
-
|
|
116
|
-
// 多边形的中点坐标
|
|
117
|
-
export const polygonCenter = (area) => {
|
|
118
|
-
/* area = [
|
|
119
|
-
[
|
|
120
|
-
[-81, 41],
|
|
121
|
-
[-81, 47],
|
|
122
|
-
[-72, 47],
|
|
123
|
-
[-72, 41],
|
|
124
|
-
[-81, 41]
|
|
125
|
-
]
|
|
126
|
-
]*/
|
|
127
|
-
|
|
128
|
-
let polygon = turf.polygon(area)
|
|
129
|
-
let center = turf.centerOfMass(polygon)
|
|
130
|
-
return center
|
|
131
|
-
}
|
|
132
|
-
|
|
133
|
-
// 获取点到线的最近一点坐标
|
|
134
|
-
export const nearestPointOnLine = (line, point) => {
|
|
135
|
-
// line = [
|
|
136
|
-
// [-77.031669, 38.878605],
|
|
137
|
-
// [-77.029609, 38.881946],
|
|
138
|
-
// [-77.020339, 38.884084],
|
|
139
|
-
// [-77.025661, 38.885821],
|
|
140
|
-
// [-77.021884, 38.889563],
|
|
141
|
-
// [-77.019824, 38.892368]
|
|
142
|
-
// ]
|
|
143
|
-
// point = [-77.037076, 38.884017]
|
|
144
|
-
|
|
145
|
-
const l = turf.lineString(line)
|
|
146
|
-
const p = turf.point(point)
|
|
147
|
-
|
|
148
|
-
var snapped = turf.nearestPointOnLine(l, p)
|
|
149
|
-
return snapped
|
|
150
|
-
}
|
|
151
|
-
|
|
152
|
-
/**
|
|
153
|
-
* type 面平移(polygon)、 点平移(point)、 线平移(lineString)
|
|
154
|
-
* data 点线面的坐标数组
|
|
155
|
-
* xy偏移值
|
|
156
|
-
*/
|
|
157
|
-
export const transformTranslate = (type, data, x, y) => {
|
|
158
|
-
return turf.transformTranslate(turf[type](data), x, y)
|
|
159
|
-
}
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
/**
|
|
163
|
-
* 根据中线点获取对应半径圆坐标
|
|
164
|
-
* center 中心点坐标[131.073341552, 45.800152475]
|
|
165
|
-
* radius 半径单位km
|
|
166
|
-
*/
|
|
167
|
-
export const pointToCircleGeoJson = (center, radius) => {
|
|
168
|
-
return turf.circle(center, radius)
|
|
169
|
-
}
|
package/src/util/measure-area.js
DELETED
|
@@ -1,215 +0,0 @@
|
|
|
1
|
-
import mapboxgl from 'mapbox-gl'
|
|
2
|
-
import * as turf from '@turf/turf'
|
|
3
|
-
|
|
4
|
-
let isMeasure = true // 测面的状态
|
|
5
|
-
let points = []
|
|
6
|
-
let jsonPoint = {
|
|
7
|
-
type: 'FeatureCollection',
|
|
8
|
-
features: []
|
|
9
|
-
}
|
|
10
|
-
let jsonLine = {
|
|
11
|
-
type: 'FeatureCollection',
|
|
12
|
-
features: []
|
|
13
|
-
}
|
|
14
|
-
let measureAreaEle = null
|
|
15
|
-
let tooltip = null
|
|
16
|
-
|
|
17
|
-
let textColor = '#fff'
|
|
18
|
-
let lineColor = '#ff0'
|
|
19
|
-
|
|
20
|
-
// 测面
|
|
21
|
-
export function measureArea(map) {
|
|
22
|
-
clearMeasure(map)
|
|
23
|
-
isMeasure = true
|
|
24
|
-
// 禁止双击缩放
|
|
25
|
-
map.doubleClickZoom.disable()
|
|
26
|
-
map.getCanvas().style.cursor = 'default'
|
|
27
|
-
measureAreaEle = document.createElement('div')
|
|
28
|
-
measureAreaEle.setAttribute('class', 'measure-area-result')
|
|
29
|
-
const option = {
|
|
30
|
-
element: measureAreaEle,
|
|
31
|
-
anchor: 'left',
|
|
32
|
-
offset: [8, 0]
|
|
33
|
-
}
|
|
34
|
-
tooltip = new mapboxgl.Marker(option).setLngLat([0, 0]).addTo(map)
|
|
35
|
-
const source = map.getSource('measure-area-points')
|
|
36
|
-
if (source) {
|
|
37
|
-
map.getSource('measure-area-points').setData(jsonPoint)
|
|
38
|
-
map.getSource('measure-area-line').setData(jsonLine)
|
|
39
|
-
} else {
|
|
40
|
-
map.addSource('measure-area-points', {
|
|
41
|
-
type: 'geojson',
|
|
42
|
-
data: jsonPoint
|
|
43
|
-
})
|
|
44
|
-
map.addSource('measure-area-line', {
|
|
45
|
-
type: 'geojson',
|
|
46
|
-
data: jsonLine
|
|
47
|
-
})
|
|
48
|
-
map.addLayer({
|
|
49
|
-
id: 'measure-area-line',
|
|
50
|
-
type: 'fill',
|
|
51
|
-
source: 'measure-area-line',
|
|
52
|
-
paint: {
|
|
53
|
-
'fill-color': lineColor,
|
|
54
|
-
'fill-opacity': 0.1
|
|
55
|
-
}
|
|
56
|
-
})
|
|
57
|
-
map.addLayer({
|
|
58
|
-
id: 'line-area-stroke',
|
|
59
|
-
type: 'line',
|
|
60
|
-
source: 'measure-area-line',
|
|
61
|
-
paint: {
|
|
62
|
-
'line-color': lineColor,
|
|
63
|
-
'line-width': 2,
|
|
64
|
-
'line-opacity': 0.65
|
|
65
|
-
}
|
|
66
|
-
})
|
|
67
|
-
map.addLayer({
|
|
68
|
-
id: 'measure-area-points',
|
|
69
|
-
type: 'circle',
|
|
70
|
-
source: 'measure-area-points',
|
|
71
|
-
paint: {
|
|
72
|
-
'circle-color': textColor,
|
|
73
|
-
'circle-radius': 3,
|
|
74
|
-
'circle-stroke-width': 2,
|
|
75
|
-
'circle-stroke-color': lineColor
|
|
76
|
-
}
|
|
77
|
-
})
|
|
78
|
-
}
|
|
79
|
-
|
|
80
|
-
map.on('click', drawPointHandler)
|
|
81
|
-
map.on('dblclick', drawResultHandler)
|
|
82
|
-
map.on('mousemove', drawMoveHandler)
|
|
83
|
-
}
|
|
84
|
-
|
|
85
|
-
// 获取面积
|
|
86
|
-
function getArea(coords) {
|
|
87
|
-
let pts = points.concat([coords])
|
|
88
|
-
pts = pts.concat([points[0]])
|
|
89
|
-
const polygon = turf.polygon([pts])
|
|
90
|
-
let area = turf.area(polygon)
|
|
91
|
-
if (area < 1000) {
|
|
92
|
-
area = Math.round(area) + 'm²' + ', 双击结束绘制'
|
|
93
|
-
} else {
|
|
94
|
-
area = (area / 1000000).toFixed(4) + 'km²' + ', 双击结束绘制'
|
|
95
|
-
}
|
|
96
|
-
return area
|
|
97
|
-
}
|
|
98
|
-
|
|
99
|
-
// 绘制测面的点位
|
|
100
|
-
function drawPointHandler(e) {
|
|
101
|
-
if (isMeasure) {
|
|
102
|
-
const coords = [e.lngLat.lng, e.lngLat.lat]
|
|
103
|
-
const map = e.target
|
|
104
|
-
points.push(coords)
|
|
105
|
-
jsonPoint.features.push({
|
|
106
|
-
type: 'Feature',
|
|
107
|
-
geometry: {
|
|
108
|
-
type: 'Point',
|
|
109
|
-
coordinates: coords
|
|
110
|
-
}
|
|
111
|
-
})
|
|
112
|
-
map.getSource('measure-area-points').setData(jsonPoint)
|
|
113
|
-
}
|
|
114
|
-
}
|
|
115
|
-
|
|
116
|
-
// 绘制显示结果
|
|
117
|
-
function drawResultHandler(e) {
|
|
118
|
-
if (isMeasure) {
|
|
119
|
-
const coords = [e.lngLat.lng, e.lngLat.lat]
|
|
120
|
-
const map = e.target
|
|
121
|
-
points.push(coords)
|
|
122
|
-
isMeasure = false
|
|
123
|
-
measureAreaEle.innerHTML = getArea(coords).split(',')[0]
|
|
124
|
-
tooltip.setLngLat(coords)
|
|
125
|
-
|
|
126
|
-
// 添加关闭按钮
|
|
127
|
-
const _ele = document.createElement('div')
|
|
128
|
-
_ele.setAttribute('class', 'measure-area-result close')
|
|
129
|
-
const option = {
|
|
130
|
-
element: _ele,
|
|
131
|
-
anchor: 'bottom-left',
|
|
132
|
-
offset: [-5, -10]
|
|
133
|
-
}
|
|
134
|
-
_ele.innerHTML = '清除'
|
|
135
|
-
_ele.style.color = '#ccc'
|
|
136
|
-
new mapboxgl.Marker(option).setLngLat(coords).addTo(map)
|
|
137
|
-
_ele.onclick = function (__e) {
|
|
138
|
-
__e.stopPropagation()
|
|
139
|
-
map.doubleClickZoom.enable()
|
|
140
|
-
clearMeasure(map)
|
|
141
|
-
_ele.remove()
|
|
142
|
-
}
|
|
143
|
-
}
|
|
144
|
-
}
|
|
145
|
-
|
|
146
|
-
// 绘制鼠标跟随时的相关内容
|
|
147
|
-
function drawMoveHandler(e) {
|
|
148
|
-
if (isMeasure) {
|
|
149
|
-
const coords = [e.lngLat.lng, e.lngLat.lat]
|
|
150
|
-
const map = e.target
|
|
151
|
-
const len = jsonPoint.features.length
|
|
152
|
-
if (len === 0) {
|
|
153
|
-
measureAreaEle.innerHTML = '点击地图开始测量'
|
|
154
|
-
} else if (len === 1) {
|
|
155
|
-
measureAreaEle.innerHTML = '点击地图继续绘制'
|
|
156
|
-
} else {
|
|
157
|
-
let pts = points.concat([coords])
|
|
158
|
-
pts = pts.concat([points[0]])
|
|
159
|
-
const json = {
|
|
160
|
-
type: 'Feature',
|
|
161
|
-
geometry: {
|
|
162
|
-
type: 'Polygon',
|
|
163
|
-
coordinates: [pts]
|
|
164
|
-
}
|
|
165
|
-
}
|
|
166
|
-
|
|
167
|
-
map.getSource('measure-area-line').setData(json)
|
|
168
|
-
measureAreaEle.innerHTML = getArea(coords)
|
|
169
|
-
}
|
|
170
|
-
measureAreaEle.style.color = textColor
|
|
171
|
-
tooltip.setLngLat(coords)
|
|
172
|
-
}
|
|
173
|
-
}
|
|
174
|
-
|
|
175
|
-
// 清除
|
|
176
|
-
function clearMeasure(map) {
|
|
177
|
-
const measureResult = map._container.querySelectorAll('.measure-area-result')
|
|
178
|
-
if (measureResult && measureResult.length > 0) {
|
|
179
|
-
Array.from(measureResult).forEach((m) => {
|
|
180
|
-
m.remove()
|
|
181
|
-
})
|
|
182
|
-
}
|
|
183
|
-
const json = {
|
|
184
|
-
type: 'FeatureCollection',
|
|
185
|
-
features: []
|
|
186
|
-
}
|
|
187
|
-
const sourceArea = map.getSource('measure-area-points')
|
|
188
|
-
if (sourceArea) {
|
|
189
|
-
map.getSource('measure-area-points').setData(json)
|
|
190
|
-
map.getSource('measure-area-line').setData(json)
|
|
191
|
-
}
|
|
192
|
-
isMeasure = true
|
|
193
|
-
points = []
|
|
194
|
-
jsonPoint = {
|
|
195
|
-
type: 'FeatureCollection',
|
|
196
|
-
features: []
|
|
197
|
-
}
|
|
198
|
-
jsonLine = {
|
|
199
|
-
type: 'FeatureCollection',
|
|
200
|
-
features: []
|
|
201
|
-
}
|
|
202
|
-
measureAreaEle = null
|
|
203
|
-
tooltip = null
|
|
204
|
-
|
|
205
|
-
map.off('click', drawPointHandler)
|
|
206
|
-
map.off('dblclick', drawResultHandler)
|
|
207
|
-
map.off('mousemove', drawMoveHandler)
|
|
208
|
-
}
|
|
209
|
-
|
|
210
|
-
// 关闭测面
|
|
211
|
-
export function closeMeasureArea(map) {
|
|
212
|
-
if (!map) return
|
|
213
|
-
map.doubleClickZoom.enable()
|
|
214
|
-
clearMeasure(map)
|
|
215
|
-
}
|