123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539 |
- import { floorplanData } from '../FloorplanData'
- import { coordinate } from '../Coordinate.js'
- import Constant from '../Constant'
- import Title from '../Geometry/Title.js'
- import BgImage from '../Geometry/BgImage.js'
- import Compass from '../Geometry/Compass.js'
- export class FloorplanService {
- constructor() {
- this.currentId = 0 // 当前可用id
- this.currentFloor = 0 // 当前楼层,第一层是0
- this.angle = 0 //旋转角度
- }
- setCurrentId(id) {
- this.currentId = id
- }
- getCurrentId() {
- return this.currentId
- }
- updateCurrentId() {
- ++this.currentId
- }
- setCurrentFloor(floor) {
- if (floorplanData.floors.length == 1) {
- this.currentFloor = 0
- } else {
- this.currentFloor = floor
- }
- }
- getCurrentFloor() {
- return this.currentFloor
- }
- getFloorNum() {
- return floorplanData.floors.length
- }
- initFloor(floorNum) {
- floorplanData.initFloor(floorNum)
- }
- getFloors() {
- return floorplanData.floors
- }
- getPoint(pointId, floor) {
- if (floor == null || typeof floor == 'undefined') {
- floor = this.currentFloor
- }
- return floorplanData.floors[floor].points[pointId]
- }
- deletePoint(pointId, wallId, floor) {
- if (floor == null || typeof floor == 'undefined') {
- floor = this.currentFloor
- }
- let point = this.getPoint(pointId)
- //有可能先删除墙,导致点没了
- if (point) {
- if (Object.keys(point.parent).length == 0) {
- point = null
- delete floorplanData.floors[floor].points[pointId]
- } else if (Object.keys(point.parent).length == 1 && !wallId) {
- delete floorplanData.floors[floor].points[pointId]
- } else if (Object.keys(point.parent).length == 1 && point.parent[wallId]) {
- delete floorplanData.floors[floor].points[pointId]
- } else if (Object.keys(point.parent).length == 1 && !point.parent[wallId]) {
- return
- } else {
- delete point.parent[wallId]
- }
- }
- }
- getWall(wallId, floor) {
- if (floor == null || typeof floor == 'undefined') {
- floor = this.currentFloor
- }
- return floorplanData.floors[floor].walls[wallId]
- }
- deleteWall(wallId, floor) {
- if (floor == null || typeof floor == 'undefined') {
- floor = this.currentFloor
- }
- let wall = this.getWall(wallId, floor)
- this.deletePoint(wall.start, wallId, floor)
- this.deletePoint(wall.end, wallId, floor)
- delete floorplanData.floors[floor].walls[wallId]
- }
- getAngle() {
- return this.angle
- }
- setAngle(angle) {
- this.angle = angle
- }
- getFloorData(floor) {
- if (floor == null || typeof floor == 'undefined') {
- floor = this.currentFloor
- }
- return floorplanData.floors[floor]
- }
- getWalls(floor) {
- if (floor == null || typeof floor == 'undefined') {
- floor = this.currentFloor
- }
- return floorplanData.floors[floor].walls
- }
- getPoints(floor) {
- if (floor == null || typeof floor == 'undefined') {
- floor = this.currentFloor
- }
- return floorplanData.floors[floor].points
- }
- addWall(wall, floor) {
- if (floor == null || typeof floor == 'undefined') {
- floor = this.currentFloor
- }
- floorplanData.floors[floor].walls[wall.vectorId] = wall
- }
- addPoint(point, floor) {
- if (floor == null || typeof floor == 'undefined') {
- floor = this.currentFloor
- }
- floorplanData.floors[floor].points[point.vectorId] = point
- }
- addRectangle(rectangle,floor){
- if (floor == null || typeof floor == 'undefined') {
- floor = this.currentFloor
- }
- floorplanData.floors[floor].rectangles[rectangle.vectorId] = rectangle
- }
- getRectangle(rectangleId, floor) {
- if (floor == null || typeof floor == 'undefined') {
- floor = this.currentFloor
- }
- return floorplanData.floors[floor].rectangles[rectangleId]
- }
- deleteRectangle(rectangleId, floor){
- if (floor == null || typeof floor == 'undefined') {
- floor = this.currentFloor
- }
- let rectangle = this.getRectangle(rectangleId, floor)
- rectangle = null
- delete floorplanData.floors[floor].rectangles[rectangleId]
- }
- addCircle(circle,floor){
- if (floor == null || typeof floor == 'undefined') {
- floor = this.currentFloor
- }
- floorplanData.floors[floor].circles[circle.vectorId] = circle
- }
- getCircle(circleId, floor) {
- if (floor == null || typeof floor == 'undefined') {
- floor = this.currentFloor
- }
- return floorplanData.floors[floor].circles[circleId]
- }
- deleteCircle(circleId, floor){
- if (floor == null || typeof floor == 'undefined') {
- floor = this.currentFloor
- }
- let circle = this.getCircle(circleId, floor)
- circle = null
- delete floorplanData.floors[floor].circles[circleId]
- }
- addArrow(arrow,floor){
- if (floor == null || typeof floor == 'undefined') {
- floor = this.currentFloor
- }
- floorplanData.floors[floor].arrows[arrow.vectorId] = arrow
- }
- getArrow(arrowId, floor) {
- if (floor == null || typeof floor == 'undefined') {
- floor = this.currentFloor
- }
- return floorplanData.floors[floor].arrows[arrowId]
- }
- deleteArrow(arrowId, floor){
- if (floor == null || typeof floor == 'undefined') {
- floor = this.currentFloor
- }
- let arrow = this.getArrow(arrowId, floor)
- arrow = null
- delete floorplanData.floors[floor].arrows[arrowId]
- }
- addIcon(icon,floor){
- if (floor == null || typeof floor == 'undefined') {
- floor = this.currentFloor
- }
- floorplanData.floors[floor].icons[icon.vectorId] = icon
- }
- getIcon(iconId, floor) {
- if (floor == null || typeof floor == 'undefined') {
- floor = this.currentFloor
- }
- return floorplanData.floors[floor].icons[iconId]
- }
- deleteIcon(iconId, floor){
- if (floor == null || typeof floor == 'undefined') {
- floor = this.currentFloor
- }
- let icon = this.getIcon(iconId, floor)
- icon = null
- delete floorplanData.floors[floor].icons[iconId]
- }
- addSign(sign, floor) {
- if (floor == null || typeof floor == 'undefined') {
- floor = this.currentFloor
- }
- floorplanData.floors[floor].signs[sign.vectorId] = sign
- }
- getSign(signId, floor) {
- if (floor == null || typeof floor == 'undefined') {
- floor = this.currentFloor
- }
- return floorplanData.floors[floor].signs[signId]
- }
- deleteSign(signId, floor) {
- if (floor == null || typeof floor == 'undefined') {
- floor = this.currentFloor
- }
- let sign = this.getSign(signId, floor)
- sign = null
- delete floorplanData.floors[floor].signs[signId]
- }
- addTag(tag, floor) {
- if (floor == null || typeof floor == 'undefined') {
- floor = this.currentFloor
- }
- floorplanData.floors[floor].tags[tag.vectorId] = tag
- }
- getTag(tagId, floor) {
- if (floor == null || typeof floor == 'undefined') {
- floor = this.currentFloor
- }
- return floorplanData.floors[floor].tags[tagId]
- }
- deleteTag(tagId, floor) {
- if (floor == null || typeof floor == 'undefined') {
- floor = this.currentFloor
- }
- let tag = this.getTag(tagId, floor)
- tag = null
- delete floorplanData.floors[floor].tags[tagId]
- }
- getTags(floor) {
- if (floor == null || typeof floor == 'undefined') {
- floor = this.currentFloor
- }
- return floorplanData.floors[floor].tags
- }
- addCustomImage(customImage, floor) {
- if (floor == null || typeof floor == 'undefined') {
- floor = this.currentFloor
- }
- floorplanData.floors[floor].customImages[customImage.vectorId] = customImage
- }
- getCustomImage(customImageId, floor) {
- if (floor == null || typeof floor == 'undefined') {
- floor = this.currentFloor
- }
- return floorplanData.floors[floor].customImages[customImageId]
- }
- deleteCustomImage(customImageId, floor) {
- if (floor == null || typeof floor == 'undefined') {
- floor = this.currentFloor
- }
- let customImage = this.getCustomImage(customImageId, floor)
- customImage = null
- delete floorplanData.floors[floor].customImages[customImageId]
- }
- addTable(table, floor) {
- if (floor == null || typeof floor == 'undefined') {
- floor = this.currentFloor
- }
- floorplanData.floors[floor].tables[table.vectorId] = table
- }
- getTable(tableId, floor) {
- if (floor == null || typeof floor == 'undefined') {
- floor = this.currentFloor
- }
- return floorplanData.floors[floor].tables[tableId]
- }
- deleteTable(tableId, floor) {
- if (floor == null || typeof floor == 'undefined') {
- floor = this.currentFloor
- }
- let table = this.getTable(tableId, floor)
- table = null
- delete floorplanData.floors[floor].tables[tableId]
- }
- getTables(floor) {
- if (floor == null || typeof floor == 'undefined') {
- floor = this.currentFloor
- }
- return floorplanData.floors[floor].tables
- }
- addCell(cell, floor) {
- if (floor == null || typeof floor == 'undefined') {
- floor = this.currentFloor
- }
- floorplanData.floors[floor].cells[cell.vectorId] = cell
- }
- getCell(cellId, floor) {
- if (floor == null || typeof floor == 'undefined') {
- floor = this.currentFloor
- }
- return floorplanData.floors[floor].cells[cellId]
- }
- deleteCell(cellId, floor) {
- if (floor == null || typeof floor == 'undefined') {
- floor = this.currentFloor
- }
- let cell = this.getCell(cellId, floor)
- cell = null
- delete floorplanData.floors[floor].cells[cellId]
- }
- getCells(floor) {
- if (floor == null || typeof floor == 'undefined') {
- floor = this.currentFloor
- }
- return floorplanData.floors[floor].cells
- }
- getRectangles(floor) {
- if (floor == null || typeof floor == 'undefined') {
- floor = this.currentFloor
- }
- return floorplanData.floors[floor].rectangles
- }
- getCircles(floor) {
- if (floor == null || typeof floor == 'undefined') {
- floor = this.currentFloor
- }
- return floorplanData.floors[floor].circles
- }
- getArrows(floor) {
- if (floor == null || typeof floor == 'undefined') {
- floor = this.currentFloor
- }
- return floorplanData.floors[floor].arrows
- }
- getIcons(floor) {
- if (floor == null || typeof floor == 'undefined') {
- floor = this.currentFloor
- }
- return floorplanData.floors[floor].icons
- }
- getSigns(floor) {
- if (floor == null || typeof floor == 'undefined') {
- floor = this.currentFloor
- }
- return floorplanData.floors[floor].signs
- }
- getCustomImages(floor){
- if (floor == null || typeof floor == 'undefined') {
- floor = this.currentFloor
- }
- return floorplanData.floors[floor].customImages
- }
- clear() {
- if (floorplanData.floors[this.currentFloor]) {
- floorplanData.floors[this.currentFloor].points = {}
- floorplanData.floors[this.currentFloor].walls = {}
- floorplanData.floors[this.currentFloor].rectangles = {}
- floorplanData.floors[this.currentFloor].circles = {}
- floorplanData.floors[this.currentFloor].tags = {}
- floorplanData.floors[this.currentFloor].tables = {}
- floorplanData.floors[this.currentFloor].cells = {}
- floorplanData.floors[this.currentFloor].signs = {}
- floorplanData.floors[this.currentFloor].customImages = {}
- floorplanData.floors[this.currentFloor].arrows = {}
- floorplanData.floors[this.currentFloor].icons = []
- }
- }
- deleteFloorData() {
- floorplanData.floors = []
- }
- createTitle(value,vectorId,floor){
- if (floor == null || typeof floor == 'undefined') {
- floor = this.currentFloor
- }
- const title = new Title(value,vectorId,floor)
- return title
- }
- addTitle(title, floor) {
- if (floor == null || typeof floor == 'undefined') {
- floor = this.currentFloor
- }
- floorplanData.floors[floor].title = title
- }
- updateTitle(value,floor){
- if (floor == null || typeof floor == 'undefined') {
- floor = this.currentFloor
- }
- const title = floorplanData.floors[floor].title
- title.setValue(value)
- }
- getTitle(floor) {
- if (floor == null || typeof floor == 'undefined') {
- floor = this.currentFloor
- }
- return floorplanData.floors[floor].title
- }
- createBgImage(value,vectorId,floor){
- if (floor == null || typeof floor == 'undefined') {
- floor = this.currentFloor
- }
- const image = new BgImage(value,vectorId,floor)
- return image
- }
- addBgImage(image, floor) {
- if (floor == null || typeof floor == 'undefined') {
- floor = this.currentFloor
- }
- floorplanData.floors[floor].image = image
- }
- async updateBgImage(src){
- const floor = this.currentFloor
- const img = floorplanData.floors[floor].image
- img.setSrc(src)
- if(img.src){
- const imageData = await floorplanService.loadImageData(img.src)
- img.setImageData(imageData)
- }
-
- }
- getBgImage(floor) {
- if (floor == null || typeof floor == 'undefined') {
- floor = this.currentFloor
- }
- return floorplanData.floors[floor].image
- }
- createCompass(value,vectorId,floor){
- if (floor == null || typeof floor == 'undefined') {
- floor = this.currentFloor
- }
- const compass = new Compass(value,vectorId,floor)
- return compass
- }
- addCompass(compass, floor) {
- if (floor == null || typeof floor == 'undefined') {
- floor = this.currentFloor
- }
- floorplanData.floors[floor].compass = compass
- }
- updateCompass(value,floor){
- if (floor == null || typeof floor == 'undefined') {
- floor = this.currentFloor
- }
- const compass = floorplanData.floors[floor].compass
- compass.setAngle(value)
- }
- // eslint-disable-next-line no-dupe-class-members
- getCompass(floor) {
- if (floor == null || typeof floor == 'undefined') {
- floor = this.currentFloor
- }
- return floorplanData.floors[floor].compass
- }
- async loadImageData(src){
- const imageData = await new Promise((resolve, reject) => {
- var img = new Image()
- img.src = src;
- img.crossOrigin=""
- img.onload = function () {
- resolve(img)
- }.bind(this)
- })
- return imageData
- }
- }
- const floorplanService = new FloorplanService()
- export { floorplanService }
|