| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879 |
- import VectorType from "../enum/VectorType.js";
- import Geometry from "./Geometry";
- import { mathUtil } from "../MathUtil.js";
- import SelectState from "../enum/SelectState.js";
- import { coordinate } from "../Coordinate.js";
- export default class BgImage extends Geometry {
- constructor(url, center, vectorId) {
- super();
- this.url = url;
- if (center) {
- this.center = center; //左上角
- } else {
- this.center = {
- x: 80,
- y: 150,
- };
- }
- this.image = null;
- this.width = 540;
- this.height = 390;
- this.scale = 1; //缩放比例
- this.geoType = VectorType.BgImage;
- this.setId(vectorId);
- }
- setImageData(imgData) {
- this.image = imgData;
- }
- setResolution(width, height) {
- this.width = width;
- this.width = height;
- }
- setUrl(url) {
- this.url = url;
- }
- setScale(scale) {
- this.scale = scale;
- }
- isContain(position) {
- let p0 = {
- x: this.center.x,
- y: this.center.y,
- };
- let p1 = {
- x: this.center.x,
- y: this.center.y + this.height * this.scale,
- };
- let p2 = {
- x: this.center.x + this.width * this.scale,
- y: this.center.y + this.height * this.scale,
- };
- let p3 = {
- x: this.center.x + this.width * this.scale,
- y: this.center.y,
- };
- position = coordinate.getScreenXY(position);
- this.points = [];
- this.points.push(p0);
- this.points.push(p1);
- this.points.push(p2);
- this.points.push(p3);
- if (mathUtil.isPointInPoly(position, this.points)) {
- return SelectState.Select;
- } else {
- return null;
- }
- }
- }
|