2023西安数博会CIM演示-【前端】-Web
AdaKing88
2023-08-21 bc03b832caa49bbcd2674fe4cae3701b5059bf95
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
import {
  getProperty
} from '@/api/gisserverApi.js'
const identifyTool = {
  handle: null,
  storeyHighlights: [],
  start: (callback) => {
    // identifyTool.close()
    
    identifyTool.handle = sgworld.coreMap.screenSpaceEventHandler.setInputAction(click => {
      console.log("console")
      var pickedFeature = sgworld.coreMap.scene.pick(click.position);
      window.sgworld.coreMap.scene.bim.PickId(click.position.x, click.position.y).then(idArr => {
        if (!pickedFeature) {
          callback()
          return
        }
        if (identifyTool.checkModelisNull(idArr)) {
          if (!pickedFeature._content) {
            callback()
            return
          }
          if (pickedFeature._content._model) {
            callback(pickedFeature, pickedFeature._content._model.type)
            return
          }
        } else {
          let modelId = idArr[0]
          let instancesId = idArr[1]
          let componentId = idArr[2]
 
          if (identifyTool.storeyHighlights.length > 0) {
            identifyTool.storeyHighlights.forEach(highlight => {
              let idInt32Array = new Int32Array(highlight)
              window.sgworld.coreMap.scene.bim.SetComponentStatus(1, idInt32Array, false)
            });
            identifyTool.storeyHighlights = []
          }
 
          let idInt32Array = new Int32Array([modelId, componentId])
          window.sgworld.coreMap.scene.bim.SetComponentStatus(2, idInt32Array, false)
          identifyTool.storeyHighlights.push([modelId, componentId])
          getProperty({
            id: componentId
          }, modelId).then(res => {
            callback(res, 'bim')
          })
        }
 
      })
      sgworld.coreMap.screenSpaceEventHandler.removeInputAction(Cesium.ScreenSpaceEventType.LEFT_CLICK)
      identifyTool.handle = null
    }, Cesium.ScreenSpaceEventType.LEFT_CLICK);
  },
  close: () => {
    if (identifyTool.handle) {
      sgworld.coreMap.screenSpaceEventHandler.removeInputAction(Cesium.ScreenSpaceEventType.LEFT_CLICK)
      identifyTool.handle = null
    }
 
    if (identifyTool.storeyHighlights.length > 0) {
      identifyTool.storeyHighlights.forEach(highlight => {
        let idInt32Array = new Int32Array(highlight)
        window.sgworld.coreMap.scene.bim.SetComponentStatus(1, idInt32Array, false)
      });
      identifyTool.storeyHighlights = []
    }
  },
  checkModelisNull(array) {
    return (array[0] === 0 && array[1] === 0 && array[2] === 0 && array[3] === 0)
  }
}
 
export default identifyTool