|
@@ -11,68 +11,83 @@ class InitMap {
|
|
|
this.m_spatialReference = options.m_spatialReference;
|
|
|
this.bus = options.bus;
|
|
|
this.onReady = options.onReady; // 新增回调参数 // [!code ++]
|
|
|
+ this.currentType = options.currentType;
|
|
|
this.intMap();
|
|
|
}
|
|
|
|
|
|
intMap() {
|
|
|
+ let that =this;
|
|
|
this.m_map = new Map({});
|
|
|
- this.m_map.ground.surfaceColor = "#002F47";
|
|
|
-
|
|
|
- this.m_view = new SceneView({
|
|
|
- container: "viewDiv",
|
|
|
- map: this.m_map,
|
|
|
- logo: false,
|
|
|
- viewingMode: "global",
|
|
|
- scale: dojoConfig["scale"],
|
|
|
- spatialReference: this.m_spatialReference,
|
|
|
- qualityProfile: "high",
|
|
|
- environment: {
|
|
|
- starsEnabled: true,
|
|
|
- atmosphereEnabled: true,
|
|
|
- weather: {
|
|
|
- type: "sunny",
|
|
|
- cloudCover: 0.7,
|
|
|
- precipitation: 0.3
|
|
|
+ if(this.currentType === "2D") {
|
|
|
+ this.m_view = new MapView({
|
|
|
+ container: "viewDiv",
|
|
|
+ map: this.m_map,
|
|
|
+ logo: false,
|
|
|
+ background:{
|
|
|
+ color:"#002F47"
|
|
|
},
|
|
|
- atmosphere: {
|
|
|
- quality: "high"
|
|
|
+ ui: {
|
|
|
+ components: []
|
|
|
},
|
|
|
- lighting: {
|
|
|
- date: new Date().setHours(-3),
|
|
|
- directShadowsEnabled: true,
|
|
|
- cameraTrackingEnabled: true
|
|
|
- }
|
|
|
- }
|
|
|
- });
|
|
|
-
|
|
|
- // 关键修改:等待 SceneView 加载完成 // [!code ++]
|
|
|
- this.m_view.when(() => {
|
|
|
- console.log("SceneView 初始化完成");
|
|
|
-
|
|
|
- // 初始化其他逻辑
|
|
|
- this.m_view.watch("stationary", (stationary) => {
|
|
|
- if (stationary) {
|
|
|
- this.bus.emit('SendMessage', {
|
|
|
- action: "MapExtentChanged",
|
|
|
- data: {
|
|
|
- extent: this.m_view.extent,
|
|
|
- scale: this.m_view.scale,
|
|
|
- camera: this.m_view.camera,
|
|
|
- rotation: this.m_view.viewpoint.rotation,
|
|
|
- center: this.m_view.center
|
|
|
- }
|
|
|
- });
|
|
|
+ spatialReference: this.m_spatialReference,
|
|
|
+ });
|
|
|
+ this.loadWatch()
|
|
|
+ }
|
|
|
+ if(this.currentType === '3D'){
|
|
|
+ this.m_map.ground.surfaceColor = "#002F47";
|
|
|
+ this.m_view = new SceneView({
|
|
|
+ container: "viewDiv",
|
|
|
+ map: this.m_map,
|
|
|
+ logo: false,
|
|
|
+ viewingMode: "global",
|
|
|
+ scale: dojoConfig["scale"],
|
|
|
+ spatialReference: this.m_spatialReference,
|
|
|
+ qualityProfile: "high",
|
|
|
+ environment: {
|
|
|
+ starsEnabled: true,
|
|
|
+ atmosphereEnabled: true,
|
|
|
+ weather: {
|
|
|
+ type: "sunny",
|
|
|
+ cloudCover: 0.7,
|
|
|
+ precipitation: 0.3
|
|
|
+ },
|
|
|
+ atmosphere: {
|
|
|
+ quality: "high"
|
|
|
+ },
|
|
|
+ lighting: {
|
|
|
+ date: new Date().setHours(-3),
|
|
|
+ directShadowsEnabled: true,
|
|
|
+ cameraTrackingEnabled: true
|
|
|
+ }
|
|
|
}
|
|
|
});
|
|
|
-
|
|
|
this.m_view.ui.empty("top-left");
|
|
|
this.m_view.ui.remove("attribution");
|
|
|
-
|
|
|
- // 触发外部回调 // [!code ++]
|
|
|
- if (this.onReady) this.onReady(); // [!code ++]
|
|
|
- }).catch(error => { // [!code ++]
|
|
|
- console.error("SceneView 初始化失败:", error); // [!code ++]
|
|
|
- }); // [!code ++]
|
|
|
+ // 关键修改:等待 SceneView 加载完成 // [!code ++]
|
|
|
+ this.m_view.when(() => {
|
|
|
+ that.loadWatch();
|
|
|
+ }).catch(error => { // [!code ++]
|
|
|
+ console.error("SceneView 初始化失败:", error); // [!code ++]
|
|
|
+ }); // [!code ++]
|
|
|
+ }
|
|
|
+ }
|
|
|
+ loadWatch(){
|
|
|
+ this.m_view.watch("stationary", (stationary) => {
|
|
|
+ if (stationary) {
|
|
|
+ this.bus.emit('SendMessage', {
|
|
|
+ action: "MapExtentChanged",
|
|
|
+ data: {
|
|
|
+ extent: this.m_view.extent,
|
|
|
+ scale: this.m_view.scale,
|
|
|
+ camera: this.m_view.camera,
|
|
|
+ rotation: this.m_view.viewpoint.rotation,
|
|
|
+ center: this.m_view.center
|
|
|
+ }
|
|
|
+ });
|
|
|
+ }
|
|
|
+ });
|
|
|
+ // 触发外部回调 // [!code ++]
|
|
|
+ if (this.onReady) this.onReady(); // [!code ++]
|
|
|
}
|
|
|
}
|
|
|
|