diff --git a/src/map/Map.Camera.ts b/src/map/Map.Camera.ts index bbb93aa0d9..fb75ef863e 100644 --- a/src/map/Map.Camera.ts +++ b/src/map/Map.Camera.ts @@ -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 () { diff --git a/src/map/Map.ts b/src/map/Map.ts index 39865cc3b6..f20301f49c 100644 --- a/src/map/Map.ts +++ b/src/map/Map.ts @@ -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 */ @@ -157,8 +157,8 @@ const options: MapOptionsType = { 'switchDragButton': false, 'mousemoveThrottleTime': MOUSEMOVE_THROTTLE_TIME, 'maxFPS': 0, - 'cameraInfiniteFar': false, - 'debug': false + 'debug': false, + 'cameraFarUndergroundInMeter': 2000 }; /** @@ -2556,7 +2556,6 @@ export type MapOptionsType = { fogColor?: any; // fixme 确认类型 devicePixelRatio?: number; heightFactor?: number; - cameraInfiniteFar?: boolean; originLatitudeForAltitude?: number; viewHistory?: boolean; @@ -2615,6 +2614,7 @@ export type MapOptionsType = { layerSwitcherControl?: boolean; navControl?: boolean; resetControl?: boolean; + cameraFarUndergroundInMeter?: number; } diff --git a/src/renderer/map/MapCanvasRenderer.ts b/src/renderer/map/MapCanvasRenderer.ts index e7900111f9..156455070c 100644 --- a/src/renderer/map/MapCanvasRenderer.ts +++ b/src/renderer/map/MapCanvasRenderer.ts @@ -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. diff --git a/test/map/MapCameraSpec.js b/test/map/MapCameraSpec.js index a0143b848f..b503304824 100644 --- a/test/map/MapCameraSpec.js +++ b/test/map/MapCameraSpec.js @@ -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() {