From f9d8937f40e6b092187a872f4c28137ca3912427 Mon Sep 17 00:00:00 2001 From: hu de yi Date: Mon, 26 Feb 2024 16:16:48 +0800 Subject: [PATCH] Map event carray terrain data (#2209) * Map event carray terrain data * updates * updates --- src/map/Map.Camera.js | 31 +++++++++++++++++++++++++------ src/map/Map.DomEvents.js | 9 +++++++++ 2 files changed, 34 insertions(+), 6 deletions(-) diff --git a/src/map/Map.Camera.js b/src/map/Map.Camera.js index 598ed232f..ebcdc5c73 100644 --- a/src/map/Map.Camera.js +++ b/src/map/Map.Camera.js @@ -270,13 +270,13 @@ Map.include(/** @lends Map.prototype */{ _setCameraMovement(frameOption, frame) { this.animateTo({ - zoom : frameOption.zoom, - center : frameOption.center, - pitch : frameOption.pitch, - bearing : frameOption.bearing + zoom: frameOption.zoom, + center: frameOption.center, + pitch: frameOption.pitch, + bearing: frameOption.bearing }, { - duration : frameOption.duration, - easing : 'out' + duration: frameOption.duration, + easing: 'out' }, frame); }, @@ -871,6 +871,25 @@ Map.include(/** @lends Map.prototype */{ return false; }, + _queryTerrainInfo(containerPoint) { + const layers = this._getLayers() || []; + for (let i = 0; i < layers.length; i++) { + const layer = layers[i]; + if (containerPoint && layer && layer.queryTerrainAtPoint && layer.getTerrainLayer && layer.getTerrainLayer()) { + const coordinate = layer.queryTerrainAtPoint(containerPoint); + if (coordinate) { + return { + coordinate, + altitude: coordinate.z + }; + } else { + break; + } + } + } + return null; + }, + _getFovRatio() { const fov = this.getFov(); return Math.tan(fov / 2 * RADIAN); diff --git a/src/map/Map.DomEvents.js b/src/map/Map.DomEvents.js index b89dafe30..a49ec8fc9 100644 --- a/src/map/Map.DomEvents.js +++ b/src/map/Map.DomEvents.js @@ -330,6 +330,12 @@ Map.include(/** @lends Map.prototype */ { return false; }, + _wrapTerrainData(eventParam) { + if (eventParam.containerPoint && !eventParam.terrain) { + eventParam.terrain = this._queryTerrainInfo(eventParam.containerPoint); + } + }, + _parseEvent(e, type) { if (!e) { return null; @@ -355,6 +361,7 @@ Map.include(/** @lends Map.prototype */ { } } } + this._wrapTerrainData(eventParam); return eventParam; }, @@ -382,6 +389,7 @@ Map.include(/** @lends Map.prototype */ { } const eventParam = this._parseEvent(e, type); + this._wrapTerrainData(eventParam); if (isMoveEvent(type)) { this.getRenderer().callInNextFrame(() => { if (eventParam.domEvent && eventParam.domEvent._cancelBubble) { @@ -417,6 +425,7 @@ Map.include(/** @lends Map.prototype */ { eventParam['viewPoint'] = map.containerPointToViewPoint(containerPoint); eventParam['pont2d'] = map._containerPointToPoint(containerPoint); } + this._wrapTerrainData(eventParam); return eventParam; } });