| @@ -1,49 +1,46 @@ | |||
| <!DOCTYPE html> | |||
| <html lang="en"> | |||
| <head> | |||
| <meta charset="utf-8" /> | |||
| <meta name="viewport" content="width=device-width,initial-scale=1.0" /> | |||
| <title>dc-example</title> | |||
| <script src="/libs/dc-sdk/dc.min.js"></script> | |||
| <script src="../dat.gui.min.js"></script> | |||
| <link href="/libs/dc-sdk/dc.min.css" type="text/css" rel="stylesheet" /> | |||
| <link href="../index.css" type="text/css" rel="stylesheet" /> | |||
| </head> | |||
| <body> | |||
| <div id="viewer-container" class="viewer-container"></div> | |||
| <script> | |||
| let viewer = undefined | |||
| <head> | |||
| <meta charset="utf-8"> | |||
| <meta name="viewport" content="width=device-width,initial-scale=1.0"> | |||
| <title>dc-example</title> | |||
| <script src='/libs/dc-sdk/dc.min.js'></script> | |||
| <script src="../dat.gui.min.js"></script> | |||
| <link href='/libs/dc-sdk/dc.min.css' type='text/css' rel='stylesheet'> | |||
| <link href='../index.css' type='text/css' rel='stylesheet'> | |||
| </head> | |||
| function initViewer() { | |||
| viewer = new DC.Viewer('viewer-container') | |||
| let baseLayer = DC.ImageryLayerFactory.createAMapImageryLayer({ | |||
| style: 'img', | |||
| crs: 'WGS84', | |||
| }) | |||
| viewer.addBaseLayer(baseLayer) | |||
| viewer.tooltip.enable = true | |||
| viewer.on(DC.MouseEventType.MOUSE_MOVE, (e) => { | |||
| viewer.tooltip.showAt(e.windowPosition, '我是鼠标提示') | |||
| }) | |||
| addGuiController() // add controller | |||
| } | |||
| <body> | |||
| <div id="viewer-container" class="viewer-container"></div> | |||
| <script> | |||
| let viewer = undefined | |||
| function initViewer() { | |||
| viewer = new DC.Viewer('viewer-container') | |||
| let baseLayer = DC.ImageryLayerFactory.createAMapImageryLayer({ | |||
| style: 'img', | |||
| crs:'WGS84' | |||
| }) | |||
| viewer.addBaseLayer( baseLayer) | |||
| viewer.tooltip.enable = true | |||
| viewer.on(DC.MouseEventType.MOUSE_MOVE, e => { | |||
| viewer.tooltip.showAt(e.windowPosition, '我是鼠标提示') | |||
| }) | |||
| addGuiController() // add controller | |||
| } | |||
| function addGuiController(){ | |||
| let controls = { | |||
| enable :true, | |||
| } | |||
| let gui = new dat.GUI(); | |||
| gui.add(controls,'enable',).onChange(value=>{ | |||
| viewer.tooltip.enable = value | |||
| }) | |||
| } | |||
| DC.ready({ | |||
| baseUrl:'../libs/dc-sdk/resources/' | |||
| }).then(initViewer) | |||
| </script> | |||
| </body> | |||
| function addGuiController() { | |||
| let controls = { | |||
| enable: true, | |||
| } | |||
| let gui = new dat.GUI() | |||
| gui.add(controls, 'enable').onChange((value) => { | |||
| viewer.tooltip.enable = value | |||
| }) | |||
| } | |||
| DC.ready({ | |||
| baseUrl: '../libs/dc-sdk/resources/', | |||
| }).then(initViewer) | |||
| </script> | |||
| </body> | |||
| </html> | |||
| @@ -66,6 +66,6 @@ | |||
| "dist" | |||
| ], | |||
| "dependencies": { | |||
| "@dvgis/dc-common": "^3.0.0" | |||
| "@dvgis/dc-common": "^3.5.0" | |||
| } | |||
| } | |||
| @@ -75,7 +75,7 @@ class MouseEvent extends Event { | |||
| // 返回转换后的坐标。 | |||
| return new Cesium.Cartesian2(x, y) | |||
| } | |||
| /** | |||
| * | |||
| * Gets the mouse information for the mouse event | |||
| @@ -84,15 +84,14 @@ class MouseEvent extends Event { | |||
| * | |||
| */ | |||
| _getMouseInfo(position) { | |||
| let adjustedPosition = this._adjustPosition(position) | |||
| let scene = this._viewer.scene | |||
| let target = scene.pick(adjustedPosition) | |||
| let target = scene.pick(position) | |||
| let cartesian = undefined | |||
| let surfaceCartesian = undefined | |||
| let wgs84Position = undefined | |||
| let wgs84SurfacePosition = undefined | |||
| if (scene.pickPositionSupported) { | |||
| cartesian = scene.pickPosition(adjustedPosition) | |||
| cartesian = scene.pickPosition(position) | |||
| } | |||
| if (cartesian) { | |||
| let c = Cesium.Ellipsoid.WGS84.cartesianToCartographic(cartesian) | |||
| @@ -108,11 +107,11 @@ class MouseEvent extends Event { | |||
| scene.mode === Cesium.SceneMode.SCENE3D && | |||
| !(this._viewer.terrainProvider instanceof Cesium.EllipsoidTerrainProvider) | |||
| ) { | |||
| let ray = scene.camera.getPickRay(adjustedPosition) | |||
| let ray = scene.camera.getPickRay(position) | |||
| surfaceCartesian = scene.globe.pick(ray, scene) | |||
| } else { | |||
| surfaceCartesian = scene.camera.pickEllipsoid( | |||
| adjustedPosition, | |||
| position, | |||
| Cesium.Ellipsoid.WGS84 | |||
| ) | |||
| } | |||
| @@ -129,7 +128,7 @@ class MouseEvent extends Event { | |||
| return { | |||
| target: target, | |||
| windowPosition: adjustedPosition, | |||
| windowPosition: position, | |||
| position: cartesian, | |||
| wgs84Position: wgs84Position, | |||
| surfacePosition: surfaceCartesian, | |||
| @@ -45,7 +45,7 @@ class HtmlLayer extends Layer { | |||
| this._renderRemoveCallback = scene.postRender.addEventListener(() => { | |||
| let cp = this._viewer.camera.positionWC | |||
| let cd = this._viewer.camera.direction | |||
| const offset = this._viewer.getOffset(); | |||
| const offset = this._viewer.getOffset() | |||
| this.eachOverlay((item) => { | |||
| if (item && item.position) { | |||
| let position = Transform.transformWGS84ToCartesian(item.position) | |||
| @@ -53,14 +53,14 @@ class HtmlLayer extends Layer { | |||
| position, | |||
| new Cesium.Cartesian3() | |||
| ) | |||
| let windowCoord = Cesium.SceneTransforms.wgs84ToWindowCoordinates( | |||
| let windowCoord = Cesium.SceneTransforms.worldToWindowCoordinates( | |||
| scene, | |||
| position | |||
| ) | |||
| if (windowCoord) { | |||
| windowCoord.x += offset.x; | |||
| windowCoord.y += offset.y; | |||
| windowCoord.x += offset.x | |||
| windowCoord.y += offset.y | |||
| } | |||
| item._updateStyle( | |||
| windowCoord, | |||
| @@ -149,7 +149,7 @@ class Transform { | |||
| */ | |||
| static transformWGS84ToWindow(position, viewer) { | |||
| let scene = viewer.scene | |||
| return Cesium.SceneTransforms.wgs84ToWindowCoordinates( | |||
| return Cesium.SceneTransforms.worldToWindowCoordinates( | |||
| scene, | |||
| this.transformWGS84ToCartesian(position) | |||
| ) | |||
| @@ -31,13 +31,13 @@ class Viewer { | |||
| } | |||
| this._delegate = Cesium.Viewer | |||
| ? new Cesium.Viewer(id, { | |||
| ...DEF_OPTS, | |||
| ...options, | |||
| }) | |||
| ...DEF_OPTS, | |||
| ...options, | |||
| }) | |||
| : new CesiumViewer(id, { | |||
| ...DEF_OPTS, | |||
| ...options, | |||
| }) // Initialize the viewer | |||
| ...DEF_OPTS, | |||
| ...options, | |||
| }) // Initialize the viewer | |||
| /** | |||
| * Registers events | |||
| @@ -657,20 +657,24 @@ class Viewer { | |||
| return this | |||
| } | |||
| /** | |||
| * | |||
| * @returns | |||
| */ | |||
| getOffset() { | |||
| const offset = { x: 0, y: 0 }; | |||
| const container = this._delegate?.container; | |||
| const offset = { x: 0, y: 0 } | |||
| const container = this._delegate?.container | |||
| if (container) { | |||
| if (container.getBoundingClientRect) { | |||
| const rect = container.getBoundingClientRect(); | |||
| offset.x = rect.left; | |||
| offset.y = rect.top; | |||
| const rect = container.getBoundingClientRect() | |||
| offset.x = rect.left | |||
| offset.y = rect.top | |||
| } else { | |||
| offset.x = container.offsetLeft; | |||
| offset.y = container.offsetTop; | |||
| offset.x = container.offsetLeft | |||
| offset.y = container.offsetTop | |||
| } | |||
| } | |||
| return offset; | |||
| return offset | |||
| } | |||
| } | |||
| @@ -34,19 +34,19 @@ class Widget { | |||
| * mount content | |||
| * @private | |||
| */ | |||
| _mountContent() { } | |||
| _mountContent() {} | |||
| /** | |||
| * binds event | |||
| * @private | |||
| */ | |||
| _bindEvent() { } | |||
| _bindEvent() {} | |||
| /** | |||
| * Unbinds event | |||
| * @private | |||
| */ | |||
| _unbindEvent() { } | |||
| _unbindEvent() {} | |||
| /** | |||
| * When enable modifies the hook executed, the subclass copies it as required | |||
| @@ -70,13 +70,24 @@ class Widget { | |||
| * @param windowCoord | |||
| * @private | |||
| */ | |||
| _updateWindowCoord(windowCoord) { } | |||
| _updateWindowCoord(windowCoord) {} | |||
| /** | |||
| * Hook for installed | |||
| * @private | |||
| */ | |||
| _installHook() { } | |||
| _installHook() {} | |||
| /** | |||
| * | |||
| * @returns | |||
| */ | |||
| _getViewerOffset() { | |||
| if (!this._viewer) { | |||
| return { x: 0, y: 0 } | |||
| } | |||
| return this._viewer.getOffset() | |||
| } | |||
| /** | |||
| * Installs to viewer | |||
| @@ -127,13 +138,6 @@ class Widget { | |||
| `) | |||
| } | |||
| getViewerOffset() { | |||
| if (!this._viewer) { | |||
| return { x: 0, y: 0 }; | |||
| } | |||
| return this._viewer.getOffset(); | |||
| } | |||
| /** | |||
| * Registers type | |||
| * @param type | |||
| @@ -233,20 +233,15 @@ class ContextMenu extends Widget { | |||
| * @private | |||
| */ | |||
| _updateWindowCoord(windowCoord) { | |||
| let visibility = this._ulEl.hasChildNodes() ? 'visible' : 'hidden'; | |||
| let { x, y } = windowCoord; | |||
| const offset = this.getViewerOffset(); | |||
| x += offset.x; | |||
| y += offset.y; | |||
| let visibility = this._ulEl.hasChildNodes() ? 'visible' : 'hidden' | |||
| let { x, y } = windowCoord | |||
| let offset = this._getViewerOffset() | |||
| x += offset.x | |||
| y += offset.y | |||
| this._wrapper.style.cssText = ` | |||
| visibility:${visibility}; | |||
| z-index:1; | |||
| transform:translate3d(${Math.round(x)}px,${Math.round( | |||
| y | |||
| )}px, 0); | |||
| transform:translate3d(${Math.round(x)}px,${Math.round(y)}px, 0); | |||
| ` | |||
| } | |||
| @@ -40,7 +40,7 @@ class Popup extends Widget { | |||
| self._updateWindowCoord && | |||
| self._wrapper.style.visibility === 'visible' | |||
| ) { | |||
| let windowCoord = Cesium.SceneTransforms.wgs84ToWindowCoordinates( | |||
| let windowCoord = Cesium.SceneTransforms.worldToWindowCoordinates( | |||
| scene, | |||
| self._position | |||
| ) | |||
| @@ -95,9 +95,10 @@ class Popup extends Widget { | |||
| x = windowCoord.x | |||
| y = windowCoord.y | |||
| } | |||
| const offset = this.getViewerOffset(); | |||
| x += offset.x; | |||
| y += offset.y; | |||
| let offset = this._getViewerOffset() | |||
| x += offset.x | |||
| y += offset.y | |||
| this._wrapper.style.cssText = ` | |||
| visibility:visible; | |||
| @@ -38,12 +38,10 @@ class Tooltip extends Widget { | |||
| */ | |||
| _updateWindowCoord(windowCoord) { | |||
| let x = windowCoord.x + 10 | |||
| let y = windowCoord.y - this._wrapper.offsetHeight / 2; | |||
| const offset = this.getViewerOffset(); | |||
| x += offset.x; | |||
| y += offset.y; | |||
| let y = windowCoord.y - this._wrapper.offsetHeight / 2 | |||
| let offset = this._getViewerOffset() | |||
| x += offset.x | |||
| y += offset.y | |||
| this._wrapper.style.cssText = ` | |||
| visibility:visible; | |||
| z-index:1; | |||
| @@ -131,7 +131,7 @@ class WindLayer extends Layer { | |||
| this._delegate.project = (coordinate) => { | |||
| let position = Cesium.Cartesian3.fromDegrees(coordinate[0], coordinate[1]) | |||
| let coord = Cesium.SceneTransforms.wgs84ToWindowCoordinates( | |||
| let coord = Cesium.SceneTransforms.worldToWindowCoordinates( | |||
| scene, | |||
| position | |||
| ) | |||