From 95c5ec4bbf98c04791f7488563bcac9cd8381e11 Mon Sep 17 00:00:00 2001 From: tengge1 <930372551@qq.com> Date: Wed, 17 Apr 2019 21:09:25 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8Dbug=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ShadowEditor.Web/src/editor/bottom/ScenePanel.js | 4 +++- ShadowEditor.Web/src/gis/Globe.js | 11 ++++++----- ShadowEditor.Web/src/gis/Scene.js | 9 +++++++-- ShadowEditor.Web/src/gis/view/OrbitViewer.js | 6 +++--- 4 files changed, 19 insertions(+), 11 deletions(-) diff --git a/ShadowEditor.Web/src/editor/bottom/ScenePanel.js b/ShadowEditor.Web/src/editor/bottom/ScenePanel.js index 2bc48f35..36f923bb 100644 --- a/ShadowEditor.Web/src/editor/bottom/ScenePanel.js +++ b/ShadowEditor.Web/src/editor/bottom/ScenePanel.js @@ -233,7 +233,9 @@ ScenePanel.prototype.onLoad = function (data) { if (this.app.editor.gis) { this.app.editor.gis.stop(); } - this.app.editor.gis = new GISScene(this.app); + this.app.editor.gis = new GISScene(this.app, { + useCameraPosition: true, + }); this.app.editor.gis.start(); } } diff --git a/ShadowEditor.Web/src/gis/Globe.js b/ShadowEditor.Web/src/gis/Globe.js index 2b6b3787..8be30ca7 100644 --- a/ShadowEditor.Web/src/gis/Globe.js +++ b/ShadowEditor.Web/src/gis/Globe.js @@ -14,16 +14,15 @@ import WGS84 from './core/WGS84'; * @param {THREE.WebGLRenderer} renderer 渲染器 * @param {Object} options 配置 * @param {String} options.server 服务端配置 + * @param {Boolean} options.useCameraPosition 是否使用相机位置 * @param {Number} options.maxThread 最大工作线程数,避免任务创建过多,导致地图卡顿 */ function Globe(camera, renderer, options = {}) { THREE.Object3D.call(this); options.server = options.server || location.origin; + options.useCameraPosition = options.useCameraPosition || false; options.maxThread = options.maxThread || 10; - options.lon = options.lon || 0; - options.lat = options.lat || 0; - options.zoom = options.zoom || 2; this.name = L_GLOBE; @@ -50,8 +49,10 @@ function Globe(camera, renderer, options = {}) { this.renderers = new Renderers(this); this.viewer = new OrbitViewer(this.camera, this.renderer.domElement); - // 相机位置 - this.viewer.setPosition(options.lon, options.lat, GeoUtils.zoomToAlt(options.zoom)); + // 如果不使用相机位置,则设置默认中心点 + if (!this.options.useCameraPosition) { + this.viewer.setPosition(0, 0, GeoUtils.zoomToAlt(2)); + } } Globe.prototype = Object.create(THREE.Object3D.prototype); diff --git a/ShadowEditor.Web/src/gis/Scene.js b/ShadowEditor.Web/src/gis/Scene.js index 44292c15..0c34d20f 100644 --- a/ShadowEditor.Web/src/gis/Scene.js +++ b/ShadowEditor.Web/src/gis/Scene.js @@ -3,10 +3,14 @@ import Globe from './Globe'; /** * GIS场景 * @author tengge / https://github.com/tengge1 - * @param {*} app + * @param {*} app 应用程序 + * @param {Object} options 配置 + * @param {Boolean} options.useCameraPosition 是否使用相机位置 */ -function Scene(app) { +function Scene(app, options = {}) { this.app = app; + this.options = options; + this.options.useCameraPosition = this.options.useCameraPosition || false; } Scene.prototype.start = function () { @@ -24,6 +28,7 @@ Scene.prototype.start = function () { this.globe = new Globe(editor.camera, editor.renderer, { server: this.app.options.server, + useCameraPosition: this.options.useCameraPosition, }); editor.scene.add(this.globe); this.oldSceneBeforeRender = editor.scene.onBeforeRender; diff --git a/ShadowEditor.Web/src/gis/view/OrbitViewer.js b/ShadowEditor.Web/src/gis/view/OrbitViewer.js index 9f842c3c..5272be09 100644 --- a/ShadowEditor.Web/src/gis/view/OrbitViewer.js +++ b/ShadowEditor.Web/src/gis/view/OrbitViewer.js @@ -135,15 +135,15 @@ OrbitViewer.prototype.onMouseWheel = function () { var d = delta * (distance - WGS84.a) / 1000; - var d_1 = GeoUtils.zoomToAlt(-1) + WGS84.a; + var d_1 = GeoUtils.zoomToAlt(2) + WGS84.a; - if (distance + d >= d_1) { // 最远0层级距离 + if (distance + d >= d_1) { // 最远2层级距离 d = 0; } var d_2 = GeoUtils.zoomToAlt(18) + WGS84.a; - if (distance + d <= d_2) { // 最近16层级 + if (distance + d <= d_2) { // 最近18层级 d = 0; }