source: imaps-frontend/src/scripts/main/MapDisplay.js@ d565449

main
Last change on this file since d565449 was d565449, checked in by stefan toskovski <stefantoska84@…>, 4 weeks ago

Update repo after prototype presentation

  • Property mode set to 100644
File size: 3.0 KB
RevLine 
[d565449]1import Konva from "konva";
2import Factory from "../util/Factory.js";
3import HttpService from "../net/HttpService.js";
4import {zoomStage} from "../util/zoomStage.js";
5export class MapDisplay {
6 constructor(containerId) {
7 this.container = document.getElementById(containerId);
8 this.containerId = containerId;
9 this.stage = new Konva.Stage({
10 container: containerId,
11 width: window.innerWidth,
12 height: window.innerHeight,
13 draggable: true,
14 });
15
16 this.shapes = [];
17 this.loaded = false;
18 this.mainLayer = new Konva.Layer();
19 this.routeLayer = new Konva.Layer();
20 this.textLayer = new Konva.Layer();
21 this.stage.add(this.mainLayer);
22 this.stage.add(this.routeLayer);
23 this.stage.add(this.textLayer);
24 this.route = new Konva.Line();
25
26 this.stage.on("resize", () => {
27 this.stage.width = window.innerWidth;
28 this.stage.height = window.innerHeight;
29 });
30
31 this.stage.on("wheel",(e) => {
32 zoomStage(e,this.stage);
33 })
34
35
36 }
37
38 deserializeMap(data) {
39 data.forEach((child) => {
40 const shape = JSON.parse(child);
41 if (shape.className !== "InfoPin") {
42 const renderedShape = Factory.createRenderedShape(
43 shape.className,
44 shape.attrs
45 );
46 this.shapes.push(renderedShape);
47 }
48 });
49 }
50
51 displayRoomNames(){
52 console.log("VLEZE")
53 this.shapes.forEach(shape => {
54 shape.displayName(this.textLayer);
55 })
56
57 this.textLayer.children.forEach(child => console.log(child,"DECAAA"));
58 }
59
60 async loadMap() {
61 const httpService = new HttpService();
62 const mapData = await httpService.get("/public/mapData");
63 console.log("DESERIALIZED --->",mapData);
64 this.deserializeMap(mapData);
65 this.shapes.forEach((shape) => {
66 this.mainLayer.add(shape);
67 });
68 this.displayRoomNames();
69 }
70
71 drawRoute(path) {
72 this.routeLayer.removeChildren();
73 console.log("====PATH====");
74 path.forEach((point) => console.log(point.x, point.y));
75
76 const pointsArray = path.flatMap((point) => [point.x, point.y]);
77
78 console.log(pointsArray, "POINTS");
79
80 let buff = [];
81 let count = 0;
82 let index = 0;
83
84 const drawNextSegment = () => {
85 if (index >= pointsArray.length) return;
86
87 buff.push(pointsArray[index]);
88 count++;
89
90 if (count % 4 === 0) {
91 const line = new Konva.Arrow({
92 points: buff,
93 stroke: "#e91332",
94 strokeWidth: 2.5,
95 dash: [5, 4],
96 lineCap: 'round',
97 lineJoin: 'round',
98 pointerLength: 7,
99 pointerWidth: 7,
100 fill:'red',
101 });
102
103 this.routeLayer.add(line);
104 this.routeLayer.draw();
105
106 console.log(buff, "BUFFER");
107 buff = [];
108 index -= 2;
109 }
110
111 index++;
112
113 setTimeout(drawNextSegment, 25);
114 };
115
116 drawNextSegment();
117}
118
119
120 search() {
121 console.log("VLEZE VO SEARCH");
122 }
123}
Note: See TracBrowser for help on using the repository browser.