BgImage.js 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. import VectorType from "../enum/VectorType.js";
  2. import Geometry from "./Geometry";
  3. import { mathUtil } from "../MathUtil.js";
  4. import SelectState from "../enum/SelectState.js";
  5. import { coordinate } from "../Coordinate.js";
  6. export default class BgImage extends Geometry {
  7. constructor(url, center, vectorId) {
  8. super();
  9. this.url = url;
  10. if (center) {
  11. this.center = center; //左上角
  12. } else {
  13. this.center = {
  14. x: 80,
  15. y: 150,
  16. };
  17. }
  18. this.image = null;
  19. this.width = 540;
  20. this.height = 390;
  21. this.scale = 1; //缩放比例
  22. this.geoType = VectorType.BgImage;
  23. this.setId(vectorId);
  24. }
  25. setImageData(imgData) {
  26. this.image = imgData;
  27. }
  28. setResolution(width, height) {
  29. this.width = width;
  30. this.width = height;
  31. }
  32. setUrl(url) {
  33. this.url = url;
  34. }
  35. setScale(scale) {
  36. this.scale = scale;
  37. }
  38. isContain(position) {
  39. let p0 = {
  40. x: this.center.x,
  41. y: this.center.y,
  42. };
  43. let p1 = {
  44. x: this.center.x,
  45. y: this.center.y + this.height * this.scale,
  46. };
  47. let p2 = {
  48. x: this.center.x + this.width * this.scale,
  49. y: this.center.y + this.height * this.scale,
  50. };
  51. let p3 = {
  52. x: this.center.x + this.width * this.scale,
  53. y: this.center.y,
  54. };
  55. position = coordinate.getScreenXY(position);
  56. this.points = [];
  57. this.points.push(p0);
  58. this.points.push(p1);
  59. this.points.push(p2);
  60. this.points.push(p3);
  61. if (mathUtil.isPointInPoly(position, this.points)) {
  62. return SelectState.Select;
  63. } else {
  64. return null;
  65. }
  66. }
  67. }