poi.ts 947 B

12345678910111213141516171819202122232425262728293031323334353637
  1. import { Attrib, CustomizeShape, ShapeType } from "../../type";
  2. import { Entity, EntityProps } from "../entity";
  3. import { defaultPoiShapeFactory, poiTypes } from "./types";
  4. type PoiData = {
  5. x: number;
  6. y: number;
  7. type: string;
  8. };
  9. export type PoiAttrib = Attrib & PoiData;
  10. export class Poi<T extends PoiAttrib = PoiAttrib> extends Entity<T, ShapeType> {
  11. static namespace = "poi";
  12. constructor(props: EntityProps<T>) {
  13. props.zIndex = props.zIndex || 5;
  14. props.name = props.name || Poi.namespace + props.attrib.id;
  15. super(props);
  16. }
  17. actShape: CustomizeShape<PoiData, ShapeType, { getSize: () => number[] }>;
  18. initShape() {
  19. const factory = poiTypes[this.attrib.type] || defaultPoiShapeFactory;
  20. this.actShape = factory(this.attrib, this);
  21. return this.actShape.shape;
  22. }
  23. diffRedraw() {
  24. this.actShape.setData(this.attrib);
  25. }
  26. mounted(): void {
  27. super.mounted();
  28. this.actShape.common(null);
  29. }
  30. }