"use strict"; window.Cesium3dTilesetLocationEditor = (function () { function _(cesiumViewer, tileset) { this._cesiumViewer = cesiumViewer; this._scene = cesiumViewer.scene; this._tileset = tileset; this._screenSpaceHandler = null; this._leftDown= false; this._leftDownCartesian = null; this._tilesetModelMatrixWhenLeftDown = null; this._initEventHandlers(); this._center = tileset.boundingSphere.center.clone(); this._x = tileset._offsetx; this._y = tileset._offsety; this._z = tileset._offsetz; this._visible = true; } _.prototype._disableDefaultCameraController = function () { var scene = this._cesiumViewer.scene; // disable the default event handlers scene.screenSpaceCameraController.enableRotate = false; scene.screenSpaceCameraController.enableTranslate = false; scene.screenSpaceCameraController.enableZoom = false; scene.screenSpaceCameraController.enableTilt = false; scene.screenSpaceCameraController.enableLook = false; }; _.prototype._enableDefaultCameraController = function () { var scene = this._cesiumViewer.scene; // disable the default event handlers scene.screenSpaceCameraController.enableRotate = true; scene.screenSpaceCameraController.enableTranslate = true; scene.screenSpaceCameraController.enableZoom = true; scene.screenSpaceCameraController.enableTilt = true; scene.screenSpaceCameraController.enableLook = true; }; _.prototype._initEventHandlers = function() { this._screenSpaceHandler = new Cesium.ScreenSpaceEventHandler(this._scene.canvas); var self = this; this._screenSpaceHandler.setInputAction(function(movement) { if(!self._visible) return; self._onScreeSpaceLeftDown(movement); }, Cesium.ScreenSpaceEventType.LEFT_DOWN); this._screenSpaceHandler.setInputAction(function(movement) { if(!self._visible) return; self._onScreeSpaceMove(movement); }, Cesium.ScreenSpaceEventType.MOUSE_MOVE); this._screenSpaceHandler.setInputAction(function(movement) { if(!self._visible) return; self._onScreeSpaceLeftUp(movement); }, Cesium.ScreenSpaceEventType.LEFT_UP); }; _.prototype._onScreeSpaceLeftDown = function(movement) { var pick = viewer.scene.pick(movement.position); if (!Cesium.defined(pick)) return; this._leftDown = true; this._disableDefaultCameraController(); console.log("down"); }; _.prototype._onScreeSpaceLeftUp = function(movement) { this._leftDown = false; console.log("up"); this._enableDefaultCameraController(); }; _.prototype._onScreeSpaceMove = function(movement) { if(!this._leftDown) return; console.log("move"); var a = this._cesiumViewer.scene.pickPosition(movement.endPosition); var cartographic = Cesium.Cartographic.fromCartesian(a); const cartographic2 = Cesium.Cartographic.fromCartesian( this._center ); const surface = Cesium.Cartesian3.fromRadians( cartographic2.longitude, cartographic2.latitude, 0.0 ); var height = $("#modelZ").val(); const offset = Cesium.Cartesian3.fromRadians( cartographic.longitude, cartographic.latitude, height ); const translation = Cesium.Cartesian3.subtract( offset, surface, new Cesium.Cartesian3() ); this._tileset.modelMatrix = Cesium.Matrix4.fromTranslation(translation); $("#modelX").val(a.x - this._center.x + this._x); $("#modelY").val(a.y - this._center.y + this._y); // $("#modelZ").val(a.z - this._center.z + this._z); // $("#modelX").val(a.x - this._center.x); // $("#modelY").val(a.y - this._center.y); // $("#modelZ").val(a.z - this._center.z); }; _.prototype.setVisible = function(visible) { this._visible = visible; }; return _; }());