gis-common 3.1.2 → 3.1.4
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/dist/constant/ErrorTypeConstant.d.ts +23 -0
- package/dist/constant/EventTypeConstant.d.ts +24 -0
- package/dist/constant/GraphicConstant.d.ts +16 -0
- package/dist/constant/LayerType.d.ts +10 -0
- package/dist/constant/index.d.ts +4 -0
- package/dist/gis-common.es.js +1751 -0
- package/dist/gis-common.umd.js +1 -0
- package/dist/index.d.ts +9 -0
- package/dist/utils/Cookie.d.ts +6 -0
- package/dist/utils/MathUtils.d.ts +36 -0
- package/package.json +26 -28
- package/dist/resource.min.js +0 -1
- package/src/assets/images/location.png +0 -0
- package/src/constant/ErrorTypeConstant.js +0 -22
- package/src/constant/EventTypeConstant.js +0 -23
- package/src/constant/GraphicConstant.js +0 -16
- package/src/constant/LayerType.js +0 -9
- package/src/constant/index.js +0 -4
- package/src/core/AudioPlayer.js +0 -30
- package/src/core/CanvasDrawer.js +0 -51
- package/src/core/DevicePixelRatio.js +0 -86
- package/src/core/ElQuery.js +0 -88
- package/src/core/EventDispatcher.js +0 -93
- package/src/core/HashMap.js +0 -26
- package/src/core/MqttClient.js +0 -108
- package/src/core/WebSocketClient.js +0 -104
- package/src/core/WebStorage.js +0 -73
- package/src/index.js +0 -10
- package/src/utils/AnimateUtils.js +0 -78
- package/src/utils/ArrayUtils.js +0 -82
- package/src/utils/AssertUtils.js +0 -112
- package/src/utils/BrowserUtils.js +0 -107
- package/src/utils/CommUtils.js +0 -236
- package/src/utils/Cookie.js +0 -23
- package/src/utils/CoordsUtils.js +0 -145
- package/src/utils/DateUtils.js +0 -144
- package/src/utils/DomUtils.js +0 -94
- package/src/utils/FileUtils.js +0 -104
- package/src/utils/GeoUtils.js +0 -253
- package/src/utils/MathUtils.js +0 -49
- package/src/utils/OptimizeUtils.js +0 -94
- package/src/utils/StringUtils.js +0 -148
- package/src/utils/index.js +0 -14
package/src/utils/DateUtils.js
DELETED
|
@@ -1,144 +0,0 @@
|
|
|
1
|
-
Date.prototype.format = function (fmt) {
|
|
2
|
-
const o = {
|
|
3
|
-
'M+': this.getMonth() + 1, // 月份
|
|
4
|
-
'd+': this.getDate(), // 日
|
|
5
|
-
'h+': this.getHours(), // 小时
|
|
6
|
-
'm+': this.getMinutes(), // 分
|
|
7
|
-
's+': this.getSeconds(), // 秒
|
|
8
|
-
'q+': Math.floor((this.getMonth() + 3) / 3), // 季度
|
|
9
|
-
S: this.getMilliseconds(), // 毫秒
|
|
10
|
-
}
|
|
11
|
-
if (/(y+)/.test(fmt)) fmt = fmt.replace(RegExp.$1, (this.getFullYear() + '').substr(4 - RegExp.$1.length))
|
|
12
|
-
for (const k in o) {
|
|
13
|
-
if (new RegExp('(' + k + ')').test(fmt)) fmt = fmt.replace(RegExp.$1, RegExp.$1.length === 1 ? o[k] : ('00' + o[k]).substr(('' + o[k]).length))
|
|
14
|
-
}
|
|
15
|
-
return fmt
|
|
16
|
-
}
|
|
17
|
-
/**
|
|
18
|
-
* 实现的时间增减功能
|
|
19
|
-
*
|
|
20
|
-
* @param {*} interval 字符串表达式,表示要添加的时间间隔类型
|
|
21
|
-
* @param {*} number 数值表达式,表示要添加的时间间隔的个数
|
|
22
|
-
*/
|
|
23
|
-
Date.prototype.addDate = function (interval, number) {
|
|
24
|
-
const date = new Date(this)
|
|
25
|
-
switch (interval) {
|
|
26
|
-
case 'y':
|
|
27
|
-
date.setFullYear(this.getFullYear() + number)
|
|
28
|
-
break
|
|
29
|
-
case 'q':
|
|
30
|
-
date.setMonth(this.getMonth() + number * 3)
|
|
31
|
-
break
|
|
32
|
-
case 'M':
|
|
33
|
-
date.setMonth(this.getMonth() + number)
|
|
34
|
-
break
|
|
35
|
-
case 'w':
|
|
36
|
-
date.setDate(this.getDate() + number * 7)
|
|
37
|
-
break
|
|
38
|
-
case 'd':
|
|
39
|
-
date.setDate(this.getDate() + number)
|
|
40
|
-
break
|
|
41
|
-
case 'h':
|
|
42
|
-
date.setHours(this.getHours() + number)
|
|
43
|
-
break
|
|
44
|
-
case 'm':
|
|
45
|
-
date.setMinutes(this.getMinutes() + number)
|
|
46
|
-
break
|
|
47
|
-
case 's':
|
|
48
|
-
date.setSeconds(this.getSeconds() + number)
|
|
49
|
-
break
|
|
50
|
-
default:
|
|
51
|
-
date.setDate(this.getDate() + number)
|
|
52
|
-
break
|
|
53
|
-
}
|
|
54
|
-
return date
|
|
55
|
-
}
|
|
56
|
-
export default {
|
|
57
|
-
lastMonthDate: new Date(new Date().getFullYear(), new Date().getMonth() - 1, 1),
|
|
58
|
-
thisMonthDate: new Date(new Date().getFullYear(), new Date().getMonth(), 1),
|
|
59
|
-
nextMonthDate: new Date(new Date().getFullYear(), new Date().getMonth() + 1, 1),
|
|
60
|
-
lastWeekDate: new Date(new Date().getFullYear(), new Date().getMonth(), new Date().getDate() + 1 - 7 - new Date().getDay()),
|
|
61
|
-
thisWeekDate: new Date(new Date().getFullYear(), new Date().getMonth(), new Date().getDate() + 1 - new Date().getDay()),
|
|
62
|
-
nextWeekDate: new Date(new Date().getFullYear(), new Date().getMonth(), new Date().getDate() + 1 + 7 - new Date().getDay()),
|
|
63
|
-
lastDayDate: new Date(new Date().getFullYear(), new Date().getMonth(), new Date().getDate() - 1),
|
|
64
|
-
thisDayDate: new Date(new Date().setHours(0, 0, 0, 0)),
|
|
65
|
-
nextDayDate: new Date(new Date().getFullYear(), new Date().getMonth(), new Date().getDate() + 1),
|
|
66
|
-
parseDate(str) {
|
|
67
|
-
if (typeof str == 'string') {
|
|
68
|
-
var results = str.match(/^ *(\d{4})-(\d{1,2})-(\d{1,2}) *$/)
|
|
69
|
-
if (results && results.length > 3) return new Date(parseInt(results[1]), parseInt(results[2]) - 1, parseInt(results[3]))
|
|
70
|
-
results = str.match(/^ *(\d{4})-(\d{1,2})-(\d{1,2}) +(\d{1,2}):(\d{1,2}):(\d{1,2}) *$/)
|
|
71
|
-
if (results && results.length > 6)
|
|
72
|
-
return new Date(
|
|
73
|
-
parseInt(results[1]),
|
|
74
|
-
parseInt(results[2]) - 1,
|
|
75
|
-
parseInt(results[3]),
|
|
76
|
-
parseInt(results[4]),
|
|
77
|
-
parseInt(results[5]),
|
|
78
|
-
parseInt(results[6])
|
|
79
|
-
)
|
|
80
|
-
results = str.match(/^ *(\d{4})-(\d{1,2})-(\d{1,2}) +(\d{1,2}):(\d{1,2}):(\d{1,2})\.(\d{1,9}) *$/)
|
|
81
|
-
if (results && results.length > 7)
|
|
82
|
-
return new Date(
|
|
83
|
-
parseInt(results[1]),
|
|
84
|
-
parseInt(results[2]) - 1,
|
|
85
|
-
parseInt(results[3]),
|
|
86
|
-
parseInt(results[4]),
|
|
87
|
-
parseInt(results[5]),
|
|
88
|
-
parseInt(results[6]),
|
|
89
|
-
parseInt(results[7])
|
|
90
|
-
)
|
|
91
|
-
}
|
|
92
|
-
return null
|
|
93
|
-
},
|
|
94
|
-
/**
|
|
95
|
-
* 将时间间隔转换成中国话
|
|
96
|
-
*
|
|
97
|
-
* @param {*} startTime
|
|
98
|
-
* @param {*} endTime
|
|
99
|
-
* @returns {*}
|
|
100
|
-
*/
|
|
101
|
-
formatDateInterval(startTime, endTime) {
|
|
102
|
-
const dateCreateTime = new Date(startTime)
|
|
103
|
-
const dateFinishTime = new Date(endTime)
|
|
104
|
-
const dateInterval = dateFinishTime.getTime() - dateCreateTime.getTime()
|
|
105
|
-
const days = Math.floor(dateInterval / (24 * 3600 * 1000))
|
|
106
|
-
const leave1 = dateInterval % (24 * 3600 * 1000)
|
|
107
|
-
const hours = Math.floor(leave1 / (3600 * 1000))
|
|
108
|
-
const leave2 = leave1 % (3600 * 1000)
|
|
109
|
-
const minutes = Math.floor(leave2 / (60 * 1000))
|
|
110
|
-
const leave3 = leave2 % (60 * 1000)
|
|
111
|
-
const seconds = Math.round(leave3 / 1000)
|
|
112
|
-
let intervalDes = ''
|
|
113
|
-
if (days > 0) {
|
|
114
|
-
intervalDes += days + '天'
|
|
115
|
-
}
|
|
116
|
-
if (hours > 0) {
|
|
117
|
-
intervalDes += hours + '时'
|
|
118
|
-
}
|
|
119
|
-
if (minutes > 0) {
|
|
120
|
-
intervalDes += minutes + '分'
|
|
121
|
-
}
|
|
122
|
-
if (seconds > 0) {
|
|
123
|
-
intervalDes += seconds + '秒'
|
|
124
|
-
}
|
|
125
|
-
if (days === 0 && hours === 0 && minutes === 0 && seconds === 0) {
|
|
126
|
-
intervalDes = '少于1秒'
|
|
127
|
-
}
|
|
128
|
-
return intervalDes
|
|
129
|
-
},
|
|
130
|
-
formatterCounter(times) {
|
|
131
|
-
const checked = function (j) {
|
|
132
|
-
return (j > 10 ? '' : '0') + (j || 0)
|
|
133
|
-
}
|
|
134
|
-
const houres = checked(Math.floor(times / 3600))
|
|
135
|
-
const level1 = times % 3600
|
|
136
|
-
const minutes = checked(Math.floor(level1 / 60))
|
|
137
|
-
const leave2 = level1 % 60
|
|
138
|
-
const seconds = checked(Math.round(leave2))
|
|
139
|
-
return `${houres}:${minutes}:${seconds}`
|
|
140
|
-
},
|
|
141
|
-
sleep(d) {
|
|
142
|
-
for (let t = Date.now(); Date.now() - t <= d; );
|
|
143
|
-
},
|
|
144
|
-
}
|
package/src/utils/DomUtils.js
DELETED
|
@@ -1,94 +0,0 @@
|
|
|
1
|
-
function trim(str) {
|
|
2
|
-
return str.trim ? str.trim() : str.replace(/^\s+|\s+$/g, '')
|
|
3
|
-
}
|
|
4
|
-
function splitWords(str) {
|
|
5
|
-
return trim(str).split(/\s+/)
|
|
6
|
-
}
|
|
7
|
-
export default {
|
|
8
|
-
getStyle(el, style) {
|
|
9
|
-
let value = el.style[style] || (el.currentStyle && el.currentStyle[style])
|
|
10
|
-
|
|
11
|
-
if ((!value || value === 'auto') && document.defaultView) {
|
|
12
|
-
const css = document.defaultView.getComputedStyle(el, null)
|
|
13
|
-
value = css ? css[style] : null
|
|
14
|
-
}
|
|
15
|
-
return value === 'auto' ? null : value
|
|
16
|
-
},
|
|
17
|
-
create(tagName, className, container) {
|
|
18
|
-
const el = document.createElement(tagName)
|
|
19
|
-
el.className = className || ''
|
|
20
|
-
|
|
21
|
-
if (container) {
|
|
22
|
-
container.appendChild(el)
|
|
23
|
-
}
|
|
24
|
-
return el
|
|
25
|
-
},
|
|
26
|
-
remove(el) {
|
|
27
|
-
const parent = el.parentNode
|
|
28
|
-
if (parent) {
|
|
29
|
-
parent.removeChild(el)
|
|
30
|
-
}
|
|
31
|
-
},
|
|
32
|
-
empty(el) {
|
|
33
|
-
while (el.firstChild) {
|
|
34
|
-
el.removeChild(el.firstChild)
|
|
35
|
-
}
|
|
36
|
-
},
|
|
37
|
-
toFront(el) {
|
|
38
|
-
const parent = el.parentNode
|
|
39
|
-
if (parent && parent.lastChild !== el) {
|
|
40
|
-
parent.appendChild(el)
|
|
41
|
-
}
|
|
42
|
-
},
|
|
43
|
-
toBack(el) {
|
|
44
|
-
const parent = el.parentNode
|
|
45
|
-
if (parent && parent.firstChild !== el) {
|
|
46
|
-
parent.insertBefore(el, parent.firstChild)
|
|
47
|
-
}
|
|
48
|
-
},
|
|
49
|
-
getClass(el) {
|
|
50
|
-
if (el.correspondingElement) {
|
|
51
|
-
el = el.correspondingElement
|
|
52
|
-
}
|
|
53
|
-
return el.className.baseVal === undefined ? el.className : el.className.baseVal
|
|
54
|
-
},
|
|
55
|
-
hasClass(el, name) {
|
|
56
|
-
if (el.classList !== undefined) {
|
|
57
|
-
return el.classList.contains(name)
|
|
58
|
-
}
|
|
59
|
-
const className = this.getClass(el)
|
|
60
|
-
return className.length > 0 && new RegExp('(^|\\s)' + name + '(\\s|$)').test(className)
|
|
61
|
-
},
|
|
62
|
-
addClass(el, name) {
|
|
63
|
-
if (el.classList !== undefined) {
|
|
64
|
-
const classes = splitWords(name)
|
|
65
|
-
for (let i = 0, len = classes.length; i < len; i++) {
|
|
66
|
-
el.classList.add(classes[i])
|
|
67
|
-
}
|
|
68
|
-
} else if (!this.hasClass(el, name)) {
|
|
69
|
-
const className = this.getClass(el)
|
|
70
|
-
this.setClass(el, (className ? className + ' ' : '') + name)
|
|
71
|
-
}
|
|
72
|
-
},
|
|
73
|
-
removeClass(el, name) {
|
|
74
|
-
if (el.classList !== undefined) {
|
|
75
|
-
const classes = splitWords(name)
|
|
76
|
-
classes.forEach((name) => el.classList.remove(name))
|
|
77
|
-
} else {
|
|
78
|
-
this.setClass(el, trim((' ' + this.getClass(el) + ' ').replace(' ' + name + ' ', ' ')))
|
|
79
|
-
}
|
|
80
|
-
},
|
|
81
|
-
setClass(el, name) {
|
|
82
|
-
if (el.className.baseVal === undefined) {
|
|
83
|
-
el.className = name
|
|
84
|
-
} else {
|
|
85
|
-
// in case of SVG element
|
|
86
|
-
el.className.baseVal = name
|
|
87
|
-
}
|
|
88
|
-
},
|
|
89
|
-
parseFromString(str) {
|
|
90
|
-
const parser = new DOMParser()
|
|
91
|
-
const doc = parser.parseFromString(str, 'text/xml')
|
|
92
|
-
return doc.children[0]
|
|
93
|
-
},
|
|
94
|
-
}
|
package/src/utils/FileUtils.js
DELETED
|
@@ -1,104 +0,0 @@
|
|
|
1
|
-
export default {
|
|
2
|
-
/**
|
|
3
|
-
* 将base64类型编码的图片转换成blob类型
|
|
4
|
-
*
|
|
5
|
-
* @param {*} data
|
|
6
|
-
* @returns {*}
|
|
7
|
-
*/
|
|
8
|
-
convertBase64ToBlob(data) {
|
|
9
|
-
var mimeString = data.split(',')[0].split(':')[1].split(';')[0]
|
|
10
|
-
var byteString = window.atob(data.split(',')[1])
|
|
11
|
-
var ab = new ArrayBuffer(byteString.length)
|
|
12
|
-
var ia = new Uint8Array(ab)
|
|
13
|
-
|
|
14
|
-
for (var i = 0; i < byteString.length; i++) {
|
|
15
|
-
ia[i] = byteString.charCodeAt(i)
|
|
16
|
-
}
|
|
17
|
-
var bb = window.BlobBuilder || window.WebKitBlobBuilder || window.MozBlobBuilder
|
|
18
|
-
|
|
19
|
-
if (bb) {
|
|
20
|
-
bb = new (window.BlobBuilder || window.WebKitBlobBuilder || window.MozBlobBuilder)()
|
|
21
|
-
bb.append(ab)
|
|
22
|
-
return bb.getBlob(mimeString)
|
|
23
|
-
} else {
|
|
24
|
-
bb = new Blob([ab], {
|
|
25
|
-
type: mimeString,
|
|
26
|
-
})
|
|
27
|
-
return bb
|
|
28
|
-
}
|
|
29
|
-
},
|
|
30
|
-
/**
|
|
31
|
-
* 将url图片转换成base64编码的图片,也可用于图片压缩
|
|
32
|
-
*
|
|
33
|
-
* @param {*} url 需要转换的图片url
|
|
34
|
-
* @param {*} width 指定宽高,如未指定则使用默认宽度
|
|
35
|
-
* @param {*} height
|
|
36
|
-
* @returns {*}
|
|
37
|
-
*/
|
|
38
|
-
convertUrlToBase64(url, width, height) {
|
|
39
|
-
return new Promise(function (resolve, reject) {
|
|
40
|
-
var img = new Image()
|
|
41
|
-
img.crossOrigin = 'Anonymous'
|
|
42
|
-
img.src = url
|
|
43
|
-
img.onload = function () {
|
|
44
|
-
var canvas = document.createElement('canvas')
|
|
45
|
-
canvas.width = width || img.width
|
|
46
|
-
canvas.height = height || img.height
|
|
47
|
-
var ctx = canvas.getContext('2d')
|
|
48
|
-
ctx.drawImage(img, 0, 0, img.width, img.height)
|
|
49
|
-
var ext = img.src.substring(img.src.lastIndexOf('.') + 1).toLowerCase()
|
|
50
|
-
var dataURL = canvas.toDataURL('image/' + ext)
|
|
51
|
-
var base64 = {
|
|
52
|
-
dataURL: dataURL,
|
|
53
|
-
type: 'image/' + ext,
|
|
54
|
-
ext: ext,
|
|
55
|
-
}
|
|
56
|
-
resolve(base64)
|
|
57
|
-
}
|
|
58
|
-
})
|
|
59
|
-
},
|
|
60
|
-
/**
|
|
61
|
-
* 将base64类型编码的图片转换成file类型
|
|
62
|
-
*
|
|
63
|
-
* @param {*} dataurl
|
|
64
|
-
* @param {*} filename
|
|
65
|
-
* @returns {*}
|
|
66
|
-
*/
|
|
67
|
-
convertBase64ToFile(dataurl, filename) {
|
|
68
|
-
var arr = dataurl.split(','),
|
|
69
|
-
mime = arr[0].match(/:(.*?);/)[1],
|
|
70
|
-
bstr = atob(arr[1]),
|
|
71
|
-
n = bstr.length,
|
|
72
|
-
u8arr = new Uint8Array(n)
|
|
73
|
-
while (n--) {
|
|
74
|
-
u8arr[n] = bstr.charCodeAt(n)
|
|
75
|
-
}
|
|
76
|
-
let file = new File([u8arr], filename, { type: mime })
|
|
77
|
-
return file
|
|
78
|
-
},
|
|
79
|
-
/**
|
|
80
|
-
* 直接下载文件,支持blob类型和url类型
|
|
81
|
-
*
|
|
82
|
-
* @param {*} data
|
|
83
|
-
* @param {*} saveName
|
|
84
|
-
*/
|
|
85
|
-
downloadFromFile(data, saveName) {
|
|
86
|
-
if (typeof data == 'object') {
|
|
87
|
-
if (data instanceof Blob) {
|
|
88
|
-
data = URL.createObjectURL(data) // 创建blob地址
|
|
89
|
-
} else {
|
|
90
|
-
const str = JSON.stringify(data)
|
|
91
|
-
const blob = new Blob([str], { type: 'text/json' }) // json对象
|
|
92
|
-
data = window.URL.createObjectURL(blob)
|
|
93
|
-
}
|
|
94
|
-
} else if (typeof data == 'string' && data.indexOf('http') === -1) {
|
|
95
|
-
const blob = new Blob([data], { type: 'text/json' }) //json文本
|
|
96
|
-
data = window.URL.createObjectURL(blob)
|
|
97
|
-
}
|
|
98
|
-
var link = document.createElement('a')
|
|
99
|
-
link.href = data
|
|
100
|
-
link.download = saveName || '' // HTML5新增的属性,指定保存文件名,可以不要后缀,注意,file:///模式下不会生效
|
|
101
|
-
link.click()
|
|
102
|
-
window.URL.revokeObjectURL(link.href)
|
|
103
|
-
},
|
|
104
|
-
}
|
package/src/utils/GeoUtils.js
DELETED
|
@@ -1,253 +0,0 @@
|
|
|
1
|
-
import MathUtils from './MathUtils'
|
|
2
|
-
export default {
|
|
3
|
-
toRadian: Math.PI / 180,
|
|
4
|
-
R: 6371393,
|
|
5
|
-
/**
|
|
6
|
-
* 验证经纬度坐标
|
|
7
|
-
*
|
|
8
|
-
* @param {*} lng
|
|
9
|
-
* @param {*} lat
|
|
10
|
-
* @returns {*} {boolean}
|
|
11
|
-
*/
|
|
12
|
-
isLnglat(lng, lat) {
|
|
13
|
-
return lng && lat && !!(+lat > -90 && +lat < 90 && +lng > -180 && +lng < 180)
|
|
14
|
-
},
|
|
15
|
-
/**
|
|
16
|
-
* 格式化经纬度(转度分秒)
|
|
17
|
-
*
|
|
18
|
-
* @param {*} lng
|
|
19
|
-
* @param {*} lat
|
|
20
|
-
* @returns {*}
|
|
21
|
-
*/
|
|
22
|
-
formatLnglat(lng, lat) {
|
|
23
|
-
let res = ''
|
|
24
|
-
function format(value) {
|
|
25
|
-
const a = parseFloat(value)
|
|
26
|
-
const degree = parseInt(a)
|
|
27
|
-
let min = parseInt((a - degree) * 60)
|
|
28
|
-
let sec = (a - degree) * 3600 - min * 60
|
|
29
|
-
return degree + '°' + min + '′' + sec.toFixed(2) + '″'
|
|
30
|
-
}
|
|
31
|
-
if (lng && lat) {
|
|
32
|
-
res = format(lng) + ',' + format(lat)
|
|
33
|
-
}
|
|
34
|
-
return res
|
|
35
|
-
},
|
|
36
|
-
/**
|
|
37
|
-
* 度分秒转十进制
|
|
38
|
-
*
|
|
39
|
-
* @param {*} lng
|
|
40
|
-
* @param {*} lat
|
|
41
|
-
* @returns {*}
|
|
42
|
-
*/
|
|
43
|
-
transformLnglat(lng, lat) {
|
|
44
|
-
function dms2deg(s) {
|
|
45
|
-
var sw = /[sw]/i.test(s)
|
|
46
|
-
var f = sw ? -1 : 1
|
|
47
|
-
var bits = s.match(/[\d.]+/g)
|
|
48
|
-
var result = 0
|
|
49
|
-
for (var i = 0, iLen = bits.length; i < iLen; i++) {
|
|
50
|
-
result += bits[i] / f
|
|
51
|
-
f *= 60
|
|
52
|
-
}
|
|
53
|
-
return result
|
|
54
|
-
}
|
|
55
|
-
if (lng && lat) {
|
|
56
|
-
return {
|
|
57
|
-
lng: dms2deg(lng),
|
|
58
|
-
lat: dms2deg(lat),
|
|
59
|
-
}
|
|
60
|
-
}
|
|
61
|
-
},
|
|
62
|
-
/**
|
|
63
|
-
* 判断点是否在多边形内
|
|
64
|
-
*
|
|
65
|
-
* @param {*} p
|
|
66
|
-
* @param {*} poly
|
|
67
|
-
* @returns {*}
|
|
68
|
-
*/
|
|
69
|
-
rayCasting(p, poly) {
|
|
70
|
-
var px = p.x,
|
|
71
|
-
py = p.y,
|
|
72
|
-
flag = false
|
|
73
|
-
for (var i = 0, l = poly.length, j = l - 1; i < l; j = i, i++) {
|
|
74
|
-
var sx = poly[i].x,
|
|
75
|
-
sy = poly[i].y,
|
|
76
|
-
tx = poly[j].x,
|
|
77
|
-
ty = poly[j].y
|
|
78
|
-
// 点与多边形顶点重合
|
|
79
|
-
if ((sx === px && sy === py) || (tx === px && ty === py)) {
|
|
80
|
-
return 'on'
|
|
81
|
-
}
|
|
82
|
-
// 判断线段两端点是否在射线两侧
|
|
83
|
-
if ((sy < py && ty >= py) || (sy >= py && ty < py)) {
|
|
84
|
-
// 线段上与射线 Y 坐标相同的点的 X 坐标
|
|
85
|
-
var x = sx + ((py - sy) * (tx - sx)) / (ty - sy)
|
|
86
|
-
// 点在多边形的边上
|
|
87
|
-
if (x === px) {
|
|
88
|
-
return 'on'
|
|
89
|
-
}
|
|
90
|
-
// 射线穿过多边形的边界
|
|
91
|
-
if (x > px) {
|
|
92
|
-
flag = !flag
|
|
93
|
-
}
|
|
94
|
-
}
|
|
95
|
-
}
|
|
96
|
-
// 射线穿过多边形边界的次数为奇数时点在多边形内
|
|
97
|
-
return flag ? 'in' : 'out'
|
|
98
|
-
},
|
|
99
|
-
/**
|
|
100
|
-
* 计算两点距离
|
|
101
|
-
*
|
|
102
|
-
* @param {*} fromPoint
|
|
103
|
-
* @param {*} toPoint
|
|
104
|
-
* @returns {*}
|
|
105
|
-
*/
|
|
106
|
-
wgs84PointsDistance(fromPoint, toPoint) {
|
|
107
|
-
var PI = Math.PI
|
|
108
|
-
function getRad(d) {
|
|
109
|
-
return (d * PI) / 180.0
|
|
110
|
-
}
|
|
111
|
-
if (arguments.length != 2) {
|
|
112
|
-
return 0
|
|
113
|
-
}
|
|
114
|
-
lon1 = fromPoint.x
|
|
115
|
-
lat1 = fromPoint.y
|
|
116
|
-
lon2 = toPoint.x
|
|
117
|
-
lat2 = toPoint.y
|
|
118
|
-
var a = 6378137,
|
|
119
|
-
b = 6356752.3142,
|
|
120
|
-
f = 1 / 298.257223563
|
|
121
|
-
var L = getRad(lon2 - lon1)
|
|
122
|
-
var U1 = Math.atan((1 - f) * Math.tan(getRad(lat1)))
|
|
123
|
-
var U2 = Math.atan((1 - f) * Math.tan(getRad(lat2)))
|
|
124
|
-
var sinU1 = Math.sin(U1),
|
|
125
|
-
cosU1 = Math.cos(U1)
|
|
126
|
-
var sinU2 = Math.sin(U2),
|
|
127
|
-
cosU2 = Math.cos(U2)
|
|
128
|
-
var lambda = L,
|
|
129
|
-
lambdaP,
|
|
130
|
-
iterLimit = 100
|
|
131
|
-
do {
|
|
132
|
-
var sinLambda = Math.sin(lambda),
|
|
133
|
-
cosLambda = Math.cos(lambda)
|
|
134
|
-
var sinSigma = Math.sqrt(
|
|
135
|
-
cosU2 * sinLambda * (cosU2 * sinLambda) + (cosU1 * sinU2 - sinU1 * cosU2 * cosLambda) * (cosU1 * sinU2 - sinU1 * cosU2 * cosLambda)
|
|
136
|
-
)
|
|
137
|
-
if (sinSigma == 0) return 0
|
|
138
|
-
var cosSigma = sinU1 * sinU2 + cosU1 * cosU2 * cosLambda
|
|
139
|
-
var sigma = Math.atan2(sinSigma, cosSigma)
|
|
140
|
-
var sinAlpha = (cosU1 * cosU2 * sinLambda) / sinSigma
|
|
141
|
-
var cosSqAlpha = 1 - sinAlpha * sinAlpha
|
|
142
|
-
var cos2SigmaM = cosSigma - (2 * sinU1 * sinU2) / cosSqAlpha
|
|
143
|
-
if (isNaN(cos2SigmaM)) cos2SigmaM = 0
|
|
144
|
-
var C = (f / 16) * cosSqAlpha * (4 + f * (4 - 3 * cosSqAlpha))
|
|
145
|
-
lambdaP = lambda
|
|
146
|
-
lambda = L + (1 - C) * f * sinAlpha * (sigma + C * sinSigma * (cos2SigmaM + C * cosSigma * (-1 + 2 * cos2SigmaM * cos2SigmaM)))
|
|
147
|
-
} while (Math.abs(lambda - lambdaP) > 1e-12 && --iterLimit > 0)
|
|
148
|
-
if (iterLimit == 0) {
|
|
149
|
-
return NaN
|
|
150
|
-
}
|
|
151
|
-
var uSq = (cosSqAlpha * (a * a - b * b)) / (b * b)
|
|
152
|
-
var A = 1 + (uSq / 16384) * (4096 + uSq * (-768 + uSq * (320 - 175 * uSq)))
|
|
153
|
-
var B = (uSq / 1024) * (256 + uSq * (-128 + uSq * (74 - 47 * uSq)))
|
|
154
|
-
var deltaSigma =
|
|
155
|
-
B *
|
|
156
|
-
sinSigma *
|
|
157
|
-
(cos2SigmaM +
|
|
158
|
-
(B / 4) *
|
|
159
|
-
(cosSigma * (-1 + 2 * cos2SigmaM * cos2SigmaM) -
|
|
160
|
-
(B / 6) * cos2SigmaM * (-3 + 4 * sinSigma * sinSigma) * (-3 + 4 * cos2SigmaM * cos2SigmaM)))
|
|
161
|
-
var s = b * A * (sigma - deltaSigma)
|
|
162
|
-
var fwdAz = Math.atan2(cosU2 * sinLambda, cosU1 * sinU2 - sinU1 * cosU2 * cosLambda)
|
|
163
|
-
var revAz = Math.atan2(cosU1 * sinLambda, -sinU1 * cosU2 + cosU1 * sinU2 * cosLambda)
|
|
164
|
-
return s
|
|
165
|
-
},
|
|
166
|
-
/**
|
|
167
|
-
* P1绕一个坐标点P2旋转θ角度后,新的坐标的计算公式
|
|
168
|
-
*
|
|
169
|
-
* @param {*} p1
|
|
170
|
-
* @param {*} p2
|
|
171
|
-
* @param {*} θ 旋转角度,正:表示顺时针,负:表示逆时针
|
|
172
|
-
*/
|
|
173
|
-
rotatePoint(p1, p2, θ) {
|
|
174
|
-
const x = (p1.x - p2.x) * Math.cos((Math.PI / 180) * -θ) - (p1.y - p2.y) * Math.sin((Math.PI / 180) * -θ) + p2.x
|
|
175
|
-
const y = (p1.x - p2.x) * Math.sin((Math.PI / 180) * -θ) + (p1.y - p2.y) * Math.cos((Math.PI / 180) * -θ) + p2.y
|
|
176
|
-
return { x, y }
|
|
177
|
-
},
|
|
178
|
-
calcBearAndDis(p1, p2) {
|
|
179
|
-
const { x: x1, y: y1 } = p1
|
|
180
|
-
const { x: x2, y: y2 } = p2
|
|
181
|
-
const dx = x2 - x1
|
|
182
|
-
const dy = y2 - y1
|
|
183
|
-
const distance = Math.sqrt(dx * dx + dy * dy)
|
|
184
|
-
const angleInRadians = Math.atan2(dy, dx)
|
|
185
|
-
const angle = (angleInRadians * (180 / Math.PI) + 360 + 90) % 360
|
|
186
|
-
return { angle, distance }
|
|
187
|
-
},
|
|
188
|
-
/**
|
|
189
|
-
* 计算latlng2相对于latlng1的方位角和距离
|
|
190
|
-
*
|
|
191
|
-
* @param {*} latlng1
|
|
192
|
-
* @param {*} latlng2
|
|
193
|
-
* @returns {*} {boolean}
|
|
194
|
-
*/
|
|
195
|
-
calcBearAndDisByPoints(latlng1, latlng2) {
|
|
196
|
-
var f1 = parseFloat(latlng1.lat),
|
|
197
|
-
l1 = parseFloat(latlng1.lng),
|
|
198
|
-
f2 = parseFloat(latlng2.lat),
|
|
199
|
-
l2 = parseFloat(latlng2.lng)
|
|
200
|
-
var y = Math.sin((l2 - l1) * this.toRadian) * Math.cos(f2 * this.toRadian)
|
|
201
|
-
var x =
|
|
202
|
-
Math.cos(f1 * this.toRadian) * Math.sin(f2 * this.toRadian) -
|
|
203
|
-
Math.sin(f1 * this.toRadian) * Math.cos(f2 * this.toRadian) * Math.cos((l2 - l1) * this.toRadian)
|
|
204
|
-
var angle = Math.atan2(y, x) * (180 / Math.PI)
|
|
205
|
-
var deltaF = (f2 - f1) * this.toRadian
|
|
206
|
-
var deltaL = (l2 - l1) * this.toRadian
|
|
207
|
-
var a =
|
|
208
|
-
Math.sin(deltaF / 2) * Math.sin(deltaF / 2) +
|
|
209
|
-
Math.cos(f1 * this.toRadian) * Math.cos(f2 * this.toRadian) * Math.sin(deltaL / 2) * Math.sin(deltaL / 2)
|
|
210
|
-
var c = 2 * Math.atan2(Math.sqrt(a), Math.sqrt(1 - a))
|
|
211
|
-
var distance = this.R * c
|
|
212
|
-
return {
|
|
213
|
-
angle,
|
|
214
|
-
distance,
|
|
215
|
-
}
|
|
216
|
-
},
|
|
217
|
-
|
|
218
|
-
/**
|
|
219
|
-
* 根据方位角和距离生成新的坐标
|
|
220
|
-
*
|
|
221
|
-
* @param {*} latlng
|
|
222
|
-
* @param {*} angle
|
|
223
|
-
* @param {*} distance
|
|
224
|
-
* @returns {*}
|
|
225
|
-
*/
|
|
226
|
-
calcPointByBearAndDis(latlng, angle, distance) {
|
|
227
|
-
const sLat = MathUtils.toRadians(parseFloat(latlng.lat))
|
|
228
|
-
const sLng = MathUtils.toRadians(parseFloat(latlng.lng))
|
|
229
|
-
angle = parseFloat(angle)
|
|
230
|
-
distance = parseFloat(distance)
|
|
231
|
-
const d = distance / this.R
|
|
232
|
-
angle = MathUtils.toRadians(angle)
|
|
233
|
-
const lat = Math.asin(Math.sin(sLat) * Math.cos(d) + Math.cos(sLat) * Math.sin(d) * Math.cos(angle))
|
|
234
|
-
const lon = sLng + Math.atan2(Math.sin(angle) * Math.sin(d) * Math.cos(sLat), Math.cos(d) - Math.sin(sLat) * Math.sin(lat))
|
|
235
|
-
return {
|
|
236
|
-
lat: MathUtils.toDegrees(lat),
|
|
237
|
-
lng: MathUtils.toDegrees(lon),
|
|
238
|
-
}
|
|
239
|
-
},
|
|
240
|
-
mercatorTolonlat(x, y) {
|
|
241
|
-
const lng = (x / 20037508.34) * 180
|
|
242
|
-
var mmy = (y / 20037508.34) * 180
|
|
243
|
-
const lat = (180 / Math.PI) * (2 * Math.atan(Math.exp((mmy * Math.PI) / 180)) - Math.PI / 2)
|
|
244
|
-
return { lng, lat }
|
|
245
|
-
},
|
|
246
|
-
lonlatToMercator(lng, lat) {
|
|
247
|
-
var earthRad = 6378137.0
|
|
248
|
-
const x = ((lng * Math.PI) / 180) * earthRad
|
|
249
|
-
var a = (lat * Math.PI) / 180
|
|
250
|
-
const y = (earthRad / 2) * Math.log((1.0 + Math.sin(a)) / (1.0 - Math.sin(a)))
|
|
251
|
-
return { x, y }
|
|
252
|
-
},
|
|
253
|
-
}
|
package/src/utils/MathUtils.js
DELETED
|
@@ -1,49 +0,0 @@
|
|
|
1
|
-
export default {
|
|
2
|
-
DEG2RAD: Math.PI / 180,
|
|
3
|
-
RAD2DEG: 180 / Math.PI,
|
|
4
|
-
randInt(low, high) {
|
|
5
|
-
return low + Math.floor(Math.random() * (high - low + 1))
|
|
6
|
-
},
|
|
7
|
-
randFloat(low, high) {
|
|
8
|
-
return low + Math.random() * (high - low)
|
|
9
|
-
},
|
|
10
|
-
/**
|
|
11
|
-
* 角度转弧度
|
|
12
|
-
*
|
|
13
|
-
* @param {*} degrees
|
|
14
|
-
* @returns {*}
|
|
15
|
-
*/
|
|
16
|
-
degreesToRadians(degrees) {
|
|
17
|
-
return degrees * this.DEG2RAD
|
|
18
|
-
},
|
|
19
|
-
/**
|
|
20
|
-
* 角度转弧度
|
|
21
|
-
*
|
|
22
|
-
* @param {*} degrees
|
|
23
|
-
* @returns {*}
|
|
24
|
-
*/
|
|
25
|
-
toRadians(degrees) {
|
|
26
|
-
return degrees * this.DEG2RAD
|
|
27
|
-
},
|
|
28
|
-
/**
|
|
29
|
-
* 弧度转角度
|
|
30
|
-
*
|
|
31
|
-
* @param {*} radians
|
|
32
|
-
* @returns {*}
|
|
33
|
-
*/
|
|
34
|
-
radiansToDegrees(radians) {
|
|
35
|
-
return radians * this.RAD2DEG
|
|
36
|
-
},
|
|
37
|
-
/**
|
|
38
|
-
* 弧度转角度
|
|
39
|
-
*
|
|
40
|
-
* @param {*} radians
|
|
41
|
-
* @returns {*}
|
|
42
|
-
*/
|
|
43
|
-
toDegrees(radians) {
|
|
44
|
-
return radians * this.RAD2DEG
|
|
45
|
-
},
|
|
46
|
-
formatFloat(value, n = 2) {
|
|
47
|
-
return Math.round(value * Math.pow(10, n)) / Math.pow(10, n)
|
|
48
|
-
},
|
|
49
|
-
}
|