123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199 |
- <!-- 画板 -->
- <template>
- <div ref="baseMap" class="base-map">
- <canvas
- v-loading="loading"
- id="floorMap1"
- :width="canvasWidth"
- :height="canvasHeight"
- tabindex="0"
- ></canvas>
- </div>
- </template>
- <script>
- import { SGraphView, SGraphScene } from "@persagy-web/graph";
- import { SFloorParser, getJsonz, SZoneParser } from "@persagy-web/big/lib";
- import { SColor, SPoint } from "@persagy-web/draw";
- /////////模拟接口数据
- const map1 = require("../../../public/assets/map/1.json");
- import { equipmentList } from "./data/equipmentList.js";
- import { spaceList } from "./data/spacelist.js";
- import { MarkItem } from "./addPictrueClass/MarkItem";
- import { FloorView } from "./addPictrueClass/FloorView";
- export default {
- data() {
- return {
- canvasWidth: 0, // 画布的宽
- canvasHeight: 0, // 画布的高
- view: null, // 视图 view
- scene: null, // 场景类
- dataKey: "base/f2a4b3d10d3511eb9a1da1ce4aece47c.jsonz", // 基 路径
- mapUrl: "/image-service/common/file_get?systemId=revit&key=", // 图 key
- loading: false,
- isShowColumn: false, //是否展示柱子
- isShowWall: false, //是否显示墙
- isShowVirtualWall: false, //是否显示虚拟墙
- isShowDoor: false, // 是否显示门
- isShowWindow: false, //是否显示窗户
- isSpaceSelectable: true, //是否显示空间
- };
- },
- methods: {
- // 初始化
- init() {
- this.clearImg();
- this.view ? (this.view.scene = this.scene) : null;
- // 获取压缩包数据并解压
- setTimeout(() => {
- this.parserData(map1.EntityList[0].Elements);
- });
- },
- // 解析数据并注入 scene 类中
- parserData(data) {
- let parser = new SFloorParser();
- parser.parseData(data);
- parser.spaceList.forEach((t) => {
- /////////////////////////////////////////
- // 样式调整
- // 是否显示实例
- t.visible = this.isSpaceSelectable;
- //是否展示名称
- t.showBaseName = false;
- // 显示边框色
- t.strokeColor = new SColor("#F0F3F7");
- // 填充色
- t.fillColor = new SColor("#F0F3F7");
- // 边框线宽
- t.lineWidth = 1;
- // 添加图例
- this.scene.addItem(t);
- });
- parser.wallList.forEach((t) => {
- // 是否显示
- t.visible = this.isShowWall;
- this.scene.addItem(t);
- });
- parser.virtualWallList.forEach((t) => {
- // 是否显示
- t.visible = this.isShowVirtualWall;
- this.scene.addItem(t);
- });
- parser.doorList.forEach((t) => {
- // 是否显示
- t.visible = this.isShowDoor;
- this.scene.addItem(t);
- });
- parser.columnList.forEach((t) => {
- // 是否显示
- t.visible = this.isShowColumn;
- this.scene.addItem(t);
- });
- parser.casementList.forEach((t) => {
- // 是否显示
- t.visible = this.isShowWindow;
- this.scene.addItem(t);
- });
- // 画板是否可拖动
- if (this.view) {
- this.view.DragMove = true;
- this.view.fitSceneToView();
- }
- // 获取空间
- this.mapSpace(spaceList);
- // 设备
- this.mapEquipment(equipmentList);
- },
- // 解析业务空间
- mapSpace(val) {
- if (!this.scene) return;
- const parse = new SZoneParser();
- parse.parseData(val);
- parse.zoneList.forEach((item) => {
- // 添加到场景
- item.selectable = true;
- item.showSelect = false;
- item.connect("onMouseDown", this, this.spaceDown);
- this.scene.addItem(item);
- });
- },
- // 解析设备点
- mapEquipment(val) {
- val.forEach((item) => {
- if (item.bimLocation) {
- const arr = item.bimLocation.split(",");
- const mark = {
- Id: item.equipId,
- ElementType: "Mark",
- equipId: item.equipId,
- Name: item.equipName,
- x: Number(arr[0]),
- y: Number(arr[1]),
- width: item.width,
- height: item.height,
- url: require("./../../public/assets/img/mark.png"),
- };
- // vuepress 报错 暂时注掉
- // const aaa = new MarkItem(null, mark);
- // aaa.connect("onMouseDown", this, this.equipDown);
- // this.scene.addItem(aaa);
- }
- });
- },
- // 点击设备
- equipDown(item, e) {
- this.locationGraphy(item);
- },
- // 点击空间
- spaceDown(item, e) {
- item.selected = true;
- this.sizeGraphy();
- },
- // 画布移动到中部
- locationGraphy(item) {
- let centerX = this.view.width / 2 - item.x * this.view.scale;
- let centerY = this.view.height / 2 - item.y * this.view.scale;
- this.view.origin = new SPoint(centerX, centerY);
- },
- // 局部放大
- sizeGraphy() {
- this.view.fitSelectedToView(0.9);
- },
- // 清空画布
- clearImg() {
- this.scene = new SGraphScene();
- if (this.view) {
- this.view.update();
- }
- },
- },
- watch: {
- // 监听key
- dataKey: {
- handler(val) {
- if (val) {
- this.init();
- }
- },
- immediate: true,
- },
- },
- created() {
- this.clearImg();
- },
- mounted() {
- // 获取 canvas 的宽高
- this.canvasWidth = 800;
- this.canvasHeight = 600;
- // 初始化场景类
- this.view = new FloorView("floorMap1");
- if (this.scene) {
- this.view.scene = this.scene;
- }
- },
- };
- </script>
|