| @@ -1,6 +1,5 @@ | |||
| { | |||
| "eslintIntegration": true, | |||
| "singleQuote": true, | |||
| "printWidth": 150, | |||
| "semi": false | |||
| } | |||
| @@ -2,7 +2,7 @@ | |||
| * @Author: Caven | |||
| * @Date: 2019-12-31 16:58:31 | |||
| * @Last Modified by: Caven | |||
| * @Last Modified time: 2020-02-01 14:45:04 | |||
| * @Last Modified time: 2020-02-04 13:27:36 | |||
| */ | |||
| import Cesium from '@/namespace' | |||
| @@ -15,9 +15,21 @@ class MouseEvent extends Event { | |||
| this._handler = new Cesium.ScreenSpaceEventHandler(this._viewer.canvas) | |||
| this._registerEvent() | |||
| this.on(Cesium.ScreenSpaceEventType.LEFT_CLICK, this._clickCallback, this) | |||
| this.on(Cesium.ScreenSpaceEventType.LEFT_DOUBLE_CLICK, this._dbclickCallback, this) | |||
| this.on(Cesium.ScreenSpaceEventType.RIGHT_CLICK, this._rightClickCallback, this) | |||
| this.on(Cesium.ScreenSpaceEventType.MOUSE_MOVE, this._mouseMoveCallback, this) | |||
| this.on( | |||
| Cesium.ScreenSpaceEventType.LEFT_DOUBLE_CLICK, | |||
| this._dbclickCallback, | |||
| this | |||
| ) | |||
| this.on( | |||
| Cesium.ScreenSpaceEventType.RIGHT_CLICK, | |||
| this._rightClickCallback, | |||
| this | |||
| ) | |||
| this.on( | |||
| Cesium.ScreenSpaceEventType.MOUSE_MOVE, | |||
| this._mouseMoveCallback, | |||
| this | |||
| ) | |||
| } | |||
| /** | |||
| @@ -44,7 +56,7 @@ class MouseEvent extends Event { | |||
| let feature = undefined | |||
| if (target.id && target.id instanceof Cesium.Entity) { | |||
| layer = target.id.layer | |||
| if (layer) { | |||
| if (layer && layer.getOverlay) { | |||
| overlay = layer.getOverlay(target.id.id) | |||
| } | |||
| //todo | |||
| @@ -109,7 +121,11 @@ class MouseEvent extends Event { | |||
| } | |||
| let target = this._viewer.scene.pick(movement.position) | |||
| let cartesian = this._viewer.scene.pickPosition(movement.position) | |||
| this._raiseEvent(Cesium.ScreenSpaceEventType.LEFT_DOUBLE_CLICK, target, cartesian) | |||
| this._raiseEvent( | |||
| Cesium.ScreenSpaceEventType.LEFT_DOUBLE_CLICK, | |||
| target, | |||
| cartesian | |||
| ) | |||
| } | |||
| /** | |||
| @@ -2,7 +2,7 @@ | |||
| * @Author: Caven | |||
| * @Date: 2020-01-13 10:13:53 | |||
| * @Last Modified by: Caven | |||
| * @Last Modified time: 2020-01-31 15:05:07 | |||
| * @Last Modified time: 2020-02-03 13:44:14 | |||
| */ | |||
| import Cesium from '@/namespace' | |||
| import Layer from './Layer' | |||
| @@ -67,6 +67,9 @@ DC.GeoJsonLayer = class extends Layer { | |||
| return this | |||
| } | |||
| /** | |||
| * | |||
| */ | |||
| toVectorLayer() { | |||
| let layer = new DC.VectorLayer(this._id) | |||
| let self = this | |||
| @@ -2,7 +2,7 @@ | |||
| * @Author: Caven | |||
| * @Date: 2020-01-09 09:16:27 | |||
| * @Last Modified by: Caven | |||
| * @Last Modified time: 2020-01-31 15:05:09 | |||
| * @Last Modified time: 2020-02-02 14:10:48 | |||
| */ | |||
| import Cesium from '@/namespace' | |||
| @@ -2,7 +2,7 @@ | |||
| * @Author: Caven | |||
| * @Date: 2020-01-03 09:38:21 | |||
| * @Last Modified by: Caven | |||
| * @Last Modified time: 2020-01-31 15:05:35 | |||
| * @Last Modified time: 2020-02-02 14:18:15 | |||
| */ | |||
| import LayerEvent from '../event/LayerEvent' | |||
| @@ -129,14 +129,21 @@ class Layer { | |||
| clear() {} | |||
| /** | |||
| * | |||
| */ | |||
| remove() { | |||
| if (this._viewer) { | |||
| this._viewer.removeLayer(this) | |||
| } | |||
| } | |||
| /** | |||
| * | |||
| * @param {*} viewer | |||
| */ | |||
| addToViewer(viewer) { | |||
| if (viewer) { | |||
| if (viewer && viewer.addLayer) { | |||
| viewer.addLayer(this) | |||
| } | |||
| return this | |||
| @@ -2,7 +2,7 @@ | |||
| * @Author: Caven | |||
| * @Date: 2019-12-30 09:24:37 | |||
| * @Last Modified by: Caven | |||
| * @Last Modified time: 2020-01-31 15:05:52 | |||
| * @Last Modified time: 2020-02-01 21:44:39 | |||
| */ | |||
| import Cesium from '@/namespace' | |||
| @@ -14,9 +14,10 @@ class ViewerOption { | |||
| } | |||
| _init() { | |||
| this._viewer.delegate._cesiumWidget._creditContainer.style.display = 'none' | |||
| this._viewer.delegate.scene.backgroundColor = Cesium.Color.TRANSPARENT | |||
| this._viewer.delegate.cesiumWidget._creditContainer.style.display = 'none' | |||
| this._viewer.delegate.cesiumWidget.screenSpaceEventHandler.removeInputAction(Cesium.ScreenSpaceEventType.LEFT_DOUBLE_CLICK) | |||
| this._viewer.delegate.scene.screenSpaceCameraController.maximumZoomDistance = 40489014.0 | |||
| this._viewer.delegate.scene.backgroundColor = Cesium.Color.TRANSPARENT | |||
| } | |||
| _setViewerOption(options) { | |||
| @@ -2,7 +2,7 @@ | |||
| * @Author: Caven | |||
| * @Date: 2020-01-03 12:18:17 | |||
| * @Last Modified by: Caven | |||
| * @Last Modified time: 2020-02-01 11:57:48 | |||
| * @Last Modified time: 2020-02-04 14:29:34 | |||
| */ | |||
| import OverlayEvent from '../event/OverlayEvent' | |||
| class Overlay { | |||
| @@ -16,7 +16,11 @@ class Overlay { | |||
| this._attr = {} | |||
| this._overlayEvent = new OverlayEvent() | |||
| this._overlayEvent.on(DC.OverlayEventType.ADD, this._addCallback, this) | |||
| this._overlayEvent.on(DC.OverlayEventType.REMOVE, this._removeCallback, this) | |||
| this._overlayEvent.on( | |||
| DC.OverlayEventType.REMOVE, | |||
| this._removeCallback, | |||
| this | |||
| ) | |||
| this.type = undefined | |||
| } | |||
| @@ -96,6 +100,38 @@ class Overlay { | |||
| this._layer.layerEvent.fire(DC.LayerEventType.REMOVE_OVERLAY, this) | |||
| } | |||
| } | |||
| /** | |||
| * | |||
| * @param {*} type | |||
| * @param {*} callback | |||
| * @param {*} context | |||
| */ | |||
| on(type, callback, context) { | |||
| this._overlayEvent.on(type, callback, context || this) | |||
| return this | |||
| } | |||
| /** | |||
| * | |||
| * @param {*} type | |||
| * @param {*} callback | |||
| * @param {*} context | |||
| */ | |||
| off(type, callback, context) { | |||
| this._overlayEvent.off(type, callback, context || this) | |||
| return this | |||
| } | |||
| /** | |||
| * | |||
| * @param {*} type | |||
| * @param {*} param | |||
| */ | |||
| fire(type, params) { | |||
| this._overlayEvent.fire(type, params) | |||
| return this | |||
| } | |||
| } | |||
| export default Overlay | |||
| @@ -2,7 +2,7 @@ | |||
| * @Author: Caven | |||
| * @Date: 2020-01-19 10:18:23 | |||
| * @Last Modified by: Caven | |||
| * @Last Modified time: 2020-02-01 12:05:36 | |||
| * @Last Modified time: 2020-02-01 18:31:04 | |||
| */ | |||
| import Cesium from '@/namespace' | |||
| @@ -93,7 +93,7 @@ DC.Billboard = class extends Overlay { | |||
| * @param {*} text | |||
| * @param {*} textStyle | |||
| */ | |||
| bindLabel(text, textStyle) { | |||
| setLabel(text, textStyle) { | |||
| this._delegate.label = { | |||
| ...textStyle, | |||
| text: text | |||
| @@ -123,6 +123,9 @@ DC.Billboard = class extends Overlay { | |||
| let billboard = undefined | |||
| if (entity.billboard) { | |||
| billboard = new DC.Billboard(position, entity.billboard.image) | |||
| billboard.attr = { | |||
| name: entity.name | |||
| } | |||
| billboard.setStyle({ | |||
| ...entity.billboard | |||
| }) | |||
| @@ -2,7 +2,7 @@ | |||
| * @Author: Caven | |||
| * @Date: 2020-01-31 18:57:02 | |||
| * @Last Modified by: Caven | |||
| * @Last Modified time: 2020-02-01 12:04:08 | |||
| * @Last Modified time: 2020-02-01 18:29:13 | |||
| */ | |||
| import Cesium from '@/namespace' | |||
| import Overlay from '../Overlay' | |||
| @@ -80,7 +80,7 @@ DC.Circle = class extends Overlay { | |||
| * @param {*} text | |||
| * @param {*} textStyle | |||
| */ | |||
| bindLabel(text, textStyle) { | |||
| setLabel(text, textStyle) { | |||
| this._delegate.label = { | |||
| text: text, | |||
| ...textStyle | |||
| @@ -2,7 +2,7 @@ | |||
| * @Author: Caven | |||
| * @Date: 2020-01-06 15:03:25 | |||
| * @Last Modified by: Caven | |||
| * @Last Modified time: 2020-02-01 11:58:47 | |||
| * @Last Modified time: 2020-02-01 18:29:54 | |||
| */ | |||
| import Cesium from '@/namespace' | |||
| @@ -68,6 +68,10 @@ DC.Point = class extends Overlay { | |||
| this._delegate.overlayId = this._id | |||
| } | |||
| /** | |||
| * | |||
| * @param {*} style | |||
| */ | |||
| setStyle(style) { | |||
| if (Object.keys(style).length === 0) { | |||
| return | |||
| @@ -2,14 +2,17 @@ | |||
| * @Author: Caven | |||
| * @Date: 2020-01-09 09:10:37 | |||
| * @Last Modified by: Caven | |||
| * @Last Modified time: 2020-02-01 11:58:54 | |||
| * @Last Modified time: 2020-02-04 15:24:43 | |||
| */ | |||
| import Overlay from '../Overlay' | |||
| import Cesium from '@/namespace' | |||
| DC.Polygon = class extends Overlay { | |||
| constructor(positions) { | |||
| if (!positions || (typeof positions !== 'string' && !Array.isArray(positions))) { | |||
| if ( | |||
| !positions || | |||
| (typeof positions !== 'string' && !Array.isArray(positions)) | |||
| ) { | |||
| throw new Error('the positions invalid') | |||
| } | |||
| super() | |||
| @@ -40,7 +43,9 @@ DC.Polygon = class extends Overlay { | |||
| } | |||
| get center() { | |||
| let boundingSphere = Cesium.BoundingSphere.fromPoints(DC.T.transformWSG84ArrayToCartesianArray(this._positions)) | |||
| let boundingSphere = Cesium.BoundingSphere.fromPoints( | |||
| DC.T.transformWSG84ArrayToCartesianArray(this._positions) | |||
| ) | |||
| return DC.T.transformCartesianToWSG84(boundingSphere.center) | |||
| } | |||
| @@ -52,8 +57,12 @@ DC.Polygon = class extends Overlay { | |||
| let positions = [...this._positions] | |||
| positions.push(positions[0]) | |||
| for (let i = 1; i < positions.length; i++) { | |||
| let oel = ellipsoid.cartographicToCartesian(DC.T.transformWSG84ToCartographic(positions[i - 1])) | |||
| let el = ellipsoid.cartographicToCartesian(DC.T.transformWSG84ToCartographic(positions[i])) | |||
| let oel = ellipsoid.cartographicToCartesian( | |||
| DC.T.transformWSG84ToCartographic(positions[i - 1]) | |||
| ) | |||
| let el = ellipsoid.cartographicToCartesian( | |||
| DC.T.transformWSG84ToCartographic(positions[i]) | |||
| ) | |||
| h += oel.x * el.y - el.x * oel.y | |||
| } | |||
| result = Math.abs(h).toFixed(2) | |||
| @@ -83,7 +92,12 @@ DC.Polygon = class extends Overlay { | |||
| _prepareHierarchy() { | |||
| let result = new Cesium.PolygonHierarchy() | |||
| result.positions = DC.T.transformWSG84ArrayToCartesianArray(this._positions) | |||
| result.holes = this._holes.map(item => new Cesium.PolygonHierarchy(DC.T.transformWSG84ArrayToCartesianArray(item))) | |||
| result.holes = this._holes.map( | |||
| item => | |||
| new Cesium.PolygonHierarchy( | |||
| DC.T.transformWSG84ArrayToCartesianArray(item) | |||
| ) | |||
| ) | |||
| return result | |||
| } | |||
| @@ -115,12 +129,55 @@ DC.Polygon = class extends Overlay { | |||
| } | |||
| } | |||
| /** | |||
| * | |||
| * @param {*} extrudedHeight | |||
| * @param {*} duration | |||
| */ | |||
| setExtrudedHeight(extrudedHeight, duration) { | |||
| if (this._delegate.polygon) { | |||
| let now = Cesium.JulianDate.now() | |||
| let oriValue = this._delegate.polygon.extrudedHeight | |||
| ? this._delegate.polygon.extrudedHeight.getValue(now) | |||
| : 0 | |||
| let rate = 0 | |||
| let stopTime = now | |||
| if (duration) { | |||
| rate = (extrudedHeight - oriValue) / duration | |||
| stopTime = DC.JulianDate.addSeconds( | |||
| now, | |||
| duration, | |||
| new Cesium.JulianDate() | |||
| ) | |||
| } | |||
| this._delegate.polygon.extrudedHeight = new Cesium.CallbackProperty( | |||
| time => { | |||
| let result = 0 | |||
| if (DC.JulianDate.greaterThan(stopTime, time)) { | |||
| result = | |||
| oriValue + | |||
| (duration - Cesium.JulianDate.secondsDifference(stopTime, time)) * | |||
| rate | |||
| } else { | |||
| result = extrudedHeight | |||
| } | |||
| return result | |||
| } | |||
| ) | |||
| } | |||
| return this | |||
| } | |||
| /** | |||
| * | |||
| * @param {*} style | |||
| */ | |||
| setStyle(style) { | |||
| if (Object.keys(style).length == 0) { | |||
| if (!style || Object.keys(style).length === 0) { | |||
| return | |||
| } | |||
| this._style = style | |||
| this._delegate.polygon && this._delegate.polygon.merge(this._style) | |||
| this._delegate.polygon && this._delegate.polygon.merge(style) | |||
| return this | |||
| } | |||
| @@ -2,7 +2,7 @@ | |||
| * @Author: Caven | |||
| * @Date: 2020-01-06 15:03:25 | |||
| * @Last Modified by: Caven | |||
| * @Last Modified time: 2020-02-01 11:59:05 | |||
| * @Last Modified time: 2020-02-04 14:14:16 | |||
| */ | |||
| import Overlay from '../Overlay' | |||
| @@ -10,7 +10,10 @@ import Cesium from '@/namespace' | |||
| DC.Polyline = class extends Overlay { | |||
| constructor(positions) { | |||
| if (!positions || (typeof positions !== 'string' && !Array.isArray(positions))) { | |||
| if ( | |||
| !positions || | |||
| (typeof positions !== 'string' && !Array.isArray(positions)) | |||
| ) { | |||
| throw new Error('the positions invalid') | |||
| } | |||
| super() | |||
| @@ -30,19 +33,28 @@ DC.Polyline = class extends Overlay { | |||
| } | |||
| get center() { | |||
| let boundingSphere = Cesium.BoundingSphere.fromPoints(DC.T.transformWSG84ArrayToCartesianArray(this._positions)) | |||
| let boundingSphere = Cesium.BoundingSphere.fromPoints( | |||
| DC.T.transformWSG84ArrayToCartesianArray(this._positions) | |||
| ) | |||
| return DC.T.transformCartesianToWSG84(boundingSphere.center) | |||
| } | |||
| get distance() { | |||
| let result = 0 | |||
| for (var i = 0; i < this._positions.length - 1; i++) { | |||
| let startCartographic = DC.T.transformWSG84ToCartographic(this._positions[i]) | |||
| let endCartographic = DC.T.transformWSG84ToCartographic(this._positions[i + 1]) | |||
| let startCartographic = DC.T.transformWSG84ToCartographic( | |||
| this._positions[i] | |||
| ) | |||
| let endCartographic = DC.T.transformWSG84ToCartographic( | |||
| this._positions[i + 1] | |||
| ) | |||
| let geodesic = new Cesium.EllipsoidGeodesic() | |||
| geodesic.setEndPoints(startCartographic, endCartographic) | |||
| let s = geodesic.surfaceDistance | |||
| s = Math.sqrt(Math.pow(s, 2) + Math.pow(endCartographic.height - startCartographic.height, 2)) | |||
| s = Math.sqrt( | |||
| Math.pow(s, 2) + | |||
| Math.pow(endCartographic.height - startCartographic.height, 2) | |||
| ) | |||
| result = result + s | |||
| } | |||
| return result > 0 ? result.toFixed(2) : result | |||
| @@ -81,6 +93,10 @@ DC.Polyline = class extends Overlay { | |||
| this._delegate.overlayId = this._id | |||
| } | |||
| /** | |||
| * | |||
| * @param {*} style | |||
| */ | |||
| setStyle(style) { | |||
| if (Object.keys(style).length == 0) { | |||
| return | |||
| @@ -2,7 +2,7 @@ | |||
| * @Author: Caven | |||
| * @Date: 2020-01-06 15:03:25 | |||
| * @Last Modified by: Caven | |||
| * @Last Modified time: 2020-02-01 12:05:10 | |||
| * @Last Modified time: 2020-02-02 16:45:32 | |||
| */ | |||
| import Overlay from '../Overlay' | |||
| @@ -68,7 +68,7 @@ DC.Model = class extends Overlay { | |||
| * @param {*} text | |||
| * @param {*} textStyle | |||
| */ | |||
| bindLabel(text, textStyle) { | |||
| setLabel(text, textStyle) { | |||
| this._delegate.label = { | |||
| ...textStyle, | |||
| text: text | |||
| @@ -2,7 +2,7 @@ | |||
| * @Author: Caven | |||
| * @Date: 2020-01-07 08:51:56 | |||
| * @Last Modified by: Caven | |||
| * @Last Modified time: 2020-02-01 12:06:52 | |||
| * @Last Modified time: 2020-02-03 13:41:06 | |||
| */ | |||
| import Cesium from '@/namespace' | |||
| import Overlay from '../Overlay' | |||
| @@ -15,6 +15,15 @@ DC.Tileset = class extends Overlay { | |||
| ...options | |||
| }) | |||
| this._state = DC.OverlayState.INITIALIZED | |||
| this._delegate.tileVisible.addEventListener(this._tileVisibleHandler, this) | |||
| this._propertyMap = undefined | |||
| } | |||
| /** | |||
| * | |||
| */ | |||
| get readyPromise() { | |||
| return this._delegate.readyPromise | |||
| } | |||
| /** | |||
| @@ -24,8 +33,10 @@ DC.Tileset = class extends Overlay { | |||
| */ | |||
| _addCallback(layer) { | |||
| this._layer = layer | |||
| this._layer.delegate.add(this._delegate) | |||
| this._state = DC.OverlayState.ADDED | |||
| this._delegate.readyPromise.then(tileset => { | |||
| this._layer.delegate.add(tileset) | |||
| this._state = DC.OverlayState.ADDED | |||
| }) | |||
| } | |||
| /** | |||
| @@ -33,13 +44,112 @@ DC.Tileset = class extends Overlay { | |||
| */ | |||
| _removeCallback() { | |||
| if (this._layer) { | |||
| this._layer.delegate.remove(this._delegate) | |||
| this._state = DC.OverlayState.REMOVED | |||
| this._delegate.readyPromise.then(tileset => { | |||
| this._layer.delegate.remove(tileset) | |||
| this._state = DC.OverlayState.REMOVED | |||
| }) | |||
| } | |||
| } | |||
| /** | |||
| * | |||
| * @param {*} tile | |||
| */ | |||
| _tileVisibleHandler(tile) { | |||
| if (this._properties && this._properties.length) { | |||
| let content = tile.content | |||
| for (let i = 0; i < content.featuresLength; i++) { | |||
| let feature = content.getFeature(i) | |||
| this._properties.forEach(property => { | |||
| if ( | |||
| feature.hasProperty(property.key) && | |||
| feature.getProperty(property.key) === property.keyValue | |||
| ) { | |||
| feature.setProperty(property.propertyName, property.propertyValue) | |||
| } | |||
| }) | |||
| } | |||
| } | |||
| } | |||
| /** | |||
| * | |||
| * @param {*} position | |||
| */ | |||
| setPosition(position) { | |||
| if (!position || !position instanceof DC.Position) { | |||
| return this | |||
| } | |||
| this._delegate.readyPromise.then(tileset => { | |||
| let modelMatrix = Cesium.Transforms.eastNorthUpToFixedFrame( | |||
| Cesium.Cartesian3.fromDegrees(position.lng, position.lat, position.alt) | |||
| ) | |||
| let rotationX = Cesium.Matrix4.fromRotationTranslation( | |||
| Cesium.Matrix3.fromRotationZ(Cesium.Math.toRadians(position.heading)) | |||
| ) | |||
| Cesium.Matrix4.multiply(modelMatrix, rotationX, modelMatrix) | |||
| tileset.root.transform = modelMatrix | |||
| }) | |||
| return this | |||
| } | |||
| /** | |||
| * | |||
| * @param {*} height | |||
| */ | |||
| setHeight(height) { | |||
| this._delegate.readyPromise.then(tileset => { | |||
| let cartographic = Cesium.Cartographic.fromCartesian( | |||
| tileset.boundingSphere.center | |||
| ) | |||
| let surface = Cesium.Cartesian3.fromRadians( | |||
| cartographic.longitude, | |||
| cartographic.latitude, | |||
| cartographic.height | |||
| ) | |||
| let offset = Cesium.Cartesian3.fromRadians( | |||
| cartographic.longitude, | |||
| cartographic.latitude, | |||
| cartographic.height + height | |||
| ) | |||
| let translation = Cesium.Cartesian3.subtract( | |||
| offset, | |||
| surface, | |||
| new Cesium.Cartesian3() | |||
| ) | |||
| tileset.modelMatrix = Cesium.Matrix4.fromTranslation(translation) | |||
| }) | |||
| return this | |||
| } | |||
| /** | |||
| * | |||
| * @param {*} scale | |||
| */ | |||
| setScale(scale) { | |||
| this._delegate.readyPromise.then(tileset => { | |||
| let modelMatrix = tileset.root.transform | |||
| if (scale > 0 && scale !== 1) { | |||
| Cesium.Matrix4.multiplyByUniformScale(modelMatrix, scale, modelMatrix) | |||
| } | |||
| tileset.root.transform = modelMatrix | |||
| }) | |||
| return this | |||
| } | |||
| /** | |||
| * | |||
| */ | |||
| setFeatureProperty(properties) { | |||
| this._properties = properties | |||
| return this | |||
| } | |||
| /** | |||
| * | |||
| * @param {*} style | |||
| */ | |||
| setStyle(style) { | |||
| if (style && style instanceof Cesium.TilesetStyle) { | |||
| if (style && style instanceof Cesium.Cesium3DTileStyle) { | |||
| this._style = style | |||
| this._delegate && (this._delegate.style = this._style) | |||
| } | |||
| @@ -2,7 +2,7 @@ | |||
| * @Author: Caven | |||
| * @Date: 2019-12-27 14:35:02 | |||
| * @Last Modified by: Caven | |||
| * @Last Modified time: 2020-01-31 15:07:00 | |||
| * @Last Modified time: 2020-02-03 14:37:45 | |||
| */ | |||
| DC.Position = class { | |||
| @@ -64,7 +64,14 @@ DC.Position = class { | |||
| } | |||
| serialize() { | |||
| let position = new DC.Position(this._lng, this._lat, this._alt, this._heading, this._pitch, this._roll) | |||
| let position = new DC.Position( | |||
| this._lng, | |||
| this._lat, | |||
| this._alt, | |||
| this._heading, | |||
| this._pitch, | |||
| this._roll | |||
| ) | |||
| return JSON.stringify(position) | |||
| } | |||
| @@ -2,7 +2,7 @@ | |||
| * @Author: Caven | |||
| * @Date: 2019-12-27 17:13:24 | |||
| * @Last Modified by: Caven | |||
| * @Last Modified time: 2020-02-01 14:54:59 | |||
| * @Last Modified time: 2020-02-02 20:45:25 | |||
| */ | |||
| import Cesium from '@/namespace' | |||
| @@ -43,8 +43,14 @@ DC.Viewer = class { | |||
| this._viewerOption = new ViewerOption(this) // Initialize the viewer option | |||
| this._cameraOption = new CameraOption(this) // Initialize the camera option | |||
| this._viewerEvent = new ViewerEvent() // Register viewer events | |||
| this._dcContainer = DC.DomUtil.create('div', 'dc-container', document.getElementById(id)) //Register the custom container | |||
| this._baseLayerPicker = new Cesium.BaseLayerPickerViewModel({ globe: this._delegate.scene.globe }) | |||
| this._dcContainer = DC.DomUtil.create( | |||
| 'div', | |||
| 'dc-container', | |||
| document.getElementById(id) | |||
| ) //Register the custom container | |||
| this._baseLayerPicker = new Cesium.BaseLayerPickerViewModel({ | |||
| globe: this._delegate.scene.globe | |||
| }) | |||
| this._layerCache = {} | |||
| this.on(DC.ViewerEventType.ADD_LAYER, this._addLayerCallback, this) //Initialize layer add event | |||
| this.on(DC.ViewerEventType.REMOVE_LAYER, this._removeLayerCallback, this) //Initialize layer remove event | |||
| @@ -81,6 +87,10 @@ DC.Viewer = class { | |||
| return this._delegate.scene.canvas | |||
| } | |||
| get clock() { | |||
| return this._delegate.clock | |||
| } | |||
| get viewerEvent() { | |||
| return this._viewerEvent | |||
| } | |||
| @@ -108,7 +118,10 @@ DC.Viewer = class { | |||
| _removeLayerCallback(layer) { | |||
| if (layer && layer.layerEvent && layer.state !== DC.LayerState.REMOVED) { | |||
| layer.layerEvent.fire(DC.LayerEventType.REMOVE, this) | |||
| if (this._layerCache[layer.type] && this._layerCache[layer.type][layer.id]) { | |||
| if ( | |||
| this._layerCache[layer.type] && | |||
| this._layerCache[layer.type][layer.id] | |||
| ) { | |||
| delete this._layerCache[layer.type][layer.id] | |||
| } | |||
| } | |||
| @@ -192,7 +205,9 @@ DC.Viewer = class { | |||
| */ | |||
| changeBaseLayer(index) { | |||
| if (this._baseLayerPicker && index >= 0) { | |||
| this._baseLayerPicker.selectedImagery = this._baseLayerPicker.imageryProviderViewModels[index] | |||
| this._baseLayerPicker.selectedImagery = this._baseLayerPicker.imageryProviderViewModels[ | |||
| index | |||
| ] | |||
| } | |||
| return this | |||
| } | |||
| @@ -273,17 +288,30 @@ DC.Viewer = class { | |||
| removeEffect(effect) {} | |||
| /** | |||
| * | |||
| * @param {*} target | |||
| */ | |||
| flyTo(target) { | |||
| this._delegate.flyTo(target.delegate || target) | |||
| return this | |||
| } | |||
| /** | |||
| * | |||
| * @param {*} target | |||
| */ | |||
| zoomTo(target) { | |||
| this._delegate.zoomTo(target.delegate || target) | |||
| return this | |||
| } | |||
| flyToPosition(position, completeCallback) { | |||
| /** | |||
| * | |||
| * @param {*} position | |||
| * @param {*} completeCallback | |||
| */ | |||
| flyToPosition(position, completeCallback, duration) { | |||
| if (position instanceof DC.Position) { | |||
| this._delegate.camera.flyTo({ | |||
| destination: DC.T.transformWSG84ToCartesian(position), | |||
| @@ -292,22 +320,39 @@ DC.Viewer = class { | |||
| pitch: Cesium.Math.toRadians(position.pitch), | |||
| roll: Cesium.Math.toRadians(position.roll) | |||
| }, | |||
| complete: completeCallback | |||
| complete: completeCallback, | |||
| duration: duration | |||
| }) | |||
| } | |||
| return this | |||
| } | |||
| /** | |||
| * | |||
| * @param {*} type | |||
| * @param {*} callback | |||
| * @param {*} context | |||
| */ | |||
| on(type, callback, context) { | |||
| this._viewerEvent.on(type, callback, context || this) | |||
| return this | |||
| } | |||
| /** | |||
| * | |||
| * @param {*} type | |||
| * @param {*} callback | |||
| * @param {*} context | |||
| */ | |||
| off(type, callback, context) { | |||
| this._viewerEvent.off(type, callback, context || this) | |||
| return this | |||
| } | |||
| /** | |||
| * | |||
| * @param {*} plugin | |||
| */ | |||
| use(plugin) { | |||
| if (plugin && plugin.install) { | |||
| plugin.install(this) | |||
| @@ -2,7 +2,7 @@ | |||
| * @Author: Caven | |||
| * @Date: 2019-12-31 17:32:01 | |||
| * @Last Modified by: Caven | |||
| * @Last Modified time: 2020-02-01 16:00:40 | |||
| * @Last Modified time: 2020-02-01 18:57:30 | |||
| */ | |||
| import Cesium from '@/namespace' | |||
| import Widget from './Widget' | |||
| @@ -33,7 +33,7 @@ class ContextMenu extends Widget { | |||
| } | |||
| } | |||
| _rightclickHandler(e) { | |||
| if (e && e.position && this._enable) { | |||
| if (e && e.position && this._enable && this._updateWindowCoord) { | |||
| this._updateWindowCoord(Cesium.SceneTransforms.wgs84ToWindowCoordinates(this._viewer.delegate.scene, e.position)) | |||
| } | |||
| } | |||
| @@ -46,7 +46,7 @@ class ContextMenu extends Widget { | |||
| this._wapper.style.cssText = ` | |||
| visibility:visible; | |||
| z-index:1; | |||
| transform:translate3d(${windowCoord.x}px,${windowCoord.y}px, 0); | |||
| transform:translate3d(${Math.round(windowCoord.x)}px,${Math.round(windowCoord.y)}px, 0); | |||
| ` | |||
| } | |||
| @@ -2,7 +2,7 @@ | |||
| * @Author: Caven | |||
| * @Date: 2020-01-15 19:16:45 | |||
| * @Last Modified by: Caven | |||
| * @Last Modified time: 2020-02-01 15:04:08 | |||
| * @Last Modified time: 2020-02-01 19:02:13 | |||
| */ | |||
| import Widget from './Widget' | |||
| @@ -11,13 +11,42 @@ class Popup extends Widget { | |||
| constructor() { | |||
| super() | |||
| this._wapper = DC.DomUtil.create('div', 'dc-popup') | |||
| this._contentEl = DC.DomUtil.create('div', 'popup-content', this._wapper) | |||
| this._config = undefined | |||
| } | |||
| _setWindowCoord(windowCoord) { | |||
| let x = windowCoord.x + 10 | |||
| let y = windowCoord.y - this._wapper.offsetHeight / 2 | |||
| this._wapper.style.zIndex = 1 | |||
| this._wapper.style.transform = `translate3d(${x}px,${y}px, 0)` | |||
| _installHook() { | |||
| this.enable = true | |||
| } | |||
| _updateWindowCoord(windowCoord) { | |||
| let x = windowCoord.x - this._wapper.offsetWidth / 2 | |||
| let y = windowCoord.y - this._wapper.offsetHeight | |||
| if (this._config && this._config.position === 'left') { | |||
| x = windowCoord.x - this._wapper.offsetWidth | |||
| } else if (this._config && this._config.position === 'right') { | |||
| x = windowCoord.x | |||
| } | |||
| if (this._config && this._config.arrow) { | |||
| } | |||
| this._wapper.style.cssText = ` | |||
| visibility:visible; | |||
| z-index:1; | |||
| transform:translate3d(${Math.round(x)}px,${Math.round(y)}px, 0); | |||
| ` | |||
| } | |||
| _setCustomClass() {} | |||
| _setCustomBg() {} | |||
| _setArrowStyle() {} | |||
| set config(config) { | |||
| this._config = config | |||
| config.customClass && this._setCustomClass() | |||
| config.customBg && this._setCustomBg() | |||
| config.arrow && this._setArrowStyle() | |||
| } | |||
| } | |||
| @@ -2,7 +2,7 @@ | |||
| * @Author: Caven | |||
| * @Date: 2020-02-01 12:07:54 | |||
| * @Last Modified by: Caven | |||
| * @Last Modified time: 2020-02-01 15:01:25 | |||
| * @Last Modified time: 2020-02-01 18:58:59 | |||
| */ | |||
| import Widget from './Widget' | |||
| @@ -17,10 +17,10 @@ class Tooltip extends Widget { | |||
| _updateWindowCoord(windowCoord) { | |||
| let x = windowCoord.x + 10 | |||
| let y = windowCoord.y - this._wapper.offsetHeight / 2 | |||
| this._wapper.cssText = ` | |||
| this._wapper.style.cssText = ` | |||
| visibility:visible; | |||
| z-index:1; | |||
| transform:translate3d(${x}px,${y}px, 0); | |||
| transform:translate3d(${Math.round(x)}px,${Math.round(y)}px, 0); | |||
| ` | |||
| } | |||
| } | |||
| @@ -2,7 +2,7 @@ | |||
| * @Author: Caven | |||
| * @Date: 2020-01-15 19:17:52 | |||
| * @Last Modified by: Caven | |||
| * @Last Modified time: 2020-02-01 15:06:09 | |||
| * @Last Modified time: 2020-02-01 18:53:59 | |||
| */ | |||
| import Cesium from '@/namespace' | |||
| @@ -47,7 +47,7 @@ class Widget { | |||
| let self = this | |||
| let scene = this._viewer.scene | |||
| scene.postRender.addEventListener(() => { | |||
| if (self._position && self._enable) { | |||
| if (self._position && self._enable && self._updateWindowCoord) { | |||
| let windowCoord = Cesium.SceneTransforms.wgs84ToWindowCoordinates(scene, self._position) | |||
| self._updateWindowCoord(windowCoord) | |||
| } | |||
| @@ -65,6 +65,7 @@ class Widget { | |||
| */ | |||
| setPosition(position) { | |||
| this._position = position | |||
| return this | |||
| } | |||
| /** | |||
| @@ -77,6 +78,7 @@ class Widget { | |||
| } else if (content && content instanceof Element) { | |||
| this._wapper.appendChild(content) | |||
| } | |||
| return this | |||
| } | |||
| /** | |||
| @@ -4,7 +4,6 @@ | |||
| top: 0; | |||
| min-width: 120px; | |||
| min-height: 10px; | |||
| color: #fff; | |||
| padding: 10px 10px; | |||
| background: rgba(255, 255, 255, 1); | |||
| border-radius: 4px; | |||
| @@ -2,9 +2,10 @@ | |||
| * @Author: Caven | |||
| * @Date: 2020-01-21 10:48:50 | |||
| * @Last Modified by: Caven | |||
| * @Last Modified time: 2020-02-01 14:13:18 | |||
| * @Last Modified time: 2020-02-01 18:47:02 | |||
| */ | |||
| import 'cesium/Widgets/widgets.css' | |||
| import './index.scss' | |||
| import './popup.scss' | |||
| import './tooltip.scss' | |||
| import './contextmenu.scss' | |||
| @@ -0,0 +1,13 @@ | |||
| .dc-popup { | |||
| position: absolute; | |||
| left: 0; | |||
| top: 0; | |||
| min-width: 120px; | |||
| min-height: 10px; | |||
| padding: 10px 10px; | |||
| background: rgba(255, 255, 255, 1); | |||
| border-radius: 4px; | |||
| visibility: hidden; | |||
| z-index: -1; | |||
| cursor: pointer; | |||
| } | |||
| @@ -2,16 +2,19 @@ | |||
| * @Author: Caven | |||
| * @Date: 2019-12-30 09:35:51 | |||
| * @Last Modified by: Caven | |||
| * @Last Modified time: 2020-01-31 15:10:07 | |||
| * @Last Modified time: 2020-02-04 14:21:26 | |||
| */ | |||
| import Cesium from '../namespace' | |||
| import Cesium from '@/namespace' | |||
| DC.Color = Cesium.Color | |||
| DC.Cartesian2 = Cesium.Cartesian2 | |||
| DC.Cartesian3 = Cesium.Cartesian3 | |||
| DC.Cartesian4 = Cesium.Cartesian4 | |||
| DC.TilesetStyle = Cesium.Cesium3DTileStyle | |||
| DC.SceneMode = Cesium.SceneMode | |||
| DC.CallbackProperty = Cesium.CallbackProperty | |||
| DC.JulianDate = Cesium.JulianDate | |||
| DC.Math = Cesium.Math | |||