1 | import Konva from "konva";
|
---|
2 | import MapShape from "./MapShape";
|
---|
3 | import Factory from "../util/Factory";
|
---|
4 | import { _registerNode } from "konva/lib/Global";
|
---|
5 | export default class InfoPin extends MapShape {
|
---|
6 | constructor(mousePos, blockSize, layer, snappable,id) {
|
---|
7 | super(
|
---|
8 | {
|
---|
9 | x: mousePos.x,
|
---|
10 | y: mousePos.y,
|
---|
11 | radiusX: blockSize * 0.5,
|
---|
12 | radiusY: blockSize * 0.7,
|
---|
13 | tailHeight: blockSize * 1.2,
|
---|
14 | fill: "#d70113",
|
---|
15 | stroke: "#1b1b1b",
|
---|
16 | strokeWidth: 0.2,
|
---|
17 | draggable: true,
|
---|
18 | name: "mapObj",
|
---|
19 | },
|
---|
20 | layer,
|
---|
21 | blockSize,
|
---|
22 | snappable
|
---|
23 | );
|
---|
24 |
|
---|
25 | this.id = id;
|
---|
26 |
|
---|
27 | this.modalEventName = "openPinModalEvent";
|
---|
28 | this.type = "InfoPin";
|
---|
29 | this._info = {
|
---|
30 | name: `Pin ${id}`,
|
---|
31 | selectedPins: [],
|
---|
32 | description: "",
|
---|
33 | };
|
---|
34 |
|
---|
35 | this.on("mouseover", () => {
|
---|
36 | this.fill("yellow");
|
---|
37 | });
|
---|
38 | this.on("mouseout", () => {
|
---|
39 | this.fill("red");
|
---|
40 | });
|
---|
41 |
|
---|
42 | this.initText();
|
---|
43 | }
|
---|
44 | _sceneFunc(context, shape) {
|
---|
45 | const { radiusX, radiusY, tailHeight } = this.attrs;
|
---|
46 |
|
---|
47 | context.beginPath();
|
---|
48 | context.ellipse(0, 0, radiusX, radiusY, 0, 0, Math.PI * 2);
|
---|
49 | context.closePath();
|
---|
50 | context.fillStrokeShape(shape);
|
---|
51 |
|
---|
52 | context.beginPath();
|
---|
53 | context.moveTo(-radiusX, radiusY);
|
---|
54 | context.lineTo(0, radiusY + tailHeight);
|
---|
55 | context.lineTo(radiusX, radiusY);
|
---|
56 | context.closePath();
|
---|
57 |
|
---|
58 | context.fillStrokeShape(shape);
|
---|
59 | }
|
---|
60 |
|
---|
61 | loadInfo(attrs) {
|
---|
62 | this.info.name = attrs.obj_name;
|
---|
63 | this.info.selectedPins = attrs.connected_pins;
|
---|
64 | this.info.description = attrs.description;
|
---|
65 | }
|
---|
66 |
|
---|
67 | saveShapeDetails() {
|
---|
68 | this.setAttr("obj_name", this.info.name);
|
---|
69 | this.setAttr("connected_pins", this.info.selectedPins);
|
---|
70 | this.setAttr("description", this.info.description);
|
---|
71 | console.log(this.info, "vnatre vo info");
|
---|
72 | }
|
---|
73 | }
|
---|
74 |
|
---|
75 | InfoPin.prototype.className = "InfoPin";
|
---|
76 | _registerNode(InfoPin);
|
---|