suerprisePlus
2024-06-05 3ed05b2ea37c4da7b0b4923991deb1d27f415027
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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
class Streetscape {
    constructor(sgworld, option = {}) {
        this.sgworld = sgworld
        this.streetscape_alpha = option.alpha || 1;
 
        ///街景坐标系定义
        proj4.defs('EPSG:4528-40M', "+title=CGCS2000_40 +proj=tmerc +lat_0=0 +lon_0=120 +ellps=GRS80 +units=m +x_0=500000 +y_0=0 +k=1.0");
        proj4.defs("EPSG:4490", "+proj=longlat +ellps=GRS80 +no_defs");
 
        /**
         *
         *  街景服务参数
         *
         */
        this.streetSphere_data = {
            StreetUrl: option.StreetUrl,
            getImageRootUrl: option.StreetUrl + "/GetPanoTile?TileID=",
            getFirstImageDir: "-1-0-0-0",
            getSecondImageDir: "-1-3-",
            getThreeImageDir: "-1-4-",
            lon: option.lon,
            lat: option.lat
        }
        this.setStreetScapeUrl()
        this.init()
    }
 
    //设置街景接口响应回调
    setStreetViewData(StreetViewData, datas) {
        StreetViewData.getImageTileID = datas.GetPanoInfoResult.ImageInfo.ImageID;
        StreetViewData.lon = datas.GetPanoInfoResult.ImageInfo.L;
        StreetViewData.lat = datas.GetPanoInfoResult.ImageInfo.B;
        StreetViewData.height = datas.GetPanoInfoResult.ImageInfo.Z;
        StreetViewData.HeadingPitchRoll = {
            heading: datas.GetPanoInfoResult.ImageInfo.Yaw,
            pitch: datas.GetPanoInfoResult.ImageInfo.Pitch,
            roll: datas.GetPanoInfoResult.ImageInfo.Roll,
        };
        //链接图片的ImageID
        let links = datas.GetPanoInfoResult.Links;
        links.forEach(function (data) {
            var linkPosition = [];
            linkPosition = proj4('EPSG:4528-40M', 'EPSG:4490', [data.X, data.Y]);
            linkPosition.push(data.Z);
            StreetViewData.linkImagesData.push({
                ImageID: data.ImageID,
                NavigationAngle: data.Angle * 180 / Math.PI,
                Position: linkPosition
            });
        });
    }
 
    //设置街景接口
    setStreetScapeUrl() {
        this.StreetScapeOption = {
            getInitImageByPosition: '/GetPanoInfo?MethodType=2&ToleratePano=0&L=' + '{lon}' + '&f=json&ViewType=1&Type=0&B=' + '{lat}' + '&PanoID=-1&TolerateBL=0.002&TolerateFacade=200',
            getInitImageInfoById: '/GetPanoInfo?Type=0&TolerateFacade=200&ToleratePano=0&ViewType=1&MethodType=0&f=json&PanoID=' + '{id}',
            getInitImageById: '',
            getSecondImageById: '',
            getThirdImageById: '',
            getInitImageByPositionCallBack: this.setStreetViewData,
            getImageInfoByIdCallBack: this.setStreetViewData
        }
        this.StreetScapeOption.getInitImageByPosition = this.streetSphere_data.StreetUrl + this.StreetScapeOption.getInitImageByPosition;
        this.StreetScapeOption.getInitImageInfoById = this.streetSphere_data.StreetUrl + this.StreetScapeOption.getInitImageInfoById;
        this.StreetScapeOption.getInitImageById = this.streetSphere_data.getImageRootUrl + '{id}' + this.streetSphere_data.getFirstImageDir;
        this.StreetScapeOption.getSecondImageById = this.streetSphere_data.getImageRootUrl + '{id}' + this.streetSphere_data.getSecondImageDir;
        this.StreetScapeOption.getThirdImageById = this.streetSphere_data.getImageRootUrl + '{id}' + this.streetSphere_data.getThreeImageDir;
    }
 
    init() {
        this.exit()
        this.sgworld.camera.stop(); //取消飞行状态
 
        this.StreetView = this.sgworld.analysis.StreetViewOpen({
            lon: this.streetSphere_data.lon,
            lat: this.streetSphere_data.lat
        }, this.StreetScapeOption, () => {
            //创建滑动按钮
            this.createSlider();
            ///创建退出按钮
            this.createExitButton();
        });
        this.setOpacity(this.streetscape_alpha);
    }
 
    exit() {
        if (this.StreetView) {
            this.StreetView.exit();
            this.StreetView = null;
            this.sliderContainer && this.sliderContainer.remove();
            //移除退出按钮
            this.exitContainer && this.exitContainer.remove();
            this.sliderContainer = this.exitContainer = undefined
        }
    }
 
    // 跳转位置
    changePosition(position) {
        this.streetSphere_data.lon = position.lon;
        this.streetSphere_data.lat = position.lat;
        this.StreetView.StreetViewData.isTwoTextures = false;
        this.StreetView.StreetViewData.isThreeTextures = false;
        this.StreetScapeOption.flyTime = 1;
        this.init();
    }
 
    // 更新服务
    changeServer(StreetUrl) {
        this.streetSphere_data.StreetUrl = StreetUrl;
        this.streetSphere_data.getImageRootUrl = StreetUrl + "/Image3DResourceService/GetImageTile/?ImageID=";
        this.streetSphere_data.getImageInfo = StreetUrl + '/Image3DResourceService/GetImageInfo/?ImageID=';
        this.StreetView.StreetViewData.isTwoTextures = false;
        this.StreetView.StreetViewData.isThreeTextures = false;
        this.setStreetScapeUrl();
        this.StreetScapeOption.flyTime = 1;
        this.init();
    }
 
    //设置街景球透明度
    setOpacity(alpha) {
        this.streetscape_alpha = alpha
        if (this.StreetView) {
            this.StreetView.setOpacity(alpha);
        }
    }
 
    //创建透明度滑动条
    createSlider() {
        var div = '<div id="streetScapeSlider" style="position: absolute;top: 0;left: 0;z-index: 99;width:218px;margin: 45px 100px 10px;"><div id="opacity-streetScape"></div></div>';
        $(document.body).append(div);
        this.sliderContainer = $('#streetScapeSlider');
        layui.use('slider', () => {
            var slider = layui.slider;
            slider.render({
                elem: '#opacity-streetScape',
                theme: '#1E9FFF',
                min: 0 //最小值
                ,
                max: 100 //最大值
                ,
                value: this.streetscape_alpha * 100,
                change: (value) => {
                    this.setOpacity(value / 100);
                }
            });
        });
    }
 
    //创建退出按钮
    createExitButton() {
        let div = '<div id="streetScapeExitButton" style="position: absolute;top: 0;left: 0;z-index: 99;margin:20px;"><button type="button" class="layui-btn layui-btn-normal">退出</button></div>';
        $(document.body).append(div);
        this.exitContainer = $('#streetScapeExitButton');
        this.exitContainer.click(() => {
            this.exit()
        })
    }
}