Compass.js 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. import VectorType from '../enum/VectorType.js'
  2. import Geometry from './Geometry'
  3. import { coordinate } from '../Coordinate'
  4. import { mathUtil } from '../MathUtil.js'
  5. export default class Compass extends Geometry {
  6. constructor(angle,vectorId, floor) {
  7. super()
  8. this.angle = angle?angle:0
  9. this.floor = floor?floor:0
  10. //固定位置
  11. this.center = {
  12. x:880,
  13. y:120
  14. }
  15. this.radius = 52 //svg的大小
  16. this.geoType = VectorType.Compass
  17. this.setId(vectorId)
  18. }
  19. setAngle(angle){
  20. this.angle = angle
  21. }
  22. //center是左上角,宽是56,高是36
  23. isContain(position) {
  24. const point = coordinate.getScreenXY(position)
  25. // const dis = mathUtil.getDistance(this.center,point)
  26. // if(dis < this.radius){
  27. // return true
  28. // }
  29. // else{
  30. // return false;
  31. // }
  32. //console.log('xy:'+(point.x - this.center.x)+','+(point.y - this.center.y))
  33. if(point.x - this.center.x > -5 && point.x - this.center.x < 40 && point.y - this.center.y > -5 && point.y - this.center.y < 60){
  34. return true
  35. }else{
  36. return false;
  37. }
  38. }
  39. }