From 33aae5dccf0e8119f1aca620914c1b75ad1c98fe Mon Sep 17 00:00:00 2001 From: hu de yi Date: Thu, 28 Aug 2025 10:03:53 +0800 Subject: [PATCH 1/2] fix Sector _containsPoint by graphical method --- packages/maptalks/src/geometry/Sector.ts | 61 +++++++++++++----------- 1 file changed, 34 insertions(+), 27 deletions(-) diff --git a/packages/maptalks/src/geometry/Sector.ts b/packages/maptalks/src/geometry/Sector.ts index 16a7f754c1..e563662a2b 100644 --- a/packages/maptalks/src/geometry/Sector.ts +++ b/packages/maptalks/src/geometry/Sector.ts @@ -1,3 +1,4 @@ +import { Geometry } from './Geometry'; import { extend, isNil } from '../core/util'; import Coordinate from '../geo/Coordinate'; import Extent from '../geo/Extent'; @@ -166,34 +167,40 @@ export class Sector extends Circle { return Circle.prototype._computePrjExtent.apply(this, arguments); } - //@internal + // @internal _containsPoint(point: Point, tolerance?: number) { - const map = this.getMap(); - if (map.isTransforming()) { - return super._containsPoint(point, tolerance); - } - const center = map._pointToContainerPoint(this._getCenter2DPoint()), - t = this._hitTestTolerance() + (tolerance || 0), - size = this.getSize(), - pc = center, - pp = point, - x = pp.x - pc.x, - y = pc.y - pp.y, - atan2 = Math.atan2(y, x), - // [0.0, 360.0) - angle = atan2 < 0 ? (atan2 + 2 * Math.PI) * 360 / (2 * Math.PI) : - atan2 * 360 / (2 * Math.PI); - const [startAngle, endAngle] = this._correctAngles(); - const sAngle = startAngle % 360, - eAngle = endAngle % 360; - let between = false; - if (sAngle > eAngle) { - between = !(angle > eAngle && angle < sAngle); - } else { - between = (angle >= sAngle && angle <= eAngle); - } - return pp.distanceTo(pc) <= (size.width / 2 + t) && between; - } + return Geometry.prototype._containsPoint.call(this, point, tolerance); + + } + + // //@internal + // _containsPoint(point: Point, tolerance?: number) { + // const map = this.getMap(); + // if (map.isTransforming()) { + // return super._containsPoint(point, tolerance); + // } + // const center = map._pointToContainerPoint(this._getCenter2DPoint()), + // t = this._hitTestTolerance() + (tolerance || 0), + // size = this.getSize(), + // pc = center, + // pp = point, + // x = pp.x - pc.x, + // y = pc.y - pp.y, + // atan2 = Math.atan2(y, x), + // // [0.0, 360.0) + // angle = atan2 < 0 ? (atan2 + 2 * Math.PI) * 360 / (2 * Math.PI) : + // atan2 * 360 / (2 * Math.PI); + // const [startAngle, endAngle] = this._correctAngles(); + // const sAngle = startAngle % 360, + // eAngle = endAngle % 360; + // let between = false; + // if (sAngle > eAngle) { + // between = !(angle > eAngle && angle < sAngle); + // } else { + // between = (angle >= sAngle && angle <= eAngle); + // } + // return pp.distanceTo(pc) <= (size.width / 2 + t) && between; + // } //@internal _computeGeodesicLength() { From 9c3728f2603a0ac7813cd93cc9d97ccaad4401b2 Mon Sep 17 00:00:00 2001 From: hu de yi Date: Thu, 28 Aug 2025 10:05:36 +0800 Subject: [PATCH 2/2] updates --- packages/maptalks/src/geometry/Sector.ts | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/packages/maptalks/src/geometry/Sector.ts b/packages/maptalks/src/geometry/Sector.ts index e563662a2b..025686a6ee 100644 --- a/packages/maptalks/src/geometry/Sector.ts +++ b/packages/maptalks/src/geometry/Sector.ts @@ -167,12 +167,6 @@ export class Sector extends Circle { return Circle.prototype._computePrjExtent.apply(this, arguments); } - // @internal - _containsPoint(point: Point, tolerance?: number) { - return Geometry.prototype._containsPoint.call(this, point, tolerance); - - } - // //@internal // _containsPoint(point: Point, tolerance?: number) { // const map = this.getMap(); @@ -202,6 +196,11 @@ export class Sector extends Circle { // return pp.distanceTo(pc) <= (size.width / 2 + t) && between; // } + // @internal + _containsPoint(point: Point, tolerance?: number) { + return Geometry.prototype._containsPoint.call(this, point, tolerance); + } + //@internal _computeGeodesicLength() { if (isNil(this._radius)) {