Skip to content

Commit

Permalink
add cameraFarUndergroundInMeter to control map's camera far (#2388)
Browse files Browse the repository at this point in the history
* add cameraFarUndergroundInMeter to control map's camera far, maptalks/issues#705

* fix cameraFar when zoom is small

* fix spec
  • Loading branch information
fuzhenn authored Jul 22, 2024
1 parent 6b0aad4 commit 4d8fc1c
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 20 deletions.
19 changes: 4 additions & 15 deletions src/map/Map.Camera.ts
Original file line number Diff line number Diff line change
Expand Up @@ -679,22 +679,11 @@ Map.include(/** @lends Map.prototype */{
}(),

_getCameraFar(fov, pitch) {
// const cameraCenterDistance = this.cameraCenterDistance = distance(this.cameraPosition, this.cameraLookAt);
// return 4 * cameraCenterDistance;
const cameraCenterDistance = this.cameraCenterDistance = distance(this.cameraPosition, this.cameraLookAt);
let farZ = cameraCenterDistance;
let y = (this.options['cameraInfiniteFar'] ? 10 : 4) * cameraCenterDistance;
if (pitch > 0) {
pitch = pitch * Math.PI / 180;
if (2 / Math.PI - pitch > fov / 2) {
const tanFov = Math.tan(fov / 2);
const tanP = Math.tan(pitch);
y = Math.max((cameraCenterDistance * tanFov) / (1 / tanP - tanFov), y);
}
}
farZ += y;
//TODO 地下的图形无法显示
return farZ + 1.0;
const distanceInMeter = cameraCenterDistance / this._meterToGLPoint;
pitch = pitch * Math.PI / 180;
const cameraFarDistance = distanceInMeter + this.options['cameraFarUndergroundInMeter'] / Math.cos(pitch);
return Math.max(cameraFarDistance * this._meterToGLPoint, cameraCenterDistance * 5);
},

_calcCascadeMatrixes: function () {
Expand Down
8 changes: 4 additions & 4 deletions src/map/Map.ts
Original file line number Diff line number Diff line change
Expand Up @@ -89,11 +89,11 @@ const REDRAW_OPTIONS_PROPERTIES = ['centerCross', 'fog', 'fogColor', 'debugSky']
* @property {String} [options.renderer=canvas] - renderer type. Don't change it if you are not sure about it. About renderer, see [TODO]{@link tutorial.renderer}.
* @property {Number} [options.devicePixelRatio=null] - device pixel ratio to override device's default one
* @property {Number} [options.heightFactor=1] - the factor for height/altitude calculation,This affects the height calculation of all layers(vectortilelayer/gllayer/threelayer/3dtilelayer)
* @property {Boolean} [options.cameraInfiniteFar=false] - Increase camera far plane to infinite. Enable this option may reduce map's performance.
* @property {Boolean} [options.stopRenderOnOffscreen=true] - whether to stop map rendering when container is offscreen
* @property {Boolean} [options.originLatitudeForAltitude=40] - default latitude for map.altitudeToPoint method
* @property {Number} [options.mousemoveThrottleTime=48] - mousemove event interval time(ms)
* @property {Number} [options.maxFPS=0] - 0 means no frame is locked, otherwise the frame is locked
* @property {Number} [options.cameraFarUndergroundInMeter=2000] - camera far distance from underground in meter
* @memberOf Map
* @instance
*/
Expand Down Expand Up @@ -157,8 +157,8 @@ const options: MapOptionsType = {
'switchDragButton': false,
'mousemoveThrottleTime': MOUSEMOVE_THROTTLE_TIME,
'maxFPS': 0,
'cameraInfiniteFar': false,
'debug': false
'debug': false,
'cameraFarUndergroundInMeter': 2000
};

/**
Expand Down Expand Up @@ -2556,7 +2556,6 @@ export type MapOptionsType = {
fogColor?: any; // fixme 确认类型
devicePixelRatio?: number;
heightFactor?: number;
cameraInfiniteFar?: boolean;
originLatitudeForAltitude?: number;

viewHistory?: boolean;
Expand Down Expand Up @@ -2615,6 +2614,7 @@ export type MapOptionsType = {
layerSwitcherControl?: boolean;
navControl?: boolean;
resetControl?: boolean;
cameraFarUndergroundInMeter?: number;

}

Expand Down
4 changes: 4 additions & 0 deletions src/renderer/map/MapCanvasRenderer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,10 @@ class MapCanvasRenderer extends MapRenderer {
return true;
}

getFrameTimestamp() {
return this._frameTimestamp || 0;
}

updateMapDOM() {
const map = this.map;
// when map is zooming, container is being transformed with matrix, panel doesn't need to be moved.
Expand Down
2 changes: 1 addition & 1 deletion test/map/MapCameraSpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -627,7 +627,7 @@ describe('Map.Camera', function () {
map.setPitch(75);
map.setBearing(45);
// expect(maptalks.Util.join(map.domCssMatrix)).to.be.eql([31.819805153394643, -8.235571585149868, 0.7139488752261732, 0.6830127018922193, 31.819805153394636, 8.23557158514987, -0.7139488752261733, -0.6830127018922194, 0, -43.466662183008076, -0.27054191763364316, -0.25881904510252074, 0, 0, 46.83368719036461, 45].join());
expect(maptalks.Util.join(map.domCssMatrix)).to.be.eql([31.819805153394643,-8.235571585149868,0.693731297039628,0.6830127018922193,31.819805153394636,8.23557158514987,-0.6937312970396281,-0.6830127018922194,0,-43.466662183008076,-0.2628807214860012,-0.25881904510252074,0,0,45.635325850044154,45].join());
expect(maptalks.Util.join(map.domCssMatrix)).to.be.eql([31.819805153394643,-8.235571585149868,0.6834126770126959,0.6830127018922193,31.819805153394636,8.23557158514987,-0.683412677012696,-0.6830127018922194,0,-43.466662183008076,-0.2589706106275245,-0.25881904510252074,0,0,44.956019102246906,45].join());
});

it('setCameraPosition', function() {
Expand Down

0 comments on commit 4d8fc1c

Please sign in to comment.