Changeset 79a0317 for imaps-frontend/src/scripts/main/MapBuilder.js
- Timestamp:
- 01/21/25 03:08:24 (3 days ago)
- Branches:
- main
- Parents:
- 0c6b92a
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
imaps-frontend/src/scripts/main/MapBuilder.js
r0c6b92a r79a0317 21 21 22 22 // TODO AKO DRAGNIT NEKOJ OD POCETOK NA STAGE POZICIIVE KE SA ZEZNAT 23 // TODO jwt vo cookie24 23 // TODO placed shape i mouseMoveHandler da ne callback ( da ne vrakjat funkcija) 25 24 // TODO text na top layer sekogas … … 35 34 this.textLayer = new Konva.Layer(); 36 35 this.gridLayer.listening(false); 36 37 this.isDrawEventBound = false; 37 38 38 39 … … 96 97 setupEventListeners() { 97 98 document.getElementById("shapeOptions").addEventListener("click", this.selectShape.bind(this)); 98 window.addEventListener("keydown", this.handleExitSelection.bind(this));99 window.addEventListener("keydown", this.handleDelete.bind(this));100 window.addEventListener("keydown", this.rotateShapesBy90Deg.bind(this));101 window.addEventListener("keydown", this.toggleEfficientDrawingMode.bind(this));99 // window.addEventListener("keydown", this.handleExitSelection.bind(this)); 100 // window.addEventListener("keydown", this.handleDelete.bind(this)); 101 // window.addEventListener("keydown", this.rotateShapesBy90Deg.bind(this)); 102 // window.addEventListener("keydown", this.toggleEfficientDrawingMode.bind(this)); 102 103 window.addEventListener("resize", this.handleResize.bind(this)); 103 104 … … 107 108 this.boundEfficientDrawingModeEventListener = this.toggleEfficientDrawingMode.bind(this); 108 109 109 //this.attachKeyPressEventListeners();110 this.attachKeyPressEventListeners(); 110 111 111 112 this.stage.on("mousedown touchstart", this.handleMouseDown.bind(this)); … … 119 120 120 121 detachKeyPressEventListeners() { 122 console.log("DETACH") 121 123 window.removeEventListener("keydown", this.boundEscapeEventListener); 122 124 window.removeEventListener("keydown", this.boundDeleteEventListener); … … 126 128 127 129 attachKeyPressEventListeners() { 130 console.log("ATTACH") 128 131 window.addEventListener("keydown", this.boundEscapeEventListener); 129 132 window.addEventListener("keydown", this.boundDeleteEventListener); … … 269 272 let infoPin = Factory.createShape("InfoPin", attrs); 270 273 addEventHandling(infoPin, this, "dblclick"); 271 //this.shapes.push(infoPin);272 274 ShapeRegistry.add(infoPin) 273 275 this.mainLayer.add(infoPin); … … 307 309 308 310 const placedObj = Factory.createShape(this.hoverObj.type, attrs); 311 309 312 if (!placedObj) return; 310 313 … … 312 315 313 316 this.mainLayer.add(placedObj); 314 //this.shapes.push(placedObj);315 console.log("VO PLACED SHAEPS WALL ZITI SE: " + placedObj.className);316 317 ShapeRegistry.add(placedObj); 317 318 addEventHandling(placedObj, this, "dblclick"); 318 319 this.mainLayer.draw(); 319 320 320 // site ovie func da se vo edna funkcija vo shape. 321 321 322 322 placedObj.displayName(this.textLayer); 323 323 placedObj.snapToGrid(); 324 placedObj.onPlace(); 324 325 325 326 triggerMapSave(); … … 328 329 this.stopDrawing(); 329 330 } 331 this.mainTransformer.nodes([]) 330 332 } 331 333 332 334 stopDrawing() { 333 this.mainTransformer.nodes([]); 334 if (this.hoverObj != null) this.hoverObj.remove(); 335 this.dragLayer.removeChildren(); 336 this.stage.off("mousemove", this.boundMouseMoveHandler); 337 this.stage.off("click", this.boundPlaceShapeHandler); 335 if(this.isDrawEventBound){ 336 this.mainTransformer.nodes([]); 337 if (this.hoverObj != null) this.hoverObj.remove(); 338 this.dragLayer.removeChildren(); 339 this.stage.off("mousemove", this.boundMouseMoveHandler); 340 this.stage.off("click", this.boundPlaceShapeHandler); 341 this.isDrawEventBound = false; 342 } 343 338 344 } 339 345 … … 365 371 this.dragLayer.add(this.hoverObj); 366 372 this.dragLayer.moveToTop(); 373 374 367 375 this.boundMouseMoveHandler = this.mouseMoveHandler.bind(this); 368 376 this.boundPlaceShapeHandler = this.placeShape.bind(this); 377 this.isDrawEventBound = true; 369 378 370 379 this.stage.on("mousemove", this.boundMouseMoveHandler); … … 374 383 selectShape(e) { 375 384 if (e.target.tagName === "LI") { 385 this.stopDrawing() 376 386 const shapeType = e.target.getAttribute("data-info"); 377 387 this.startDrawing(shapeType); 378 this.mainTransformer.nodes([]) ;388 this.mainTransformer.nodes([]) 379 389 } 380 390 } … … 464 474 465 475 saveShapeDetails() { 466 // this.shapes.forEach(shape => {467 // shape.saveShapeDetails();468 // console.log(shape.info);469 // });470 476 ShapeRegistry.saveDetails(); 471 477 console.log("thisflornum",this.floorNum) … … 478 484 } 479 485 480 getPayload(){481 this.saveShapeDetails();482 return {483 shapes: ShapeRegistry.getShapes(this.floorNum),484 roomTypes: JSON.stringify(this.roomTypes),485 mapName: this.mapName,486 floorNum: this.floorNum487 }488 }489 486 490 487 491 488 handleStageClick(e) { 492 489 if (this.selectionRectangle.visible()) { 490 console.log("STAGECLICK1") 493 491 return; 494 492 } 495 493 496 494 if (e.target === this.stage) { 495 console.log("STAGECLICK2") 497 496 this.mainTransformer.nodes([]); 498 497 return; … … 500 499 501 500 if (!e.target.hasName("mapObj")) { 501 console.log("STAGECLICK3") 502 502 return; 503 503 } … … 505 505 const metaPressed = e.evt.shiftKey || e.evt.ctrlKey || e.evt.metaKey; 506 506 const isSelected = this.mainTransformer.nodes().indexOf(e.target) >= 0; 507 507 508 508 509 if (!metaPressed && !isSelected) { … … 527 528 } 528 529 529 getRoomTypes() {530 return this.roomTypes;531 }532 533 getRooms() {534 return this.getShapeInfoByType("Room");535 }536 537 getPins() {538 return this.getShapeInfoByType("InfoPin");539 }540 541 getEntrances() {542 return this.getShapeInfoByType("Entrance");543 }544 545 546 547 getShapeInfoByType(type) {548 return ShapeRegistry.getShapes(this.floorNum).filter((shape) => shape.className === type).map((shape) => shape.info);549 }550 551 530 552 531 drawConnection(node1Name, node2Name) { 553 532 554 533 ShapeRegistry.drawConnection(node1Name,node2Name); 555 }556 557 getNodeByName(name) {558 return ShapeRegistry.getShapes(this.floorNum).filter(shape => shape instanceof MapNode && shape.info.name === name)[0];559 534 } 560 535 … … 571 546 } 572 547 573 isMainEntranceSelected() {574 console.log(this.getEntrances().forEach((en) => console.log(en.isMainEntrance, "asdsad")));575 576 let hasMainEntrance = false;577 578 this.getEntrances().forEach((entrance) => {579 if (entrance.isMainEntrance === true) hasMainEntrance = true;580 });581 582 return hasMainEntrance;583 584 }585 548 586 549 clearMap() { … … 653 616 this.mainLayer.add(this.selectionRectangle); 654 617 655 ShapeRegistry.getShapes(this.floorNum).forEach((shape) => shape.displayName(this.textLayer)); 618 ShapeRegistry.getShapes(this.floorNum).forEach((shape) => { 619 shape.displayName(this.textLayer); 620 if(shape.className === "Entrance"){ 621 shape.setHighlight(); 622 } 623 }); 656 624 } 657 625
Note:
See TracChangeset
for help on using the changeset viewer.