Skip to content

Commit

Permalink
Map event carray terrain data (#2209)
Browse files Browse the repository at this point in the history
* Map event  carray terrain data

* updates

* updates
  • Loading branch information
deyihu authored Feb 26, 2024
1 parent 1dc4219 commit f9d8937
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 6 deletions.
31 changes: 25 additions & 6 deletions src/map/Map.Camera.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
},

Expand Down Expand Up @@ -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);
Expand Down
9 changes: 9 additions & 0 deletions src/map/Map.DomEvents.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -355,6 +361,7 @@ Map.include(/** @lends Map.prototype */ {
}
}
}
this._wrapTerrainData(eventParam);
return eventParam;
},

Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -417,6 +425,7 @@ Map.include(/** @lends Map.prototype */ {
eventParam['viewPoint'] = map.containerPointToViewPoint(containerPoint);
eventParam['pont2d'] = map._containerPointToPoint(containerPoint);
}
this._wrapTerrainData(eventParam);
return eventParam;
}
});
Expand Down

0 comments on commit f9d8937

Please sign in to comment.