123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297 |
- <template>
- <div :id="`drawFloor${id}`" class="drawFloor" v-loading="canvasLoading">
- <canvas :id="`floorCanvas${id}`" :width="cadWidth" :height="cadHeight" ref="canvas" tabindex="0"></canvas>
- <div class="operate" v-if="showTools">
- <canvasFun @fit="fit" @savePng="savePng" @saveSvg="saveSvg" @divide="divide" @clearDivide="clearDivide" @scale="scale"
- @changeAbsorb="changeAbsorb" :config="config" ref="canvasFun" @saveJson="saveJson"></canvasFun>
- </div>
- </div>
- </template>
- <script>
- import { DivideFloorScene, FloorView, Opt } from "@saga-web/cad-engine/lib"
- import { SColor, SPoint } from "@saga-web/draw/lib";
- import canvasFun from "@/components/old-adm/business_space/newGraphy/canvasFun"
- import ScanController from "@/controller/old-adm/ScanController";
- import { EditLineItem } from "@saga-web/cad-engine"
- import { mapGetters } from "vuex";
- export default {
- components: {
- canvasFun
- },
- data() {
- return {
- drawMainScene: null,
- view: null,
- dataKey: '',
- cadWidth: 800,
- cadHeight: 600,
- canvasLoading: false,
- FloorID: '',
- Outline: [],
- floorData: {},
- config: {
- isEdit: false,
- divide: true
- },
- shadeList: [],
- type: 1,
- scaleItem: null,
- urlModelId: '',
- };
- },
- props: {
- isEdit: {
- default: false
- },
- showTools: {
- default: false
- },
- id: {
- default: 0
- },
- dialog: {
- default: false
- }
- },
- computed: {
- ...mapGetters("layout", ["projectId", "projects"]),
- projectName() {
- let projectObj = this.projects.find(item => {
- return item.id == this.projectId
- })
- return projectObj ? projectObj.name ? projectObj.name : projectObj.id : this.projectId
- }
- },
- created() {
- this.FloorID = this.$route.query.FloorID;
- this.urlModelId = this.$route.query.modelId
- Opt.sceneMarkColor = new SColor('#00000080');
- if (!this.dialog) {
- this.init();
- }
- },
- mounted() {
- this.cadWidth = document.getElementById(`drawFloor${this.id}`).offsetWidth;
- this.cadHeight = document.getElementById(`drawFloor${this.id}`).offsetHeight;
- },
- methods: {
-
- init() {
- this.getFloorData();
- },
-
- initGraphy(Id, type) {
-
-
-
- let that = this;
- that.type = type;
- that.clearGraphy()
- that.drawMainScene = new DivideFloorScene();
- that.canvasLoading = true;
- if (type == 1) {
- that.drawMainScene.getFloorData(`${window.__systemConf.baseServiceUrl}/revit-algorithm/base-graph/query`, { ModelId: Id }).then(res => {
- that.getGraphtSuc(res)
- })
- } else if(type==2){
- that.drawMainScene.loadUrl(`${window.__systemConf.baseServiceUrl}/image-service/common/file_get?systemId=revit&key=${Id}`).then(res => {
- that.getGraphtSuc(res)
- })
- }else if(type==3){
- that.drawMainScene.loadImg(`${window.__systemConf.baseServiceUrl}/image-service/common/image_get?systemId=dataPlatform&key=${Id}`, res=>{
- that.getGraphtSuc(res)
- })
- }
- },
-
- getGraphtSuc(res) {
- this.canvasLoading = false;
- if (res == 'error') {
- this.FloorMap = '';
- console.log('数据解析异常');
- return;
- }
- if (res.Result == 'failure') {
- this.showTools = false;
- this.$message.warning(res.Message);
- return;
- }
- this.view.scene = this.drawMainScene;
- this.view.fitSceneToView();
- this.drawMainScene.isSpaceSelectable = false;
- if (this.type == 3) {
- this.addScaleItem(this.floorData.properties)
- this.$emit('getGraphSuc');
- if (this.floorData.infos && this.floorData.infos.FloorMapShift) {
- const struct = JSON.parse(this.floorData.infos.FloorMapShift)
- const x = struct.x;
- const y = struct.y;
- if (x != 0 || y != 0) {
- this.drawMainScene.imgList[0].moveTo(x, y);
- }
- }
- }
- if (this.$refs.canvasFun) {
- this.view.minScale = this.view.scale;
- this.$refs.canvasFun.everyScale = this.view.scale;
- }
- if (this.floorData.outline && this.floorData.outline.length) {
- let newArr = this.floorData.outline.map(t => {
- return new SPoint(t.X, t.Y);
- })
- this.drawMainScene.addSceneMark(newArr);
- }
- this.$emit('handled', this.floorData.outline && this.floorData.outline.length > 0)
- },
-
- getFloorData() {
- let pa = {
- filters: `id='${this.FloorID}'`,
-
-
- }
-
- const temp = this.urlModelId && this.urlModelId.split('.')[1]
- if (temp && (temp.toLowerCase() == 'png' || temp.toLowerCase() == 'jpg')) {
- ScanController.floorQueryAndSign(pa).then(res => {
- this.floorData = res.content[0];
- if (this.floorData.infos && this.floorData.infos.floorMap) {
- let floorMap = this.floorData.infos.floorMap
- this.initGraphy(floorMap, 3)
- }
- })
- } else {
-
- ScanController.floorQueryOutline(pa).then(res => {
- this.floorData = res.content[0];
- if (this.floorData.infos && this.floorData.infos.floorMap) {
- this.getOtherFloorOutLine();
- let floorMap = this.floorData.infos.floorMap
- this.initGraphy(floorMap, 2)
- }
- })
- }
- },
-
- getOtherFloorOutLine() {
- let modelid = this.floorData.modelId;
- if (modelid) {
- let pa = {
- filters: `modelId='${modelid}'`,
- cascade: [{ name: 'building' }]
- }
- this.shadeList = [];
- ScanController.floorQueryOutline(pa).then(res => {
- const temp = res.content.map(t => {
- if (t.id != this.FloorID) {
- if ( t.outline && t.outline.length) {
- let line = t.outline.map(item => {
- return new SPoint(item.X, item.Y);
- })
- this.shadeList.push(line);
- }
- return t
- }
- }).filter(item => item);
- this.drawMainScene.addAllShade(this.shadeList);
- this.$emit('changeSign', res.content.length > 1, temp);
- });
- }
- },
-
- addScaleItem(data) {
- this.scaleItem = new EditLineItem(null)
- this.scaleItem.strokeColor = SColor.Red;
- this.drawMainScene.addItem(this.scaleItem)
- if (data && data.line && data.line.length == 2) {
- this.scaleItem.line = data.line;
- this.scaleItem.text = data.text;
-
- this.scaleItem.pointChange();
- }
- },
-
- clearGraphy() {
- if (this.view) {
- this.view.scene = null;
- return
- }
- let id = `floorCanvas${this.id}`;
- this.view = new FloorView(id)
- },
-
- focus() {
- document.getElementById(`floorCanvas${this.id}`).focus()
- },
-
-
- fit() {
- this.view.fitSceneToView()
- },
-
- savePng() {
- this.view.saveImage(`${this.projectName}-${this.buildFloorName}.png`, 'png');
- },
-
- saveSvg() {
- this.view.saveSceneSvg(`${this.projectName}-${this.buildFloorName}.svg`, 6400, 4800);
- },
-
- saveJson() {
- this.view.saveFloorJson(`${this.projectName}-${this.buildFloorName}.json`)
- },
-
- divide() {
- this.drawMainScene.isMarking = true;
- },
-
- clearDivide() {
- this.drawMainScene.clearSceneMark()
- },
-
- changeAbsorb(isAbsorbing) {
- this.drawMainScene.isAbsorbing = isAbsorbing;
- },
-
- scale(val) {
- if (!this.view) {
- return;
- }
- let scale = this.view.scale;
- this.view.scaleByPoint(val / scale, this.cadWidth / 2, this.cadHeight / 2)
- },
- },
- watch: {
- "view.scale": {
- handler(n) {
- if (this.$refs.canvasFun) {
- let s = n * 10 / this.view.minScale
- this.$refs.canvasFun.sliderVal = s > 1000 ? 1000 : s;
- }
- }
- },
- "isEdit": {
- handler(n) {
- this.config.isEdit = n;
- }
- }
- }
- };
- </script>
- <style scoped lang="less">
- .drawFloor {
- width: 100%;
- height: 100%;
- position: relative;
- .operate {
- position: absolute;
- left: 50%;
- bottom: 20px;
- transform: translateX(-50%);
- z-index: 99;
- }
- }
- </style>
|