|
@@ -1,32 +1,34 @@
|
|
|
+// InitMap 修改后代码
|
|
|
import Map from '@arcgis/core/Map'
|
|
|
import MapView from '@arcgis/core/views/MapView'
|
|
|
import SceneView from '@arcgis/core/views/SceneView'
|
|
|
import dojoConfig from '../../config/tsconfig.json'
|
|
|
-class InitMap{
|
|
|
+
|
|
|
+class InitMap {
|
|
|
constructor(options) {
|
|
|
this.m_map = options.m_map;
|
|
|
this.m_view = options.m_view;
|
|
|
this.m_spatialReference = options.m_spatialReference;
|
|
|
this.bus = options.bus;
|
|
|
- this.intMap()
|
|
|
+ this.onReady = options.onReady; // 新增回调参数 // [!code ++]
|
|
|
+ this.intMap();
|
|
|
}
|
|
|
- intMap(){
|
|
|
+
|
|
|
+ intMap() {
|
|
|
this.m_map = new Map({});
|
|
|
- this.m_map.ground.surfaceColor = "#002F47"
|
|
|
- // this.m_map.ground.navigationConstraint = {
|
|
|
- // type: "none"
|
|
|
- // };
|
|
|
+ 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",
|
|
|
+ container: "viewDiv",
|
|
|
+ map: this.m_map,
|
|
|
+ logo: false,
|
|
|
+ viewingMode: "global",
|
|
|
+ scale: dojoConfig["scale"],
|
|
|
+ spatialReference: this.m_spatialReference,
|
|
|
+ qualityProfile: "high",
|
|
|
environment: {
|
|
|
starsEnabled: true,
|
|
|
- atmosphereEnabled: true, //大气层
|
|
|
+ atmosphereEnabled: true,
|
|
|
weather: {
|
|
|
type: "sunny",
|
|
|
cloudCover: 0.7,
|
|
@@ -42,27 +44,36 @@ class InitMap{
|
|
|
}
|
|
|
}
|
|
|
});
|
|
|
- // this.m_view.constraints = {
|
|
|
- // collision: {
|
|
|
- // enabled: false
|
|
|
- // }
|
|
|
- // };
|
|
|
- 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
|
|
|
- }
|
|
|
- })
|
|
|
- }
|
|
|
- })
|
|
|
- this.m_view.ui.empty("top-left");
|
|
|
- this.m_view.ui.remove("attribution");
|
|
|
+
|
|
|
+ // 关键修改:等待 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
|
|
|
+ }
|
|
|
+ });
|
|
|
+ }
|
|
|
+ });
|
|
|
+
|
|
|
+ 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 ++]
|
|
|
}
|
|
|
}
|
|
|
-export default InitMap
|
|
|
+
|
|
|
+export default InitMap;
|