af-mobile-client-vue3 1.1.6 → 1.1.7
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/.env +6 -6
- package/.env.development +4 -4
- package/.env.envoiceShow +6 -6
- package/.env.production +6 -6
- package/.husky/commit-msg +1 -1
- package/.husky/pre-commit +1 -1
- package/.vscode/settings.json +61 -61
- package/mock/modules/user.mock.ts +152 -152
- package/package.json +1 -1
- package/public/favicon.svg +4 -4
- package/public/safari-pinned-tab.svg +32 -32
- package/scripts/verifyCommit.js +19 -19
- package/src/App.vue +43 -43
- package/src/api/user/index.ts +40 -40
- package/src/bootstrap.ts +18 -18
- package/src/components/core/NavBar/index.vue +12 -12
- package/src/components/core/Tabbar/index.vue +38 -38
- package/src/components/core/XGridDropOption/index.vue +151 -151
- package/src/components/core/XMultiSelect/index.vue +183 -183
- package/src/components/data/XCellDetail/index.vue +106 -106
- package/src/components/data/XForm/index.vue +5 -0
- package/src/components/data/XFormItem/index.vue +3 -4
- package/src/components/data/XOlMap/README.md +0 -2
- package/src/components/data/XOlMap/XLocationPicker/index.vue +21 -9
- package/src/components/data/XOlMap/index.vue +81 -74
- package/src/components/data/XOlMap/types.ts +0 -4
- package/src/components/data/XOlMap/utils/wgs84ToGcj02.js +154 -154
- package/src/components/data/XReportForm/XReportFormJsonRender.vue +220 -220
- package/src/components/data/XReportForm/index.vue +1079 -1079
- package/src/components/data/XReportGrid/XAddReport/index.ts +1 -1
- package/src/components/data/XReportGrid/XReportDrawer/index.ts +1 -1
- package/src/components/data/XSignature/index.vue +285 -285
- package/src/components/data/XTag/index.vue +10 -10
- package/src/components/layout/NormalDataLayout/index.vue +70 -70
- package/src/components/layout/TabBarLayout/index.vue +40 -40
- package/src/components.d.ts +53 -53
- package/src/env.d.ts +16 -16
- package/src/font-style/font.css +3 -3
- package/src/hooks/useCommon.ts +9 -9
- package/src/locales/en-US.json +25 -25
- package/src/locales/zh-CN.json +25 -25
- package/src/plugins/AppData.ts +38 -38
- package/src/router/guards.ts +59 -59
- package/src/router/index.ts +61 -61
- package/src/router/invoiceRoutes.ts +33 -33
- package/src/services/api/common.ts +109 -109
- package/src/services/api/manage.ts +8 -8
- package/src/services/api/search.ts +16 -16
- package/src/services/restTools.ts +56 -56
- package/src/services/v3Api.ts +11 -11
- package/src/stores/modules/setting.ts +52 -52
- package/src/stores/mutation-type.ts +7 -7
- package/src/utils/authority-utils.ts +84 -84
- package/src/utils/crypto.ts +39 -39
- package/src/utils/i18n.ts +41 -41
- package/src/utils/indexedDB.ts +180 -180
- package/src/utils/mobileUtil.ts +26 -26
- package/src/utils/routerUtil.ts +271 -271
- package/src/utils/runEvalFunction.ts +13 -13
- package/src/utils/wechatUtil.ts +9 -9
- package/src/views/common/LoadError.vue +64 -64
- package/src/views/common/NotFound.vue +68 -68
- package/src/views/component/EvaluateRecordView/index.vue +40 -40
- package/src/views/component/XCellDetailView/index.vue +217 -217
- package/src/views/component/XOlMapView/XLocationPicker/index.vue +120 -120
- package/src/views/component/XOlMapView/index.vue +0 -1
- package/src/views/component/XReportFormIframeView/index.vue +47 -47
- package/src/views/component/XReportFormView/index.vue +13 -13
- package/src/views/component/XSignatureView/index.vue +50 -50
- package/src/views/component/menu.vue +117 -117
- package/src/views/component/notice.vue +46 -46
- package/src/views/component/topNav.vue +36 -36
- package/src/views/invoiceShow/index.vue +61 -61
- package/src/views/user/login/ForgetPasswordForm.vue +94 -94
- package/src/views/user/login/LoginTitle.vue +68 -68
- package/src/views/user/login/index.vue +22 -22
- package/src/views/user/my/index.vue +230 -230
- package/src/vue-router.d.ts +9 -9
- package/tsconfig.json +43 -43
|
@@ -1,22 +1,36 @@
|
|
|
1
1
|
<script setup lang="ts">
|
|
2
|
-
import type { LocationResult } from '../types'
|
|
2
|
+
import type { LocationResult, PhoneLocationStatus } from '../types'
|
|
3
|
+
import { mobileUtil } from '@af-mobile-client-vue3/utils/mobileUtil'
|
|
3
4
|
import { Button } from 'vant'
|
|
4
5
|
import { nextTick, onMounted, ref, watch } from 'vue'
|
|
5
6
|
import XOlMap from '../index.vue'
|
|
6
7
|
|
|
7
8
|
interface Props {
|
|
8
9
|
modelValue?: LocationResult
|
|
9
|
-
tianDiTuKey: string
|
|
10
|
-
amapKey: string
|
|
11
10
|
defaultCenter?: [number, number]
|
|
12
11
|
defaultZoom?: number
|
|
13
12
|
}
|
|
14
13
|
|
|
15
14
|
const props = withDefaults(defineProps<Props>(), {
|
|
16
|
-
defaultCenter: () =>
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
15
|
+
defaultCenter: () => {
|
|
16
|
+
try {
|
|
17
|
+
mobileUtil.execute({
|
|
18
|
+
param: undefined,
|
|
19
|
+
funcName: 'getPhoneStatus',
|
|
20
|
+
callbackFunc: (result) => {
|
|
21
|
+
const locationResult = result as PhoneLocationStatus
|
|
22
|
+
if (locationResult.f_latitude && locationResult.f_longitude) {
|
|
23
|
+
return [locationResult.f_longitude, locationResult.f_latitude]
|
|
24
|
+
}
|
|
25
|
+
},
|
|
26
|
+
})
|
|
27
|
+
}
|
|
28
|
+
catch (error) {
|
|
29
|
+
console.error('获取位置信息失败:', error)
|
|
30
|
+
}
|
|
31
|
+
return [108.948024, 34.263161] // 北京天安门坐标
|
|
32
|
+
},
|
|
33
|
+
defaultZoom: 16,
|
|
20
34
|
})
|
|
21
35
|
|
|
22
36
|
const emit = defineEmits<{
|
|
@@ -55,8 +69,6 @@ onMounted(() => {
|
|
|
55
69
|
mapRef.value.init({
|
|
56
70
|
center: props.defaultCenter,
|
|
57
71
|
zoom: props.defaultZoom,
|
|
58
|
-
tianDiTuKey: props.tianDiTuKey,
|
|
59
|
-
amapKey: props.amapKey,
|
|
60
72
|
})
|
|
61
73
|
|
|
62
74
|
// 初始化后尝试获取地址信息
|
|
@@ -17,6 +17,7 @@ import type {
|
|
|
17
17
|
WMSOptions,
|
|
18
18
|
} from './types'
|
|
19
19
|
import locationIcon from '@af-mobile-client-vue3/assets/img/component/positioning.png'
|
|
20
|
+
import { getConfigByName } from '@af-mobile-client-vue3/services/api/common'
|
|
20
21
|
import { mobileUtil } from '@af-mobile-client-vue3/utils/mobileUtil'
|
|
21
22
|
import { Map, View } from 'ol'
|
|
22
23
|
import { defaults as defaultControls, ScaleLine } from 'ol/control'
|
|
@@ -73,6 +74,8 @@ const wmsLayerStatus = ref<WMSLayerConfig[]>([])
|
|
|
73
74
|
const vectorLayers: Record<number, VectorLayer<VectorSource>> = {}
|
|
74
75
|
const pointLayerStatus = ref<PointLayerConfig[]>([])
|
|
75
76
|
|
|
77
|
+
const tiandityKey = ref()
|
|
78
|
+
const gaodeKey = ref()
|
|
76
79
|
/** 导航模式 是否正在跟随定位 */
|
|
77
80
|
const isFollowingLocation = ref(false)
|
|
78
81
|
/** 定位定时器 */
|
|
@@ -85,11 +88,10 @@ let locationLayer: VectorLayer<VectorSource> | null = null
|
|
|
85
88
|
*/
|
|
86
89
|
function createLocationLayer(): VectorLayer<VectorSource> {
|
|
87
90
|
const source = new VectorSource()
|
|
88
|
-
|
|
91
|
+
return new VectorLayer({
|
|
89
92
|
source,
|
|
90
93
|
zIndex: 10, // 确保位置图标在最上层
|
|
91
94
|
})
|
|
92
|
-
return layer
|
|
93
95
|
}
|
|
94
96
|
|
|
95
97
|
/**
|
|
@@ -252,7 +254,7 @@ function initializeLayers(tianDiTuKey = ''): void {
|
|
|
252
254
|
*/
|
|
253
255
|
async function getAddressInfo(location: [number, number]): Promise<string> {
|
|
254
256
|
try {
|
|
255
|
-
const key =
|
|
257
|
+
const key = gaodeKey.value
|
|
256
258
|
|
|
257
259
|
if (!key) {
|
|
258
260
|
return '获取地址失败: 未配置密钥'
|
|
@@ -320,86 +322,91 @@ function init(params: InitParams = {}): void {
|
|
|
320
322
|
zoom = 10,
|
|
321
323
|
maxZoom = 18,
|
|
322
324
|
minZoom = 4,
|
|
323
|
-
tianDiTuKey = '',
|
|
324
|
-
amapKey = '',
|
|
325
325
|
} = params
|
|
326
326
|
|
|
327
327
|
try {
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
328
|
+
getConfigByName('webConfig', (res) => {
|
|
329
|
+
const tianDiTuKey = res.tianDiTuKey || 'c16876b28898637c0a1a68b3fa410504'
|
|
330
|
+
const amapKey = res.amapKey || '5ebabc4536d4b42e0dd1e20175cca8ab'
|
|
331
|
+
|
|
332
|
+
tiandityKey.value = tianDiTuKey
|
|
333
|
+
gaodeKey.value = amapKey
|
|
334
|
+
// 初始化所有底图图层
|
|
335
|
+
initializeLayers(tianDiTuKey)
|
|
336
|
+
|
|
337
|
+
// 创建地图实例 - 加载所有底图图层,但默认只显示高德地图
|
|
338
|
+
map = new Map({
|
|
339
|
+
target: mapRef.value,
|
|
340
|
+
layers: Object.values(baseMaps), // 加载所有底图图层
|
|
341
|
+
view: new View({
|
|
342
|
+
center: fromLonLat(center),
|
|
343
|
+
zoom,
|
|
344
|
+
projection: 'EPSG:3857',
|
|
345
|
+
maxZoom,
|
|
346
|
+
minZoom,
|
|
347
|
+
}),
|
|
348
|
+
controls: defaultControls({
|
|
349
|
+
zoom: false,
|
|
350
|
+
rotate: false,
|
|
351
|
+
attribution: false,
|
|
352
|
+
}).extend([
|
|
353
|
+
new ScaleLine({
|
|
354
|
+
units: 'metric',
|
|
355
|
+
className: 'ol-scale-line',
|
|
356
|
+
}),
|
|
357
|
+
]),
|
|
358
|
+
interactions: defaultInteractions({
|
|
359
|
+
altShiftDragRotate: false,
|
|
360
|
+
pinchRotate: false,
|
|
350
361
|
}),
|
|
351
|
-
]),
|
|
352
|
-
interactions: defaultInteractions({
|
|
353
|
-
altShiftDragRotate: false,
|
|
354
|
-
pinchRotate: false,
|
|
355
|
-
}),
|
|
356
|
-
})
|
|
357
|
-
|
|
358
|
-
// 更新地图大小,确保地图正确渲染
|
|
359
|
-
setTimeout(() => {
|
|
360
|
-
if (map) {
|
|
361
|
-
map.updateSize()
|
|
362
|
-
// 确保默认图层正确显示
|
|
363
|
-
handleMapChange('tianditu')
|
|
364
|
-
}
|
|
365
|
-
}, 200)
|
|
366
|
-
|
|
367
|
-
// 监听地图移动结束事件
|
|
368
|
-
map.on('moveend', handleMoveEnd)
|
|
369
|
-
|
|
370
|
-
// 设置鼠标样式
|
|
371
|
-
if (mapRef.value) {
|
|
372
|
-
mapRef.value.style.cursor = 'grab'
|
|
373
|
-
// 监听地图事件
|
|
374
|
-
const mapElement = mapRef.value
|
|
375
|
-
|
|
376
|
-
// 鼠标按下时
|
|
377
|
-
mapElement.addEventListener('mousedown', () => {
|
|
378
|
-
mapElement.style.cursor = 'grabbing'
|
|
379
|
-
// 用户开始拖动地图,取消跟随定位
|
|
380
|
-
if (locationTimer) {
|
|
381
|
-
isFollowingLocation.value = false
|
|
382
|
-
}
|
|
383
362
|
})
|
|
384
363
|
|
|
385
|
-
//
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
364
|
+
// 更新地图大小,确保地图正确渲染
|
|
365
|
+
setTimeout(() => {
|
|
366
|
+
if (map) {
|
|
367
|
+
map.updateSize()
|
|
368
|
+
// 确保默认图层正确显示
|
|
369
|
+
handleMapChange('tianditu')
|
|
390
370
|
}
|
|
391
|
-
})
|
|
371
|
+
}, 200)
|
|
372
|
+
|
|
373
|
+
// 监听地图移动结束事件
|
|
374
|
+
map.on('moveend', handleMoveEnd)
|
|
375
|
+
|
|
376
|
+
// 设置鼠标样式
|
|
377
|
+
if (mapRef.value) {
|
|
378
|
+
mapRef.value.style.cursor = 'grab'
|
|
379
|
+
// 监听地图事件
|
|
380
|
+
const mapElement = mapRef.value
|
|
381
|
+
|
|
382
|
+
// 鼠标按下时
|
|
383
|
+
mapElement.addEventListener('mousedown', () => {
|
|
384
|
+
mapElement.style.cursor = 'grabbing'
|
|
385
|
+
// 用户开始拖动地图,取消跟随定位
|
|
386
|
+
if (locationTimer) {
|
|
387
|
+
isFollowingLocation.value = false
|
|
388
|
+
}
|
|
389
|
+
})
|
|
392
390
|
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
391
|
+
// 触摸开始时
|
|
392
|
+
mapElement.addEventListener('touchstart', () => {
|
|
393
|
+
// 用户开始拖动地图,取消跟随定位
|
|
394
|
+
if (locationTimer) {
|
|
395
|
+
isFollowingLocation.value = false
|
|
396
|
+
}
|
|
397
|
+
})
|
|
397
398
|
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
399
|
+
// 鼠标释放时
|
|
400
|
+
mapElement.addEventListener('mouseup', () => {
|
|
401
|
+
mapElement.style.cursor = 'grab'
|
|
402
|
+
})
|
|
403
|
+
|
|
404
|
+
// 鼠标离开地图时
|
|
405
|
+
mapElement.addEventListener('mouseleave', () => {
|
|
406
|
+
mapElement.style.cursor = 'grab'
|
|
407
|
+
})
|
|
408
|
+
}
|
|
409
|
+
})
|
|
403
410
|
}
|
|
404
411
|
catch (error) {
|
|
405
412
|
console.error('地图初始化失败:', error)
|
|
@@ -28,12 +28,8 @@ export interface InitParams {
|
|
|
28
28
|
maxZoom?: number
|
|
29
29
|
/** 最小缩放级别 */
|
|
30
30
|
minZoom?: number
|
|
31
|
-
/** 天地图密钥 */
|
|
32
|
-
tianDiTuKey?: string
|
|
33
31
|
/** 是否开启地址选择模式 */
|
|
34
32
|
enableLocationPicker?: boolean
|
|
35
|
-
/** 高德地图 API key */
|
|
36
|
-
amapKey?: string
|
|
37
33
|
}
|
|
38
34
|
|
|
39
35
|
/** 点位数据接口 */
|
|
@@ -1,154 +1,154 @@
|
|
|
1
|
-
// 导入proj控件
|
|
2
|
-
import * as proj from 'ol/proj'
|
|
3
|
-
|
|
4
|
-
function forEachPoint(func) {
|
|
5
|
-
return function (input, opt_output, opt_dimension) {
|
|
6
|
-
const len = input.length
|
|
7
|
-
|
|
8
|
-
const dimension = opt_dimension || 2
|
|
9
|
-
let output
|
|
10
|
-
|
|
11
|
-
if (opt_output) {
|
|
12
|
-
output = opt_output
|
|
13
|
-
}
|
|
14
|
-
else {
|
|
15
|
-
if (dimension !== 2) {
|
|
16
|
-
output = input.slice()
|
|
17
|
-
}
|
|
18
|
-
else {
|
|
19
|
-
output = [len]
|
|
20
|
-
}
|
|
21
|
-
}
|
|
22
|
-
for (let offset = 0; offset < len; offset += dimension) {
|
|
23
|
-
func(input, output, offset)
|
|
24
|
-
}
|
|
25
|
-
return output
|
|
26
|
-
}
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
const gcj02 = {}
|
|
30
|
-
const PI = Math.PI
|
|
31
|
-
const AXIS = 6378245.0
|
|
32
|
-
// eslint-disable-next-line no-loss-of-precision
|
|
33
|
-
const OFFSET = 0.00669342162296594323 // (a^2 - b^2) / a^2
|
|
34
|
-
|
|
35
|
-
function delta(wgLon, wgLat) {
|
|
36
|
-
let dLat = transformLat(wgLon - 105.0, wgLat - 35.0)
|
|
37
|
-
let dLon = transformLon(wgLon - 105.0, wgLat - 35.0)
|
|
38
|
-
const radLat = (wgLat / 180.0) * PI
|
|
39
|
-
let magic = Math.sin(radLat)
|
|
40
|
-
magic = 1 - OFFSET * magic * magic
|
|
41
|
-
const sqrtMagic = Math.sqrt(magic)
|
|
42
|
-
dLat = (dLat * 180.0) / (((AXIS * (1 - OFFSET)) / (magic * sqrtMagic)) * PI)
|
|
43
|
-
dLon = (dLon * 180.0) / ((AXIS / sqrtMagic) * Math.cos(radLat) * PI)
|
|
44
|
-
return [dLon, dLat]
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
function outOfChina(lon, lat) {
|
|
48
|
-
if (lon < 72.004 || lon > 137.8347) {
|
|
49
|
-
return true
|
|
50
|
-
}
|
|
51
|
-
return lat < 0.8293 || lat > 55.8271
|
|
52
|
-
}
|
|
53
|
-
|
|
54
|
-
function transformLat(x, y) {
|
|
55
|
-
let ret = -100.0 + 2.0 * x + 3.0 * y + 0.2 * y * y + 0.1 * x * y + 0.2 * Math.sqrt(Math.abs(x))
|
|
56
|
-
ret += ((20.0 * Math.sin(6.0 * x * PI) + 20.0 * Math.sin(2.0 * x * PI)) * 2.0) / 3.0
|
|
57
|
-
ret += ((20.0 * Math.sin(y * PI) + 40.0 * Math.sin((y / 3.0) * PI)) * 2.0) / 3.0
|
|
58
|
-
ret += ((160.0 * Math.sin((y / 12.0) * PI) + 320 * Math.sin((y * PI) / 30.0)) * 2.0) / 3.0
|
|
59
|
-
return ret
|
|
60
|
-
}
|
|
61
|
-
|
|
62
|
-
function transformLon(x, y) {
|
|
63
|
-
let ret = 300.0 + x + 2.0 * y + 0.1 * x * x + 0.1 * x * y + 0.1 * Math.sqrt(Math.abs(x))
|
|
64
|
-
ret += ((20.0 * Math.sin(6.0 * x * PI) + 20.0 * Math.sin(2.0 * x * PI)) * 2.0) / 3.0
|
|
65
|
-
ret += ((20.0 * Math.sin(x * PI) + 40.0 * Math.sin((x / 3.0) * PI)) * 2.0) / 3.0
|
|
66
|
-
ret += ((150.0 * Math.sin((x / 12.0) * PI) + 300.0 * Math.sin((x / 30.0) * PI)) * 2.0) / 3.0
|
|
67
|
-
return ret
|
|
68
|
-
}
|
|
69
|
-
|
|
70
|
-
gcj02.toWGS84 = forEachPoint((input, output, offset) => {
|
|
71
|
-
let lng = input[offset]
|
|
72
|
-
let lat = input[offset + 1]
|
|
73
|
-
if (!outOfChina(lng, lat)) {
|
|
74
|
-
const deltaD = delta(lng, lat)
|
|
75
|
-
lng = lng - deltaD[0] // 改回减法
|
|
76
|
-
lat = lat - deltaD[1] // 改回减法
|
|
77
|
-
}
|
|
78
|
-
output[offset] = lng
|
|
79
|
-
output[offset + 1] = lat
|
|
80
|
-
})
|
|
81
|
-
|
|
82
|
-
gcj02.fromWGS84 = forEachPoint((input, output, offset) => {
|
|
83
|
-
let lng = input[offset]
|
|
84
|
-
let lat = input[offset + 1]
|
|
85
|
-
if (!outOfChina(lng, lat)) {
|
|
86
|
-
const deltaD = delta(lng, lat)
|
|
87
|
-
lng = lng + deltaD[0] // 改回加法
|
|
88
|
-
lat = lat + deltaD[1] // 改回加法
|
|
89
|
-
}
|
|
90
|
-
output[offset] = lng
|
|
91
|
-
output[offset + 1] = lat
|
|
92
|
-
})
|
|
93
|
-
|
|
94
|
-
const sphericalMercator = {}
|
|
95
|
-
const RADIUS = 6378137
|
|
96
|
-
const MAX_LATITUDE = 85.0511287798
|
|
97
|
-
const RAD_PER_DEG = Math.PI / 180
|
|
98
|
-
|
|
99
|
-
sphericalMercator.forward = forEachPoint((input, output, offset) => {
|
|
100
|
-
const lat = Math.max(Math.min(MAX_LATITUDE, input[offset + 1]), -MAX_LATITUDE)
|
|
101
|
-
const sin = Math.sin(lat * RAD_PER_DEG)
|
|
102
|
-
output[offset] = RADIUS * input[offset] * RAD_PER_DEG
|
|
103
|
-
output[offset + 1] = (RADIUS * Math.log((1 + sin) / (1 - sin))) / 2
|
|
104
|
-
})
|
|
105
|
-
|
|
106
|
-
sphericalMercator.inverse = forEachPoint((input, output, offset) => {
|
|
107
|
-
output[offset] = input[offset] / RADIUS / RAD_PER_DEG
|
|
108
|
-
output[offset + 1] = (2 * Math.atan(Math.exp(input[offset + 1] / RADIUS)) - Math.PI / 2) / RAD_PER_DEG
|
|
109
|
-
})
|
|
110
|
-
|
|
111
|
-
const projzh = {}
|
|
112
|
-
|
|
113
|
-
projzh.ll2gmerc = function (input, opt_output, opt_dimension) {
|
|
114
|
-
const output = gcj02.toWGS84(input, opt_output, opt_dimension) // 改用 toWGS84
|
|
115
|
-
return projzh.ll2smerc(output, output, opt_dimension)
|
|
116
|
-
}
|
|
117
|
-
|
|
118
|
-
projzh.gmerc2ll = function (input, opt_output, opt_dimension) {
|
|
119
|
-
const output = projzh.smerc2ll(input, input, opt_dimension)
|
|
120
|
-
return gcj02.fromWGS84(output, opt_output, opt_dimension) // 改用 fromWGS84
|
|
121
|
-
}
|
|
122
|
-
|
|
123
|
-
// smerc2gmerc 需要修改
|
|
124
|
-
|
|
125
|
-
projzh.smerc2gmerc = function (input, opt_output, opt_dimension) {
|
|
126
|
-
let output = projzh.smerc2ll(input, input, opt_dimension)
|
|
127
|
-
output = gcj02.toWGS84(output, output, opt_dimension) // 这里应该用 toWGS84
|
|
128
|
-
return projzh.ll2smerc(output, output, opt_dimension)
|
|
129
|
-
}
|
|
130
|
-
|
|
131
|
-
// gmerc2smerc 需要修改
|
|
132
|
-
|
|
133
|
-
projzh.gmerc2smerc = function (input, opt_output, opt_dimension) {
|
|
134
|
-
let output = projzh.smerc2ll(input, input, opt_dimension)
|
|
135
|
-
output = gcj02.fromWGS84(output, output, opt_dimension) // 这里应该用 fromWGS84
|
|
136
|
-
return projzh.ll2smerc(output, output, opt_dimension)
|
|
137
|
-
}
|
|
138
|
-
|
|
139
|
-
projzh.ll2smerc = sphericalMercator.forward
|
|
140
|
-
projzh.smerc2ll = sphericalMercator.inverse
|
|
141
|
-
|
|
142
|
-
// 定义WGS84转GCJ02的投影
|
|
143
|
-
const extent = [-20037508.342789244, -20037508.342789244, 20037508.342789244, 20037508.342789244]
|
|
144
|
-
export const wgs84ToGcj02Projection = new proj.Projection({
|
|
145
|
-
code: 'WGS84-TO-GCJ02',
|
|
146
|
-
extent,
|
|
147
|
-
units: 'm',
|
|
148
|
-
})
|
|
149
|
-
|
|
150
|
-
// 添加投影和转换方法
|
|
151
|
-
proj.addProjection(wgs84ToGcj02Projection)
|
|
152
|
-
// 注意这里转换方法的顺序与原来相反
|
|
153
|
-
proj.addCoordinateTransforms('EPSG:4326', wgs84ToGcj02Projection, projzh.ll2gmerc, projzh.gmerc2ll)
|
|
154
|
-
proj.addCoordinateTransforms('EPSG:3857', wgs84ToGcj02Projection, projzh.smerc2gmerc, projzh.gmerc2smerc)
|
|
1
|
+
// 导入proj控件
|
|
2
|
+
import * as proj from 'ol/proj'
|
|
3
|
+
|
|
4
|
+
function forEachPoint(func) {
|
|
5
|
+
return function (input, opt_output, opt_dimension) {
|
|
6
|
+
const len = input.length
|
|
7
|
+
|
|
8
|
+
const dimension = opt_dimension || 2
|
|
9
|
+
let output
|
|
10
|
+
|
|
11
|
+
if (opt_output) {
|
|
12
|
+
output = opt_output
|
|
13
|
+
}
|
|
14
|
+
else {
|
|
15
|
+
if (dimension !== 2) {
|
|
16
|
+
output = input.slice()
|
|
17
|
+
}
|
|
18
|
+
else {
|
|
19
|
+
output = [len]
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
for (let offset = 0; offset < len; offset += dimension) {
|
|
23
|
+
func(input, output, offset)
|
|
24
|
+
}
|
|
25
|
+
return output
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
const gcj02 = {}
|
|
30
|
+
const PI = Math.PI
|
|
31
|
+
const AXIS = 6378245.0
|
|
32
|
+
// eslint-disable-next-line no-loss-of-precision
|
|
33
|
+
const OFFSET = 0.00669342162296594323 // (a^2 - b^2) / a^2
|
|
34
|
+
|
|
35
|
+
function delta(wgLon, wgLat) {
|
|
36
|
+
let dLat = transformLat(wgLon - 105.0, wgLat - 35.0)
|
|
37
|
+
let dLon = transformLon(wgLon - 105.0, wgLat - 35.0)
|
|
38
|
+
const radLat = (wgLat / 180.0) * PI
|
|
39
|
+
let magic = Math.sin(radLat)
|
|
40
|
+
magic = 1 - OFFSET * magic * magic
|
|
41
|
+
const sqrtMagic = Math.sqrt(magic)
|
|
42
|
+
dLat = (dLat * 180.0) / (((AXIS * (1 - OFFSET)) / (magic * sqrtMagic)) * PI)
|
|
43
|
+
dLon = (dLon * 180.0) / ((AXIS / sqrtMagic) * Math.cos(radLat) * PI)
|
|
44
|
+
return [dLon, dLat]
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
function outOfChina(lon, lat) {
|
|
48
|
+
if (lon < 72.004 || lon > 137.8347) {
|
|
49
|
+
return true
|
|
50
|
+
}
|
|
51
|
+
return lat < 0.8293 || lat > 55.8271
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
function transformLat(x, y) {
|
|
55
|
+
let ret = -100.0 + 2.0 * x + 3.0 * y + 0.2 * y * y + 0.1 * x * y + 0.2 * Math.sqrt(Math.abs(x))
|
|
56
|
+
ret += ((20.0 * Math.sin(6.0 * x * PI) + 20.0 * Math.sin(2.0 * x * PI)) * 2.0) / 3.0
|
|
57
|
+
ret += ((20.0 * Math.sin(y * PI) + 40.0 * Math.sin((y / 3.0) * PI)) * 2.0) / 3.0
|
|
58
|
+
ret += ((160.0 * Math.sin((y / 12.0) * PI) + 320 * Math.sin((y * PI) / 30.0)) * 2.0) / 3.0
|
|
59
|
+
return ret
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
function transformLon(x, y) {
|
|
63
|
+
let ret = 300.0 + x + 2.0 * y + 0.1 * x * x + 0.1 * x * y + 0.1 * Math.sqrt(Math.abs(x))
|
|
64
|
+
ret += ((20.0 * Math.sin(6.0 * x * PI) + 20.0 * Math.sin(2.0 * x * PI)) * 2.0) / 3.0
|
|
65
|
+
ret += ((20.0 * Math.sin(x * PI) + 40.0 * Math.sin((x / 3.0) * PI)) * 2.0) / 3.0
|
|
66
|
+
ret += ((150.0 * Math.sin((x / 12.0) * PI) + 300.0 * Math.sin((x / 30.0) * PI)) * 2.0) / 3.0
|
|
67
|
+
return ret
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
gcj02.toWGS84 = forEachPoint((input, output, offset) => {
|
|
71
|
+
let lng = input[offset]
|
|
72
|
+
let lat = input[offset + 1]
|
|
73
|
+
if (!outOfChina(lng, lat)) {
|
|
74
|
+
const deltaD = delta(lng, lat)
|
|
75
|
+
lng = lng - deltaD[0] // 改回减法
|
|
76
|
+
lat = lat - deltaD[1] // 改回减法
|
|
77
|
+
}
|
|
78
|
+
output[offset] = lng
|
|
79
|
+
output[offset + 1] = lat
|
|
80
|
+
})
|
|
81
|
+
|
|
82
|
+
gcj02.fromWGS84 = forEachPoint((input, output, offset) => {
|
|
83
|
+
let lng = input[offset]
|
|
84
|
+
let lat = input[offset + 1]
|
|
85
|
+
if (!outOfChina(lng, lat)) {
|
|
86
|
+
const deltaD = delta(lng, lat)
|
|
87
|
+
lng = lng + deltaD[0] // 改回加法
|
|
88
|
+
lat = lat + deltaD[1] // 改回加法
|
|
89
|
+
}
|
|
90
|
+
output[offset] = lng
|
|
91
|
+
output[offset + 1] = lat
|
|
92
|
+
})
|
|
93
|
+
|
|
94
|
+
const sphericalMercator = {}
|
|
95
|
+
const RADIUS = 6378137
|
|
96
|
+
const MAX_LATITUDE = 85.0511287798
|
|
97
|
+
const RAD_PER_DEG = Math.PI / 180
|
|
98
|
+
|
|
99
|
+
sphericalMercator.forward = forEachPoint((input, output, offset) => {
|
|
100
|
+
const lat = Math.max(Math.min(MAX_LATITUDE, input[offset + 1]), -MAX_LATITUDE)
|
|
101
|
+
const sin = Math.sin(lat * RAD_PER_DEG)
|
|
102
|
+
output[offset] = RADIUS * input[offset] * RAD_PER_DEG
|
|
103
|
+
output[offset + 1] = (RADIUS * Math.log((1 + sin) / (1 - sin))) / 2
|
|
104
|
+
})
|
|
105
|
+
|
|
106
|
+
sphericalMercator.inverse = forEachPoint((input, output, offset) => {
|
|
107
|
+
output[offset] = input[offset] / RADIUS / RAD_PER_DEG
|
|
108
|
+
output[offset + 1] = (2 * Math.atan(Math.exp(input[offset + 1] / RADIUS)) - Math.PI / 2) / RAD_PER_DEG
|
|
109
|
+
})
|
|
110
|
+
|
|
111
|
+
const projzh = {}
|
|
112
|
+
|
|
113
|
+
projzh.ll2gmerc = function (input, opt_output, opt_dimension) {
|
|
114
|
+
const output = gcj02.toWGS84(input, opt_output, opt_dimension) // 改用 toWGS84
|
|
115
|
+
return projzh.ll2smerc(output, output, opt_dimension)
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
projzh.gmerc2ll = function (input, opt_output, opt_dimension) {
|
|
119
|
+
const output = projzh.smerc2ll(input, input, opt_dimension)
|
|
120
|
+
return gcj02.fromWGS84(output, opt_output, opt_dimension) // 改用 fromWGS84
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
// smerc2gmerc 需要修改
|
|
124
|
+
|
|
125
|
+
projzh.smerc2gmerc = function (input, opt_output, opt_dimension) {
|
|
126
|
+
let output = projzh.smerc2ll(input, input, opt_dimension)
|
|
127
|
+
output = gcj02.toWGS84(output, output, opt_dimension) // 这里应该用 toWGS84
|
|
128
|
+
return projzh.ll2smerc(output, output, opt_dimension)
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
// gmerc2smerc 需要修改
|
|
132
|
+
|
|
133
|
+
projzh.gmerc2smerc = function (input, opt_output, opt_dimension) {
|
|
134
|
+
let output = projzh.smerc2ll(input, input, opt_dimension)
|
|
135
|
+
output = gcj02.fromWGS84(output, output, opt_dimension) // 这里应该用 fromWGS84
|
|
136
|
+
return projzh.ll2smerc(output, output, opt_dimension)
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
projzh.ll2smerc = sphericalMercator.forward
|
|
140
|
+
projzh.smerc2ll = sphericalMercator.inverse
|
|
141
|
+
|
|
142
|
+
// 定义WGS84转GCJ02的投影
|
|
143
|
+
const extent = [-20037508.342789244, -20037508.342789244, 20037508.342789244, 20037508.342789244]
|
|
144
|
+
export const wgs84ToGcj02Projection = new proj.Projection({
|
|
145
|
+
code: 'WGS84-TO-GCJ02',
|
|
146
|
+
extent,
|
|
147
|
+
units: 'm',
|
|
148
|
+
})
|
|
149
|
+
|
|
150
|
+
// 添加投影和转换方法
|
|
151
|
+
proj.addProjection(wgs84ToGcj02Projection)
|
|
152
|
+
// 注意这里转换方法的顺序与原来相反
|
|
153
|
+
proj.addCoordinateTransforms('EPSG:4326', wgs84ToGcj02Projection, projzh.ll2gmerc, projzh.gmerc2ll)
|
|
154
|
+
proj.addCoordinateTransforms('EPSG:3857', wgs84ToGcj02Projection, projzh.smerc2gmerc, projzh.gmerc2smerc)
|