forked from drone/command-center-dashboard

罗广辉
2025-04-21 2800fa4f32f3900509cb4d6eefaf2bfaf54efdd7
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
/*
 * @Author: GuLiMmo 2820890765@qq.com
 * @Date: 2024-05-11 09:18:29
 * @LastEditors: GuLiMmo 2820890765@qq.com
 * @LastEditTime: 2024-05-11 09:20:27
 * @FilePath: /bigScreen/src/utils/cesium/webMercatorTilingScheme/index.js
 * @Description: 高德地图纠偏
 * Copyright (c) 2024 by GuLiMmo, All Rights Reserved.
 */
import {
    WebMercatorProjection,
    WebMercatorTilingScheme,
    Math,
    Cartographic,
    Cartesian2,
} from 'cesium'
import CoordTransform from './CoordTransform'
 
class AmapMercatorTilingScheme extends WebMercatorTilingScheme {
    constructor() {
        super()
 
        let projection = new WebMercatorProjection()
 
        this._projection.project = function (cartographic, result) {
            result = CoordTransform.WGS84ToGCJ02(
                Math.toDegrees(cartographic.longitude),
                Math.toDegrees(cartographic.latitude)
            )
            result = projection.project(
                new Cartographic(Math.toRadians(result[0]), Math.toRadians(result[1]))
            )
            return new Cartesian2(result.x, result.y)
        }
 
        this._projection.unproject = function (cartesian, result) {
            let cartographic = projection.unproject(cartesian)
            result = CoordTransform.GCJ02ToWGS84(
                Math.toDegrees(cartographic.longitude),
                Math.toDegrees(cartographic.latitude)
            )
            return new Cartographic(Math.toRadians(result[0]), Math.toRadians(result[1]))
        }
    }
}
 
export default AmapMercatorTilingScheme