svg-poi.ts 861 B

12345678910111213141516171819202122232425262728293031323334
  1. import { Poi, PoiData } from "./poi";
  2. import {
  3. getSVGProps,
  4. PathsShapeAct,
  5. pathsToShapeAct,
  6. } from "../../core/helper/svg";
  7. import { EntityProps } from "../../core/base/entity";
  8. import konva from "konva";
  9. export type SVGPoiData = PoiData & {
  10. type: string;
  11. };
  12. export class SVGPoi extends Poi<konva.Group> {
  13. private act: PathsShapeAct;
  14. constructor(props: EntityProps<SVGPoiData>) {
  15. const shape = new konva.Group();
  16. super({ ...props, shape });
  17. getSVGProps(props.attrib.type).then((paths) => {
  18. this.act = pathsToShapeAct(paths, undefined, true);
  19. shape.add(this.act.shape);
  20. this.setPointerStyle({
  21. common: this.act.common,
  22. hover: () => this.act.setFill("blue"),
  23. focus: () => this.act.setFill("red"),
  24. drag: () => this.act.setFill("#0cff00"),
  25. });
  26. });
  27. this.enableDrag();
  28. }
  29. }