From 60969810cece9758659c49c60f3d02a8e05a2eff Mon Sep 17 00:00:00 2001 From: fuzhenn Date: Mon, 27 Nov 2023 10:34:23 +0800 Subject: [PATCH] ignore layer without geometries listening certain events in Map's GeometryEvents --- src/layer/OverlayLayer.js | 21 +++++++++++++++++++++ src/map/Map.Topo.js | 5 +++++ 2 files changed, 26 insertions(+) diff --git a/src/layer/OverlayLayer.js b/src/layer/OverlayLayer.js index 45a70107ec..1c63b9ec9b 100644 --- a/src/layer/OverlayLayer.js +++ b/src/layer/OverlayLayer.js @@ -52,6 +52,27 @@ class OverlayLayer extends Layer { } } + isGeometryListening(types) { + if (!this._geoList) { + return false; + } + if (!Array.isArray(types)) { + types = [types]; + } + for (let i = 0, l = this._geoList.length; i < l; i++) { + const geometry = this._geoList[i]; + if (!geometry) { + continue; + } + for (let j = 0; j < types.length; j++) { + if (geometry.listens(types[j])) { + return true; + } + } + } + return false; + } + /** * Get a geometry by its id * @param {String|Number} id - id of the geometry diff --git a/src/map/Map.Topo.js b/src/map/Map.Topo.js index 9bb9aa45fe..08ff498724 100644 --- a/src/map/Map.Topo.js +++ b/src/map/Map.Topo.js @@ -106,6 +106,11 @@ Map.include(/** @lends Map.prototype */ { opts.tolerance = opts.tolerance || 0; opts.tolerance += layer.options.geometryEventTolerance; } + if (layer.isGeometryListening && isMapGeometryEvent && opts.eventTypes.indexOf('mousemove') >= 0) { + if (!layer.isGeometryListening(opts.eventTypes)) { + return []; + } + } if (layer.identifyAtPoint) { result = layer.identifyAtPoint(containerPoint, opts); } else if (coordinate && layer.identify) {