北京经济技术开发区经开区虚拟城市项目-【前端】--政府服务中心-1号屏Web
Surpriseplus
2023-10-07 a77448eb072f10dd3827694140f87c3069b1dba4
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
160
161
162
163
164
165
166
167
168
169
170
class StreetscapeYZ {
  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");
 
    var bkProjection = "EPSG:900913";
    var wgsProjection = "EPSG:4326";
    var transformPoint = proj4(wgsProjection, bkProjection, [
      option.lon,
      option.lat,
    ]);
 
    // option.StreetUrl = "http://10.10.4.116:8081/Help4Gov/";
    // option.x = 116.3639809972959;
    // option.y = 39.721765460108294;
    /**
     *
     *  街景服务参数
     *
     */
    this.streetSphere_data = {
      StreetUrl: option.StreetUrl,
      getImageRootUrl: option.StreetUrl + "/GetPanoTile?TileID=",
      getFirstImageDir: "-1-0-0-0",
      getSecondImageDir: "-1-3-",
      getThreeImageDir: "-1-4-",
      lon: transformPoint[0],
      lat: transformPoint[1],
      x: option.lon,
      y: 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:
        "SosoService/?qt=qsdata&x=" +
        "{lon}" +
        "&y=" +
        "{lat}" +
        "&r=50&action=1",
      getImageById: "SosoService/scape/?qt=pdata&from=PC",
      getInitImageById: "",
      getSecondImageById: "",
      getThirdImageById: "",
      getInitImageByPositionCallBack: this.setStreetViewData,
      getImageInfoByIdCallBack: this.setStreetViewData,
    };
    this.StreetScapeOption.getInitImageByPosition =
      this.streetSphere_data.StreetUrl +
      this.StreetScapeOption.getInitImageByPosition;
    this.StreetScapeOption.getImageById =
      this.streetSphere_data.StreetUrl + this.StreetScapeOption.getImageById;
    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.StreetView = this.sgworld.Analysis.StreetViewOpenYZ(
      {
        lon: this.streetSphere_data.lon,
        lat: this.streetSphere_data.lat,
        x: this.streetSphere_data.x,
        y: this.streetSphere_data.y,
      },
      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;
    }
  }
 
  //设置街景球透明度
  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();
    });
  }
}