| /* | |||||
| * @Author: Caven | |||||
| * @Date: 2019-12-27 17:18:52 | |||||
| * @Last Modified by: Caven | |||||
| * @Last Modified time: 2020-01-30 21:07:02 | |||||
| */ | |||||
| import './const' | |||||
| import './utils' | |||||
| import './postion/DC.Position' | |||||
| import './transform/DC.T' | |||||
| import './imagery' | |||||
| import './layer' | |||||
| import './overlay' | |||||
| import './viewer/DC.Viewer' | 
| /* | |||||
| * @Author: Caven | |||||
| * @Date: 2019-12-27 14:29:05 | |||||
| * @Last Modified by: Caven | |||||
| * @Last Modified time: 2020-01-30 21:17:32 | |||||
| */ | |||||
| ;(function() { | |||||
| let namespace = {} | |||||
| let initialized = false | |||||
| let DC = { | |||||
| Http: undefined, | |||||
| Version: '1.0.0', | |||||
| Config: {} | |||||
| } | |||||
| window.DC = DC | |||||
| function requireCesium() { | |||||
| return new Promise((resolve, reject) => { | |||||
| let Cesium = require('cesium/Cesium') | |||||
| namespace['Cesium'] = Cesium | |||||
| resolve() | |||||
| }) | |||||
| } | |||||
| /** | |||||
| * 获取 namespace | |||||
| */ | |||||
| DC.getNamespace = function() { | |||||
| return namespace | |||||
| } | |||||
| /** | |||||
| * 开始 | |||||
| */ | |||||
| DC.init = function(callback) { | |||||
| DC.ready(callback) | |||||
| } | |||||
| /** | |||||
| * 开始 | |||||
| */ | |||||
| DC.ready = function(callback) { | |||||
| try { | |||||
| if (!initialized) { | |||||
| requireCesium().then(() => { | |||||
| require('./DC.Loader') | |||||
| delete window.Cesium //删除winow下的Cesium | |||||
| }) | |||||
| } | |||||
| callback && callback() | |||||
| initialized = true | |||||
| } catch (e) { | |||||
| delete window.Cesium | |||||
| initialized = false | |||||
| } | |||||
| } | |||||
| })() | 
| /* | |||||
| * @Author: Caven | |||||
| * @Date: 2020-01-03 10:09:19 | |||||
| * @Last Modified by: Caven | |||||
| * @Last Modified time: 2020-01-31 14:53:54 | |||||
| */ | |||||
| import Cesium from '@/namespace' | |||||
| DC.MouseEventType = { | |||||
| CLICK: Cesium.ScreenSpaceEventType.LEFT_CLICK, | |||||
| RIGHT_CLICK: Cesium.ScreenSpaceEventType.RIGHT_CLICK, | |||||
| DB_CLICK: Cesium.ScreenSpaceEventType.LEFT_DOUBLE_CLICK, | |||||
| MOUSE_MOVE: Cesium.ScreenSpaceEventType.MOUSE_MOVE, | |||||
| WHEEL: Cesium.ScreenSpaceEventType.WHEEL, | |||||
| MOUSE_OVER: 'mouseover', | |||||
| MOUSE_OUT: 'mouseout' | |||||
| } | |||||
| DC.ViewerEventType = { | |||||
| ADD_LAYER: 'addLayer', | |||||
| REMOVE_LAYER: 'removeLayer', | |||||
| ADD_EFFECT: 'addEffect', | |||||
| REMOVE_EFFECT: 'removeEffect' | |||||
| } | |||||
| DC.LayerType = { | |||||
| VECTOR: 'vector', | |||||
| TILESET: 'tileset', | |||||
| KML: 'kml', | |||||
| CZML: 'czml', | |||||
| GEOJSON: 'geojson' | |||||
| } | |||||
| DC.LayerEventType = { | |||||
| ADD: 'add', | |||||
| CLEAR: 'clear', | |||||
| REMOVE: 'remove', | |||||
| ADD_OVERLAY: 'addOverlay', | |||||
| REMOVE_OVERLAY: 'removeOverlay' | |||||
| } | |||||
| DC.LayerState = { | |||||
| INITIALIZED: 'initialized', | |||||
| ADDED: 'added', | |||||
| REMOVED: 'removed', | |||||
| CLEARED: 'cleared' | |||||
| } | |||||
| DC.OverlayType = { | |||||
| POINT: 'point', | |||||
| POLYLINE: 'polyline', | |||||
| POLYGON: 'polygon', | |||||
| MODEL: 'model', | |||||
| BILLBOARD: 'billboard' | |||||
| } | |||||
| DC.OverlayEventType = { | |||||
| ADD: 'add', | |||||
| REMOVE: 'remove' | |||||
| } | |||||
| DC.OverlayState = { | |||||
| INITIALIZED: 'initialized', | |||||
| ADDED: 'added', | |||||
| REMOVED: 'removed' | |||||
| } | |||||
| DC.EffectType = { | |||||
| RAIN: 'rain', | |||||
| SNOW: 'snow' | |||||
| } | |||||
| DC.EffectEventType = { | |||||
| ADD: 'add', | |||||
| REMOVE: 'remove' | |||||
| } | |||||
| DC.EffectState = { | |||||
| INITIALIZED: 'initialized', | |||||
| ADDED: 'added', | |||||
| REMOVED: 'removed' | |||||
| } | |||||
| DC.WidgetType = { | |||||
| Popup: 'Popup', | |||||
| ContextMenu: 'ContextMenu' | |||||
| } | |||||
| DC.WidgetState = { | |||||
| INITIALIZED: 'initialized', | |||||
| INSTALLED: 'installed', | |||||
| UNINSTALLED: 'uninstalled', | |||||
| SHOW: 'show', | |||||
| HIDDEN: 'hidden' | |||||
| } | 
| /* | |||||
| * @Author: Caven | |||||
| * @Date: 2020-01-02 14:26:35 | |||||
| * @Last Modified by: Caven | |||||
| * @Last Modified time: 2020-01-21 12:14:17 | |||||
| */ | |||||
| import Cesium from '@/namespace' | |||||
| import Event from './Event' | |||||
| class EffectEvent extends Event { | |||||
| constructor() { | |||||
| super() | |||||
| this._registerEvent() | |||||
| } | |||||
| _registerEvent() { | |||||
| for (let key in DC.EffectEventType) { | |||||
| let type = DC.EffectEventType[key] | |||||
| this._eventCache[type] = new Cesium.Event() | |||||
| } | |||||
| } | |||||
| } | |||||
| export default EffectEvent | 
| /* | |||||
| * @Author: Caven | |||||
| * @Date: 2020-01-02 15:24:38 | |||||
| * @Last Modified by: Caven | |||||
| * @Last Modified time: 2020-01-21 12:14:17 | |||||
| */ | |||||
| class Event { | |||||
| constructor() { | |||||
| this._eventCache = {} | |||||
| } | |||||
| /** | |||||
| * | |||||
| */ | |||||
| _registerEvent() {} | |||||
| /** | |||||
| * | |||||
| * @param {*} type | |||||
| * @param {*} callback | |||||
| * @param {*} context | |||||
| */ | |||||
| _on(type, callback, context) { | |||||
| let event = this.getEvent(type) | |||||
| if (callback && event) { | |||||
| event.addEventListener(callback, context || this) | |||||
| } | |||||
| } | |||||
| /** | |||||
| * | |||||
| * @param {*} type | |||||
| * @param {*} callback | |||||
| * @param {*} context | |||||
| */ | |||||
| _off(type, callback, context) { | |||||
| let event = this.getEvent(type) | |||||
| if (callback && event) { | |||||
| event.removeEventListener(callback, context || this) | |||||
| } | |||||
| } | |||||
| /** | |||||
| * | |||||
| * @param {*} type | |||||
| * @param {*} params | |||||
| */ | |||||
| _fire(type, params) { | |||||
| let event = this.getEvent(type) | |||||
| if (event) { | |||||
| event.raiseEvent(params) | |||||
| } | |||||
| } | |||||
| /** | |||||
| * | |||||
| * @param {*} type | |||||
| * @param {*} callback | |||||
| * @param {*} context | |||||
| */ | |||||
| on(type, callback, context) { | |||||
| this._on(type, callback, context) | |||||
| return this | |||||
| } | |||||
| /** | |||||
| * | |||||
| * @param {*} type | |||||
| * @param {*} callback | |||||
| * @param {*} context | |||||
| */ | |||||
| off(type, callback, context) { | |||||
| this._off(type, callback, context) | |||||
| return this | |||||
| } | |||||
| /** | |||||
| * | |||||
| * @param {*} type | |||||
| * @param {*} params | |||||
| */ | |||||
| fire(type, params) { | |||||
| this._fire(type, params) | |||||
| return this | |||||
| } | |||||
| /** | |||||
| * | |||||
| * @param {} type | |||||
| */ | |||||
| getEvent(type) { | |||||
| return this._eventCache[type] || undefined | |||||
| } | |||||
| } | |||||
| export default Event | 
| /* | |||||
| * @Author: Caven | |||||
| * @Date: 2020-01-02 14:26:35 | |||||
| * @Last Modified by: Caven | |||||
| * @Last Modified time: 2020-01-21 12:14:20 | |||||
| */ | |||||
| import Cesium from '@/namespace' | |||||
| import Event from './Event' | |||||
| class LayerEvent extends Event { | |||||
| constructor() { | |||||
| super() | |||||
| this._registerEvent() | |||||
| } | |||||
| _registerEvent() { | |||||
| for (let key in DC.LayerEventType) { | |||||
| let type = DC.LayerEventType[key] | |||||
| this._eventCache[type] = new Cesium.Event() | |||||
| } | |||||
| } | |||||
| } | |||||
| export default LayerEvent | 
| /* | |||||
| * @Author: Caven | |||||
| * @Date: 2019-12-31 16:58:31 | |||||
| * @Last Modified by: Caven | |||||
| * @Last Modified time: 2020-01-31 14:50:44 | |||||
| */ | |||||
| import Cesium from '@/namespace' | |||||
| import Event from './Event' | |||||
| class MouseEvent extends Event { | |||||
| constructor(viewer) { | |||||
| super() | |||||
| this._viewer = viewer | |||||
| 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) | |||||
| } | |||||
| /** | |||||
| * Register Cesium mouse events | |||||
| */ | |||||
| _registerEvent() { | |||||
| for (let key in Cesium.ScreenSpaceEventType) { | |||||
| let type = Cesium.ScreenSpaceEventType[key] | |||||
| this._eventCache[type] = new Cesium.Event() | |||||
| this._handler.setInputAction(movement => { | |||||
| this._eventCache[type].raiseEvent(movement) | |||||
| }, type) | |||||
| } | |||||
| } | |||||
| /** | |||||
| * | |||||
| * @param {*} target | |||||
| * gets the target information for the mouse event | |||||
| */ | |||||
| _getTargetInfo(target) { | |||||
| let overlay = undefined | |||||
| let layer = undefined | |||||
| let feature = undefined | |||||
| if (target.id && target.id instanceof Cesium.Entity) { | |||||
| layer = target.id.layer | |||||
| if (layer) { | |||||
| overlay = layer.getOverlay(target.id.id) | |||||
| } | |||||
| //todo | |||||
| } else if (target.id instanceof Cesium.Cesium3DTileFeature) { | |||||
| // todo | |||||
| } | |||||
| return { layer: layer, overlay: overlay, feature: feature } | |||||
| } | |||||
| /** | |||||
| * @param {*} type | |||||
| * @param {*} target | |||||
| */ | |||||
| _raiseEvent(type, target, position = null) { | |||||
| let stopPropagation = false | |||||
| if (target) { | |||||
| let targetInfo = this._getTargetInfo(target) | |||||
| let overlay = targetInfo.overlay | |||||
| if (overlay && overlay.overlayEvent) { | |||||
| let event = overlay.overlayEvent.getEvent(type) | |||||
| if (event && event.numberOfListeners > 0) { | |||||
| event.raiseEvent({ | |||||
| layer: targetInfo.layer, | |||||
| overlay: overlay, | |||||
| feature: targetInfo.feature, | |||||
| position: position | |||||
| }) | |||||
| stopPropagation = true | |||||
| } | |||||
| } | |||||
| } | |||||
| if (!stopPropagation) { | |||||
| let event = this._viewer.viewerEvent.getEvent(type) | |||||
| if (event && event.numberOfListeners > 0) { | |||||
| event.raiseEvent({ position: position, overlay: undefined }) | |||||
| } | |||||
| } | |||||
| } | |||||
| /** | |||||
| * | |||||
| * @param {*} movement | |||||
| * default click event callback | |||||
| */ | |||||
| _clickCallback(movement) { | |||||
| if (!movement || !movement.position) { | |||||
| return | |||||
| } | |||||
| let target = this._viewer.scene.pick(movement.position) | |||||
| let cartesian = this._viewer.scene.pickPosition(movement.position) | |||||
| this._raiseEvent(Cesium.ScreenSpaceEventType.LEFT_CLICK, target, cartesian) | |||||
| } | |||||
| /** | |||||
| * | |||||
| * @param {*} movement | |||||
| * default dbclick event callback | |||||
| */ | |||||
| _dbclickCallback(movement) { | |||||
| if (!movement || !movement.position) { | |||||
| return | |||||
| } | |||||
| 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) | |||||
| } | |||||
| /** | |||||
| * @param {*} movement | |||||
| * default rightclick event callback | |||||
| */ | |||||
| _rightClickCallback(movement) { | |||||
| if (!movement || !movement.position) { | |||||
| return | |||||
| } | |||||
| let target = this._viewer.scene.pick(movement.position) | |||||
| let cartesian = this._viewer.scene.pickPosition(movement.position) | |||||
| this._raiseEvent(Cesium.ScreenSpaceEventType.RIGHT_CLICK, target, cartesian) | |||||
| } | |||||
| /** | |||||
| * | |||||
| * @param {*} movement | |||||
| * default mousemove event callback | |||||
| */ | |||||
| _mouseMoveCallback(movement) { | |||||
| if (!movement || !movement.endPosition) { | |||||
| return | |||||
| } | |||||
| let target = this._viewer.scene.pick(movement.endPosition) | |||||
| if (target) { | |||||
| this._viewer.canvas.style.cursor = 'pointer' | |||||
| } | |||||
| let cartesian = this._viewer.scene.pickPosition(movement.endPosition) | |||||
| this._raiseEvent(Cesium.ScreenSpaceEventType.MOUSE_MOVE, target, cartesian) | |||||
| } | |||||
| } | |||||
| export default MouseEvent | 
| /* | |||||
| * @Author: Caven | |||||
| * @Date: 2020-01-02 14:26:35 | |||||
| * @Last Modified by: Caven | |||||
| * @Last Modified time: 2020-01-21 12:14:22 | |||||
| */ | |||||
| import Cesium from '@/namespace' | |||||
| import Event from './Event' | |||||
| class OverlayEvent extends Event { | |||||
| constructor() { | |||||
| super() | |||||
| this._registerEvent() | |||||
| } | |||||
| _registerEvent() { | |||||
| // mouse event | |||||
| for (let key in DC.MouseEventType) { | |||||
| let type = DC.MouseEventType[key] | |||||
| this._eventCache[type] = new Cesium.Event() | |||||
| } | |||||
| // | |||||
| for (let key in DC.OverlayEventType) { | |||||
| let type = DC.OverlayEventType[key] | |||||
| this._eventCache[type] = new Cesium.Event() | |||||
| } | |||||
| } | |||||
| } | |||||
| export default OverlayEvent | 
| /* | |||||
| * @Author: Caven | |||||
| * @Date: 2020-01-02 14:26:35 | |||||
| * @Last Modified by: Caven | |||||
| * @Last Modified time: 2020-01-31 14:22:52 | |||||
| */ | |||||
| import Cesium from '@/namespace' | |||||
| import Event from './Event' | |||||
| class ViewerEvent extends Event { | |||||
| constructor() { | |||||
| super() | |||||
| this._registerEvent() | |||||
| } | |||||
| _registerEvent() { | |||||
| // mouse event | |||||
| for (let key in DC.MouseEventType) { | |||||
| let type = DC.MouseEventType[key] | |||||
| this._eventCache[type] = new Cesium.Event() | |||||
| } | |||||
| // | |||||
| for (let key in DC.ViewerEventType) { | |||||
| let type = DC.ViewerEventType[key] | |||||
| this._eventCache[type] = new Cesium.Event() | |||||
| } | |||||
| } | |||||
| } | |||||
| export default ViewerEvent | 
| /* | |||||
| * @Author: Caven | |||||
| * @Date: 2020-01-13 10:13:53 | |||||
| * @Last Modified by: Caven | |||||
| * @Last Modified time: 2020-01-22 11:13:23 | |||||
| */ | |||||
| import Cesium from '@/namespace' | |||||
| import Layer from './Layer' | |||||
| DC.GeoJsonLayer = class extends Layer { | |||||
| constructor(id, url) { | |||||
| super(id) | |||||
| this._delegate = new Cesium.GeoJsonDataSource(id).load(url) | |||||
| this._state = DC.LayerState.INITIALIZED | |||||
| this.type = DC.LayerType.GEOJSON | |||||
| } | |||||
| _addCallback(viewer) { | |||||
| this._viewer = viewer | |||||
| this._viewer.delegate.dataSources.add(this._delegate) | |||||
| this._state = DC.LayerState.ADDED | |||||
| } | |||||
| _removeCallback() { | |||||
| if (this._viewer) { | |||||
| this._cache = {} | |||||
| this._delegate.removeAll() | |||||
| this._viewer.delegate.dataSources.remove(this._delegate) | |||||
| this._state = DC.LayerState.REMOVED | |||||
| } | |||||
| } | |||||
| _createBillboard(entity) { | |||||
| if (entity.position && entity.billboard) { | |||||
| return DC.Billboard.fromEntity(entity) | |||||
| } | |||||
| } | |||||
| _createPolyline(entity) { | |||||
| if (entity.polyline) { | |||||
| return DC.Polyline.fromEntity(entity) | |||||
| } | |||||
| } | |||||
| _createPolygon(entity) { | |||||
| if (entity.polygon) { | |||||
| return DC.Polygon.fromEntity(entity) | |||||
| } | |||||
| } | |||||
| eachOverlay(method, context) { | |||||
| if (this._delegate) { | |||||
| this._delegate.then(dataSource => { | |||||
| let entities = dataSource.entities.values | |||||
| entities.forEach(item => { | |||||
| method.call(context, item) | |||||
| }) | |||||
| }) | |||||
| return this | |||||
| } | |||||
| } | |||||
| clear() { | |||||
| this._cache = {} | |||||
| this._delegate.removeAll() | |||||
| this._state = DC.LayerState.CLEARED | |||||
| return this | |||||
| } | |||||
| toVectorLayer() { | |||||
| let layer = new DC.VectorLayer(this._id) | |||||
| let self = this | |||||
| this.eachOverlay(item => { | |||||
| if (item.billboard) { | |||||
| layer.addOverlay(self._createBillboard(item)) | |||||
| } else if (item.polyline) { | |||||
| layer.addOverlay(self._createPolyline(item)) | |||||
| } else if (item.polygon) { | |||||
| layer.addOverlay(self._createPolygon(item)) | |||||
| } | |||||
| }) | |||||
| return layer | |||||
| } | |||||
| } | 
| /* | |||||
| * @Author: Caven | |||||
| * @Date: 2020-01-09 09:16:27 | |||||
| * @Last Modified by: Caven | |||||
| * @Last Modified time: 2020-01-22 11:06:49 | |||||
| */ | |||||
| import Cesium from '@/namespace' | |||||
| import Layer from './Layer' | |||||
| /** | |||||
| * TilesetLayer is used to add various tileset | |||||
| */ | |||||
| DC.TilesetLayer = class extends Layer { | |||||
| constructor(id) { | |||||
| super(id) | |||||
| this._delegate = new Cesium.PrimitiveCollection() | |||||
| this._state = DC.LayerState.INITIALIZED | |||||
| this.type = DC.LayerType.TILESET | |||||
| } | |||||
| _addCallback(viewer) { | |||||
| this._viewer = viewer | |||||
| this._viewer.delegate.scene.primitives.add(this._delegate) | |||||
| this._state = DC.LayerState.ADDED | |||||
| } | |||||
| _removeCallback() { | |||||
| if (this._viewer) { | |||||
| this._cache = {} | |||||
| this._delegate.removeAll() | |||||
| this._viewer.delegate.scene.primitives.remove(this._delegate) | |||||
| this._state = DC.LayerState.REMOVED | |||||
| } | |||||
| } | |||||
| clear() { | |||||
| this._cache = {} | |||||
| this._delegate.removeAll() | |||||
| this._state = DC.LayerState.CLEARED | |||||
| return this | |||||
| } | |||||
| } | 
| /* | |||||
| * @Author: Caven | |||||
| * @Date: 2020-01-02 16:42:03 | |||||
| * @Last Modified by: Caven | |||||
| * @Last Modified time: 2020-01-22 11:05:26 | |||||
| */ | |||||
| import Cesium from '@/namespace' | |||||
| import Layer from './Layer' | |||||
| /** | |||||
| * The vector layer is used to add various enitity, which is essentially a CustomDataSource | |||||
| * that is used to place entities of the same class or business attribute into the same layer | |||||
| */ | |||||
| DC.VectorLayer = class extends Layer { | |||||
| constructor(id) { | |||||
| super(id) | |||||
| this._delegate = new Cesium.CustomDataSource(id) | |||||
| this._state = DC.LayerState.INITIALIZED | |||||
| this.type = DC.LayerType.VECTOR | |||||
| } | |||||
| _addCallback(viewer) { | |||||
| this._viewer = viewer | |||||
| this._viewer.delegate.dataSources.add(this._delegate) | |||||
| this._state = DC.LayerState.ADDED | |||||
| } | |||||
| _removeCallback() { | |||||
| if (this._viewer) { | |||||
| this._cache = {} | |||||
| this._delegate.removeAll() | |||||
| this._viewer.delegate.dataSources.remove(this._delegate) | |||||
| this._state = DC.LayerState.REMOVED | |||||
| } | |||||
| } | |||||
| clear() { | |||||
| this._cache = {} | |||||
| this._delegate.removeAll() | |||||
| this._state = DC.LayerState.CLEARED | |||||
| return this | |||||
| } | |||||
| } | 
| /* | |||||
| * @Author: Caven | |||||
| * @Date: 2020-01-03 09:38:21 | |||||
| * @Last Modified by: Caven | |||||
| * @Last Modified time: 2020-01-22 11:01:33 | |||||
| */ | |||||
| import LayerEvent from '../event/LayerEvent' | |||||
| class Layer { | |||||
| constructor(id) { | |||||
| this._id = id || DC.Util.uuid() | |||||
| this._delegate = undefined | |||||
| this._viewer = undefined | |||||
| this._state = undefined | |||||
| this._show = true | |||||
| this._cache = {} | |||||
| this._attr = {} | |||||
| this._layerEvent = new LayerEvent() | |||||
| this._layerEvent.on(DC.LayerEventType.ADD, this._addCallback, this) | |||||
| this._layerEvent.on(DC.LayerEventType.REMOVE, this._removeCallback, this) | |||||
| this._layerEvent.on(DC.LayerEventType.ADD_OVERLAY, this._addOverlayCallback, this) | |||||
| this._layerEvent.on(DC.LayerEventType.REMOVE_OVERLAY, this._removeOverlayCallback, this) | |||||
| this.type = undefined | |||||
| } | |||||
| set show(show) { | |||||
| this._show = show | |||||
| this._delegate && (this._delegate.show = this._show) | |||||
| } | |||||
| get show() { | |||||
| return this._show | |||||
| } | |||||
| get layerEvent() { | |||||
| return this._layerEvent | |||||
| } | |||||
| set attr(attr) { | |||||
| this._attr = attr | |||||
| } | |||||
| get attr() { | |||||
| return this._attr | |||||
| } | |||||
| get id() { | |||||
| return this._id | |||||
| } | |||||
| get delegate() { | |||||
| return this._delegate | |||||
| } | |||||
| get state() { | |||||
| return this._state | |||||
| } | |||||
| /** | |||||
| * | |||||
| * @param {*} veiwer | |||||
| * the layer added callback function | |||||
| * subclasses need to be overridden | |||||
| */ | |||||
| _addCallback(veiwer) {} | |||||
| /** | |||||
| * the layer removed callback function | |||||
| * subclasses need to be overridden | |||||
| */ | |||||
| _removeCallback() {} | |||||
| /** | |||||
| * | |||||
| * @param {*} overlay | |||||
| * the layer add overlay callback function | |||||
| */ | |||||
| _addOverlayCallback(overlay) { | |||||
| if (overlay && overlay.overlayEvent && overlay.state !== DC.OverlayState.ADDED) { | |||||
| overlay.overlayEvent.fire(DC.OverlayEventType.ADD, this) | |||||
| this._cache[overlay.id] = overlay | |||||
| } | |||||
| } | |||||
| /** | |||||
| * | |||||
| * @param {*} overlay | |||||
| * the layer remove overlay callback function | |||||
| */ | |||||
| _removeOverlayCallback(overlay) { | |||||
| if (overlay && overlay.overlayEvent && overlay.state !== DC.OverlayState.REMOVED) { | |||||
| overlay.overlayEvent.fire(DC.OverlayEventType.REMOVE, this) | |||||
| delete this._cache[overlay.id] | |||||
| } | |||||
| } | |||||
| /** | |||||
| * | |||||
| * @param {*} overlay | |||||
| * the layer add overlay | |||||
| */ | |||||
| addOverlay(overlay) { | |||||
| this._addOverlayCallback(overlay) | |||||
| return this | |||||
| } | |||||
| removeOverlay(overlay) { | |||||
| this._removeOverlayCallback(overlay) | |||||
| return this | |||||
| } | |||||
| getOverlayByAttr(atrrName, attrVal) { | |||||
| let overlay = undefined | |||||
| for (let key in this._cache) { | |||||
| if (this._cache[key].attr[atrrName] === attrVal) { | |||||
| overlay = this._cache[key] | |||||
| } | |||||
| } | |||||
| return overlay | |||||
| } | |||||
| eachOverlay(method, context) { | |||||
| for (let key in this._cache) { | |||||
| method.call(context, this._cache[key]) | |||||
| } | |||||
| return this | |||||
| } | |||||
| clear() {} | |||||
| remove() { | |||||
| if (this._viewer) { | |||||
| this._viewer.removeLayer(this) | |||||
| } | |||||
| } | |||||
| addToViewer(viewer) { | |||||
| if (viewer) { | |||||
| viewer.addLayer(this) | |||||
| } | |||||
| return this | |||||
| } | |||||
| } | |||||
| export default Layer | 
| /* | |||||
| * @Author: Caven | |||||
| * @Date: 2020-01-03 11:06:26 | |||||
| * @Last Modified by: Caven | |||||
| * @Last Modified time: 2020-01-21 12:14:30 | |||||
| */ | |||||
| import './DC.VectorLayer' | |||||
| import './DC.TilesetLayer' | |||||
| import './DC.GeoJsonLayer' | 
| /* | |||||
| * @Author: Caven | |||||
| * @Date: 2020-01-03 12:18:17 | |||||
| * @Last Modified by: Caven | |||||
| * @Last Modified time: 2020-01-21 12:15:02 | |||||
| */ | |||||
| import OverlayEvent from '../event/OverlayEvent' | |||||
| class Overlay { | |||||
| constructor() { | |||||
| this._id = DC.Util.uuid() | |||||
| this._layer = undefined | |||||
| this._state = undefined | |||||
| this._delegate = undefined | |||||
| this._show = true | |||||
| this._style = {} | |||||
| 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.type = undefined | |||||
| } | |||||
| get id() { | |||||
| return this._id | |||||
| } | |||||
| set show(show) { | |||||
| this._show = show | |||||
| this._delegate && (this._delegate.show = this._show) | |||||
| } | |||||
| get show() { | |||||
| return this._show | |||||
| } | |||||
| set attr(attr) { | |||||
| this._attr = attr | |||||
| } | |||||
| get attr() { | |||||
| return this._attr | |||||
| } | |||||
| get overlayEvent() { | |||||
| return this._overlayEvent | |||||
| } | |||||
| get delegate() { | |||||
| return this._delegate | |||||
| } | |||||
| get state() { | |||||
| return this._state | |||||
| } | |||||
| /*** | |||||
| * 构建代理,子类需要覆盖重写 | |||||
| */ | |||||
| _prepareDelegate() {} | |||||
| /** | |||||
| * | |||||
| * @param {*} layer | |||||
| * 覆盖物添加调用的回调函数,子类需要覆盖重写 | |||||
| */ | |||||
| _addCallback(layer) {} | |||||
| /** | |||||
| * 覆盖物删除调用的回调函数,子类需要覆盖重写 | |||||
| */ | |||||
| _removeCallback() {} | |||||
| /** | |||||
| * | |||||
| * @param {*} style | |||||
| * 设置覆盖物样式,子类需要覆盖重写 | |||||
| */ | |||||
| setStyle(style) {} | |||||
| /** | |||||
| * 覆盖物删除 | |||||
| */ | |||||
| remove() { | |||||
| if (this._layer) { | |||||
| this._layer.layerEvent.fire(DC.LayerEventType.REMOVE_OVERLAY, this) | |||||
| } | |||||
| } | |||||
| } | |||||
| export default Overlay | 
| /* | |||||
| * @Author: Caven | |||||
| * @Date: 2020-01-19 10:18:23 | |||||
| * @Last Modified by: Caven | |||||
| * @Last Modified time: 2020-01-22 11:16:04 | |||||
| */ | |||||
| import Cesium from '@/namespace' | |||||
| import Overlay from '../Overlay' | |||||
| DC.Billboard = class extends Overlay { | |||||
| constructor(position, icon) { | |||||
| if (!position || !(position instanceof DC.Position)) { | |||||
| throw new Error('the position invalid') | |||||
| } | |||||
| super() | |||||
| this._position = position | |||||
| this._icon = icon | |||||
| this._size = [32, 32] | |||||
| this._delegate = new Cesium.Entity() | |||||
| this._state = DC.OverlayState.INITIALIZED | |||||
| this.type = DC.OverlayType.BILLBOARD | |||||
| } | |||||
| set position(position) { | |||||
| this._position = position | |||||
| } | |||||
| get position() { | |||||
| return this._position | |||||
| } | |||||
| set icon(icon) { | |||||
| this._icon = icon | |||||
| } | |||||
| get icon() { | |||||
| return this._icon | |||||
| } | |||||
| set size(size) { | |||||
| this._size = size | |||||
| } | |||||
| get size() { | |||||
| return this._size | |||||
| } | |||||
| _prepareDelegate() { | |||||
| /** | |||||
| * set the location | |||||
| */ | |||||
| this._delegate.position = new Cesium.CallbackProperty(time => { | |||||
| return DC.T.transformWSG84ToCartesian(this._position) | |||||
| }) | |||||
| /** | |||||
| * set the orientation | |||||
| */ | |||||
| this._delegate.orientation = new Cesium.CallbackProperty(time => { | |||||
| return Cesium.Transforms.headingPitchRollQuaternion( | |||||
| DC.T.transformWSG84ToCartesian(this._position), | |||||
| new Cesium.HeadingPitchRoll( | |||||
| Cesium.Math.toRadians(this._position.heading), | |||||
| Cesium.Math.toRadians(this._position.pitch), | |||||
| Cesium.Math.toRadians(this._position.roll) | |||||
| ) | |||||
| ) | |||||
| }) | |||||
| /** | |||||
| * initialize the Overlay parameter | |||||
| */ | |||||
| this._delegate.billboard = { | |||||
| ...this._style, | |||||
| image: new Cesium.CallbackProperty(time => { | |||||
| return this._icon | |||||
| }), | |||||
| width: new Cesium.CallbackProperty(time => { | |||||
| return this._size[0] || 32 | |||||
| }), | |||||
| height: new Cesium.CallbackProperty(time => { | |||||
| return this._size[1] || 32 | |||||
| }) | |||||
| } | |||||
| this._delegate.layer = this._layer | |||||
| this._delegate.overlayId = this._id | |||||
| } | |||||
| _addCallback(layer) { | |||||
| this._layer = layer | |||||
| this._prepareDelegate() | |||||
| this._layer.delegate.entities.add(this._delegate) | |||||
| this._state = DC.OverlayState.ADDED | |||||
| } | |||||
| _removeCallback() { | |||||
| if (this._layer) { | |||||
| this._layer.delegate.entities.remove(this._delegate) | |||||
| this._state = DC.OverlayState.REMOVED | |||||
| } | |||||
| } | |||||
| setStyle(style) { | |||||
| if (Object.keys(style).length === 0) { | |||||
| return | |||||
| } | |||||
| this._style = style | |||||
| this._delegate.billboard && this._delegate.billboard.merge(this._style) | |||||
| return this | |||||
| } | |||||
| static fromEntity(entity) { | |||||
| let position = DC.T.transformCartesianToWSG84(entity.position._value) | |||||
| let billboard = undefined | |||||
| if (entity.billboard) { | |||||
| billboard = new DC.Billboard(position, entity.billboard.image) | |||||
| billboard.setStyle({ | |||||
| ...entity.billboard | |||||
| }) | |||||
| } | |||||
| return billboard | |||||
| } | |||||
| } | 
| /* | |||||
| * @Author: Caven | |||||
| * @Date: 2020-01-06 15:03:25 | |||||
| * @Last Modified by: Caven | |||||
| * @Last Modified time: 2020-01-22 11:17:19 | |||||
| */ | |||||
| import Cesium from '@/namespace' | |||||
| import Overlay from '../Overlay' | |||||
| const DEF_STYLE = { | |||||
| pixelSize: 8, | |||||
| outlineColor: Cesium.Color.BLUE, | |||||
| outlineWidth: 2 | |||||
| } | |||||
| DC.Point = class extends Overlay { | |||||
| constructor(position) { | |||||
| if (!position || !(position instanceof DC.Position)) { | |||||
| throw new Error('the position invalid') | |||||
| } | |||||
| super() | |||||
| this._position = position | |||||
| this._delegate = new Cesium.Entity() | |||||
| this._state = DC.OverlayState.INITIALIZED | |||||
| this.type = DC.OverlayType.POINT | |||||
| } | |||||
| set position(position) { | |||||
| this._position = position | |||||
| } | |||||
| get position() { | |||||
| return this._position | |||||
| } | |||||
| _prepareDelegate() { | |||||
| /** | |||||
| * set the location | |||||
| */ | |||||
| this._delegate.position = new Cesium.CallbackProperty(time => { | |||||
| return DC.T.transformWSG84ToCartesian(this._position) | |||||
| }) | |||||
| /** | |||||
| * set the orientation | |||||
| */ | |||||
| this._delegate.orientation = new Cesium.CallbackProperty(time => { | |||||
| return Cesium.Transforms.headingPitchRollQuaternion( | |||||
| DC.T.transformWSG84ToCartesian(this._position), | |||||
| new Cesium.HeadingPitchRoll( | |||||
| Cesium.Math.toRadians(this._position.heading), | |||||
| Cesium.Math.toRadians(this._position.pitch), | |||||
| Cesium.Math.toRadians(this._position.roll) | |||||
| ) | |||||
| ) | |||||
| }) | |||||
| /** | |||||
| * initialize the Overlay parameter | |||||
| */ | |||||
| this._delegate.point = { | |||||
| ...DEF_STYLE, | |||||
| ...this._style | |||||
| } | |||||
| this._delegate.layer = this._layer | |||||
| this._delegate.overlayId = this._id | |||||
| } | |||||
| _addCallback(layer) { | |||||
| this._layer = layer | |||||
| this._prepareDelegate() | |||||
| this._layer.delegate.entities.add(this._delegate) | |||||
| this._state = DC.OverlayState.ADDED | |||||
| } | |||||
| _removeCallback() { | |||||
| if (this._layer) { | |||||
| this._layer.delegate.entities.remove(this._delegate) | |||||
| this._state = DC.OverlayState.REMOVED | |||||
| } | |||||
| } | |||||
| setStyle(style) { | |||||
| if (Object.keys(style).length === 0) { | |||||
| return | |||||
| } | |||||
| this._style = style | |||||
| this._delegate.point && DC.Util.merge(this._delegate.point, DEF_STYLE, this._style) | |||||
| return this | |||||
| } | |||||
| } | 
| /* | |||||
| * @Author: Caven | |||||
| * @Date: 2020-01-09 09:10:37 | |||||
| * @Last Modified by: Caven | |||||
| * @Last Modified time: 2020-01-22 11:16:23 | |||||
| */ | |||||
| import Overlay from '../Overlay' | |||||
| import Cesium from '@/namespace' | |||||
| DC.Polygon = class extends Overlay { | |||||
| constructor(positions) { | |||||
| if (!positions || (typeof positions !== 'string' && !Array.isArray(positions))) { | |||||
| throw new Error('the positions invalid') | |||||
| } | |||||
| super() | |||||
| this._positions = [] | |||||
| this._holes = [] | |||||
| this._preparePositions(positions) | |||||
| this._delegate = new Cesium.Entity() | |||||
| this._state = DC.OverlayState.INITIALIZED | |||||
| this.type = DC.OverlayType.POLYGON | |||||
| } | |||||
| set positions(positions) { | |||||
| this._preparePositions(positions) | |||||
| } | |||||
| get positions() { | |||||
| return this._positions | |||||
| } | |||||
| set holes(holes) { | |||||
| if (holes && holes.length) { | |||||
| this._holes = holes.map(item => this._preparePositions(item)) | |||||
| } | |||||
| } | |||||
| get holes() { | |||||
| return this._holes | |||||
| } | |||||
| get center() { | |||||
| let boundingSphere = Cesium.BoundingSphere.fromPoints(DC.T.transformWSG84ArrayToCartesianArray(this._positions)) | |||||
| return DC.T.transformCartesianToWSG84(boundingSphere.center) | |||||
| } | |||||
| get area() { | |||||
| let result = 0 | |||||
| if (this._positions) { | |||||
| let h = 0 | |||||
| let ellipsoid = Cesium.Ellipsoid.WGS84 | |||||
| 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])) | |||||
| h += oel.x * el.y - el.x * oel.y | |||||
| } | |||||
| result = Math.abs(h).toFixed(2) | |||||
| } | |||||
| return result | |||||
| } | |||||
| _preparePositions(positions) { | |||||
| if (typeof positions === 'string') { | |||||
| if (positions.indexOf('#') >= 0) { | |||||
| throw new Error('the positions invalid') | |||||
| } | |||||
| positions = positions.split(';') | |||||
| } | |||||
| this._positions = positions.map(item => { | |||||
| if (Array.isArray(item)) { | |||||
| return DC.Position.fromCoordArray(item) | |||||
| } else { | |||||
| return DC.Position.fromCoordString(item) | |||||
| } | |||||
| }) | |||||
| } | |||||
| _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))) | |||||
| return result | |||||
| } | |||||
| _prepareDelegate() { | |||||
| /** | |||||
| * initialize the Overlay parameter | |||||
| */ | |||||
| this._delegate.polygon = { | |||||
| ...this._style, | |||||
| hierarchy: new Cesium.CallbackProperty(time => { | |||||
| return this._prepareHierarchy() | |||||
| }) | |||||
| } | |||||
| this._delegate.layer = this._layer | |||||
| this._delegate.overlayId = this._id | |||||
| } | |||||
| _addCallback(layer) { | |||||
| this._layer = layer | |||||
| this._prepareDelegate() | |||||
| this._layer.delegate.entities.add(this._delegate) | |||||
| this._state = DC.OverlayState.ADDED | |||||
| } | |||||
| _removeCallback() { | |||||
| if (this._layer) { | |||||
| this._layer.delegate.entities.remove(this._delegate) | |||||
| this._state = DC.OverlayState.REMOVED | |||||
| } | |||||
| } | |||||
| setStyle(style) { | |||||
| if (Object.keys(style).length == 0) { | |||||
| return | |||||
| } | |||||
| this._style = style | |||||
| this._delegate.polygon && this._delegate.polygon.merge(this._style) | |||||
| return this | |||||
| } | |||||
| static fromEntity(entity) {} | |||||
| } | 
| /* | |||||
| * @Author: Caven | |||||
| * @Date: 2020-01-06 15:03:25 | |||||
| * @Last Modified by: Caven | |||||
| * @Last Modified time: 2020-01-22 11:17:30 | |||||
| */ | |||||
| import Overlay from '../Overlay' | |||||
| import Cesium from '@/namespace' | |||||
| DC.Polyline = class extends Overlay { | |||||
| constructor(positions) { | |||||
| if (!positions || (typeof positions !== 'string' && !Array.isArray(positions))) { | |||||
| throw new Error('the positions invalid') | |||||
| } | |||||
| super() | |||||
| this._positions = [] | |||||
| this._preparePositions(positions) | |||||
| this._delegate = new Cesium.Entity() | |||||
| this._state = DC.OverlayState.INITIALIZED | |||||
| this.type = DC.OverlayType.POLYLINE | |||||
| } | |||||
| set positions(positions) { | |||||
| this._preparePositions(positions) | |||||
| } | |||||
| get positions() { | |||||
| return this._positions | |||||
| } | |||||
| get center() { | |||||
| 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 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)) | |||||
| result = result + s | |||||
| } | |||||
| return result > 0 ? result.toFixed(2) : result | |||||
| } | |||||
| _preparePositions(positions) { | |||||
| if (typeof positions === 'string') { | |||||
| if (positions.indexOf('#') >= 0) { | |||||
| throw new Error('the positions invalid') | |||||
| } | |||||
| positions = positions.split(';') | |||||
| } | |||||
| this._positions = positions.map(item => { | |||||
| if (Array.isArray(item)) { | |||||
| return DC.Position.fromCoordArray(item) | |||||
| } else { | |||||
| return DC.Position.fromCoordString(item) | |||||
| } | |||||
| }) | |||||
| } | |||||
| _prepareDelegate() { | |||||
| /** | |||||
| * initialize the Overlay parameter | |||||
| */ | |||||
| this._delegate.polyline = { | |||||
| ...this._style, | |||||
| positions: new Cesium.CallbackProperty(time => { | |||||
| return DC.T.transformWSG84ArrayToCartesianArray(this._positions) | |||||
| }) | |||||
| } | |||||
| this._delegate.layer = this._layer | |||||
| this._delegate.overlayId = this._id | |||||
| } | |||||
| _addCallback(layer) { | |||||
| this._layer = layer | |||||
| this._prepareDelegate() | |||||
| this._layer.delegate.entities.add(this._delegate) | |||||
| this._state = DC.OverlayState.ADDED | |||||
| } | |||||
| _removeCallback() { | |||||
| if (this._layer) { | |||||
| this._layer.delegate.entities.remove(this._delegate) | |||||
| this._state = DC.OverlayState.REMOVED | |||||
| } | |||||
| } | |||||
| setStyle(style) { | |||||
| if (Object.keys(style).length == 0) { | |||||
| return | |||||
| } | |||||
| this._style = style | |||||
| this._delegate.polyline && this._delegate.polyline.merge(this._style) | |||||
| return this | |||||
| } | |||||
| fromEntity(entity) { | |||||
| // this._positions = | |||||
| } | |||||
| } | 
| /* | |||||
| * @Author: Caven | |||||
| * @Date: 2020-01-06 15:04:15 | |||||
| * @Last Modified by: Caven | |||||
| * @Last Modified time: 2020-01-21 12:15:00 | |||||
| */ | |||||
| import './base/DC.Point' | |||||
| import './base/DC.Polyline' | |||||
| import './base/DC.Polygon' | |||||
| import './model/DC.Model' | |||||
| import './model/DC.Tileset' | 
| /* | |||||
| * @Author: Caven | |||||
| * @Date: 2020-01-06 15:03:25 | |||||
| * @Last Modified by: Caven | |||||
| * @Last Modified time: 2020-01-21 12:14:56 | |||||
| */ | |||||
| import Overlay from '../Overlay' | |||||
| import Cesium from '@/namespace' | |||||
| DC.Model = class extends Overlay { | |||||
| constructor(position, modelUrl) { | |||||
| if (!position || !(position instanceof DC.Position)) { | |||||
| throw new Error('the position invalid') | |||||
| } | |||||
| super() | |||||
| this._position = position | |||||
| this._modelUrl = modelUrl | |||||
| this._delegate = new Cesium.Entity() | |||||
| this._state = DC.OverlayState.INITIALIZED | |||||
| } | |||||
| set position(position) { | |||||
| this._position = position | |||||
| } | |||||
| get position() { | |||||
| return this._position | |||||
| } | |||||
| set modelUrl(modelUrl) { | |||||
| this._modelUrl = modelUrl | |||||
| } | |||||
| get modelUrl() { | |||||
| return this._modelUrl | |||||
| } | |||||
| _prepareDelegate() { | |||||
| // 设置位置 | |||||
| this._delegate.position = new Cesium.CallbackProperty(time => { | |||||
| return DC.T.transformWSG84ToCartesian(this._position) | |||||
| }) | |||||
| // 设置朝向 | |||||
| this._delegate.orientation = new Cesium.CallbackProperty(time => { | |||||
| return Cesium.Transforms.headingPitchRollQuaternion( | |||||
| DC.T.transformWSG84ToCartesian(this._position), | |||||
| new Cesium.HeadingPitchRoll( | |||||
| Cesium.Math.toRadians(this._position.heading), | |||||
| Cesium.Math.toRadians(this._position.pitch), | |||||
| Cesium.Math.toRadians(this._position.roll) | |||||
| ) | |||||
| ) | |||||
| }) | |||||
| // 设置模型参数 | |||||
| this._delegate.model = { | |||||
| ...this._style, | |||||
| uri: new Cesium.CallbackProperty(time => { | |||||
| return this._modelUrl | |||||
| }) | |||||
| } | |||||
| this._delegate.layer = this._layer | |||||
| this._delegate.overlayId = this._id | |||||
| } | |||||
| _addCallback(layer) { | |||||
| this._layer = layer | |||||
| this._prepareDelegate() | |||||
| this._layer.delegate.entities.add(this._delegate) | |||||
| this._state = DC.OverlayState.ADDED | |||||
| } | |||||
| _removeCallback() { | |||||
| if (this._layer) { | |||||
| this._layer.delegate.entities.remove(this._delegate) | |||||
| this._state = DC.OverlayState.REMOVED | |||||
| } | |||||
| } | |||||
| setStyle(style) { | |||||
| if (Object.keys(style).length == 0) { | |||||
| return | |||||
| } | |||||
| this._style = style | |||||
| this._delegate.model && this._delegate.model.merge(this._style) | |||||
| } | |||||
| } | 
| /* | |||||
| * @Author: Caven | |||||
| * @Date: 2020-01-07 08:51:56 | |||||
| * @Last Modified by: Caven | |||||
| * @Last Modified time: 2020-01-21 12:14:58 | |||||
| */ | |||||
| import Cesium from '@/namespace' | |||||
| import Overlay from '../Overlay' | |||||
| DC.Tileset = class extends Overlay { | |||||
| constructor(url, options = {}) { | |||||
| super() | |||||
| this._delegate = new Cesium.Cesium3DTileset({ | |||||
| url: url, | |||||
| ...options | |||||
| }) | |||||
| this._state = DC.OverlayState.INITIALIZED | |||||
| } | |||||
| _addCallback(layer) { | |||||
| this._layer = layer | |||||
| this._layer.delegate.add(this._delegate) | |||||
| this._state = DC.OverlayState.ADDED | |||||
| } | |||||
| _removeCallback() { | |||||
| if (this._layer) { | |||||
| this._layer.delegate.remove(this._delegate) | |||||
| this._state = DC.OverlayState.REMOVED | |||||
| } | |||||
| } | |||||
| setStyle(style) { | |||||
| if (style && style instanceof Cesium.TilesetStyle) { | |||||
| this._style = style | |||||
| this._delegate && (this._delegate.style = this._style) | |||||
| } | |||||
| return this | |||||
| } | |||||
| remove() { | |||||
| if (this._layer) { | |||||
| this._layer.layerEvent.fire(DC.LayerEventType.REMOVE_OVERLAY, this) | |||||
| } | |||||
| } | |||||
| } | 
| /* | |||||
| * @Author: Caven | |||||
| * @Date: 2019-12-27 14:35:02 | |||||
| * @Last Modified by: Caven | |||||
| * @Last Modified time: 2020-01-21 12:15:02 | |||||
| */ | |||||
| DC.Position = class { | |||||
| constructor(lng, lat, alt = 0, heading = 0, pitch = 0, roll = 0) { | |||||
| this._lng = lng | |||||
| this._lat = lat | |||||
| this._alt = alt | |||||
| this._heading = heading | |||||
| this._pitch = pitch | |||||
| this._roll = roll | |||||
| } | |||||
| set lng(lng) { | |||||
| this._lng = lng | |||||
| } | |||||
| get lng() { | |||||
| return this._lng | |||||
| } | |||||
| set lat(lat) { | |||||
| this._lat = lat | |||||
| } | |||||
| get lat() { | |||||
| return this._lat | |||||
| } | |||||
| set alt(alt) { | |||||
| this._alt = alt | |||||
| } | |||||
| get alt() { | |||||
| return this._alt | |||||
| } | |||||
| set heading(heading) { | |||||
| this._heading = heading | |||||
| } | |||||
| get heading() { | |||||
| return this._heading | |||||
| } | |||||
| set pitch(pitch) { | |||||
| this._pitch = pitch | |||||
| } | |||||
| get pitch() { | |||||
| return this._pitch | |||||
| } | |||||
| set roll(roll) { | |||||
| this._roll = roll | |||||
| } | |||||
| get roll() { | |||||
| return this._roll | |||||
| } | |||||
| serialize() { | |||||
| let position = new DC.Position(this._lng, this._lat, this._alt, this._heading, this._pitch, this._roll) | |||||
| return JSON.stringify(position) | |||||
| } | |||||
| /** | |||||
| * | |||||
| * @param {*} valStr | |||||
| * 反序列化 | |||||
| */ | |||||
| static deserialize(valStr) { | |||||
| let position = new DC.Position() | |||||
| let obj = JSON.parse(valStr) | |||||
| if (obj) { | |||||
| position.lng = obj.lng || 0 | |||||
| position.lat = obj.lat || 0 | |||||
| position.alt = obj.alt || 0 | |||||
| position.heading = obj.heading || 0 | |||||
| position.pitch = obj.pitch || 0 | |||||
| position.roll = obj.roll || 0 | |||||
| } | |||||
| return position | |||||
| } | |||||
| static fromCoordString(str) { | |||||
| let position = new DC.Position() | |||||
| if (str && typeof str === 'string') { | |||||
| let temp = str.split(',') | |||||
| if (temp && temp.length) { | |||||
| position.lng = temp[0] || 0 | |||||
| position.lat = temp[1] || 0 | |||||
| position.alt = temp[2] || 0 | |||||
| } | |||||
| } | |||||
| return position | |||||
| } | |||||
| static fromCoordArray(arr) { | |||||
| let position = new DC.Position() | |||||
| if (Array.isArray(arr)) { | |||||
| position.lng = arr[0] || 0 | |||||
| position.lat = arr[1] || 0 | |||||
| position.alt = arr[2] || 0 | |||||
| } | |||||
| return position | |||||
| } | |||||
| } | 
| /* | |||||
| * @Author: Caven | |||||
| * @Date: 2020-01-07 09:00:32 | |||||
| * @Last Modified by: Caven | |||||
| * @Last Modified time: 2020-01-31 13:51:12 | |||||
| */ | |||||
| import Cesium from '@/namespace' | |||||
| DC.T = class { | |||||
| /** | |||||
| * | |||||
| * @param {*} cartesian | |||||
| * 卡迪尔坐标转84坐标 | |||||
| */ | |||||
| static transformCartesianToWSG84(cartesian) { | |||||
| if (cartesian) { | |||||
| let ellipsoid = Cesium.Ellipsoid.WGS84 | |||||
| let cartographic = ellipsoid.cartesianToCartographic(cartesian) | |||||
| return new DC.Position( | |||||
| Cesium.Math.toDegrees(cartographic.longitude), | |||||
| Cesium.Math.toDegrees(cartographic.latitude), | |||||
| cartographic.height | |||||
| ) | |||||
| } | |||||
| return new DC.Position(0, 0) | |||||
| } | |||||
| /** | |||||
| * | |||||
| * @param {*} position | |||||
| * 84坐标转卡迪尔坐标 | |||||
| */ | |||||
| static transformWSG84ToCartesian(position) { | |||||
| return position | |||||
| ? Cesium.Cartesian3.fromDegrees(position.lng, position.lat, position.alt, Cesium.Ellipsoid.WGS84) | |||||
| : Cesium.Cartesian3.ZERO | |||||
| } | |||||
| /** | |||||
| * | |||||
| * @param {*} position | |||||
| * 84坐标转制图坐标 | |||||
| */ | |||||
| static transformWSG84ToCartographic(position) { | |||||
| return position | |||||
| ? Cesium.Cartographic.fromDegrees(position.lng, position.lat, position.alt) | |||||
| : Cesium.Cartographic.ZERO | |||||
| } | |||||
| /** | |||||
| * | |||||
| * @param {*} cartesianArr | |||||
| * 卡迪尔坐标数组转84坐标数组 | |||||
| */ | |||||
| static transformCartesianArrayToWSG84Array(cartesianArr) { | |||||
| return cartesianArr ? cartesianArr.map(item => DC.T.transformCartesianToWSG84(item)) : [] | |||||
| } | |||||
| /** | |||||
| * | |||||
| * @param {*} WSG84Arr | |||||
| * 84坐标数组转卡迪尔坐标数组 | |||||
| */ | |||||
| static transformWSG84ArrayToCartesianArray(WSG84Arr) { | |||||
| return WSG84Arr ? WSG84Arr.map(item => DC.T.transformWSG84ToCartesian(item)) : [] | |||||
| } | |||||
| static transformWindowCoordToWSG84(position, viewer) {} | |||||
| static transformWSG84ToWindowCoord(position, viewer) {} | |||||
| static transformWSG84ToCanvasCoord(position) {} | |||||
| static transformCanvasCoordToWSG84(position) {} | |||||
| } | 
| /* | |||||
| * @Author: Caven | |||||
| * @Date: 2019-12-31 17:50:13 | |||||
| * @Last Modified by: Caven | |||||
| * @Last Modified time: 2020-01-21 12:15:23 | |||||
| */ | |||||
| /** | |||||
| * Dom工具类 | |||||
| * 部分代码借鉴leaflet | |||||
| * https://github.com/Leaflet/Leaflet/tree/master/src/core | |||||
| */ | |||||
| DC.DomUtil = class { | |||||
| /** | |||||
| * | |||||
| * @param {*} tagName | |||||
| * @param {*} className | |||||
| * @param {*} container | |||||
| * Creates an HTML element with `tagName`, sets its class to `className`, and optionally appends it to `container` element. | |||||
| */ | |||||
| static create(tagName, className, container) { | |||||
| var el = document.createElement(tagName) | |||||
| el.className = className || '' | |||||
| if (container) { | |||||
| container.appendChild(el) | |||||
| } | |||||
| return el | |||||
| } | |||||
| /** | |||||
| *t | |||||
| * @param {*} el | |||||
| * Removes `el` from its parent element | |||||
| */ | |||||
| static remove(el) { | |||||
| var parent = el.parentNode | |||||
| if (parent) { | |||||
| parent.removeChild(el) | |||||
| } | |||||
| } | |||||
| /** | |||||
| * | |||||
| * @param {*} el | |||||
| * Removes all of `el`'s children elements from `el` | |||||
| */ | |||||
| static empty(el) { | |||||
| while (el.firstChild) { | |||||
| el.removeChild(el.firstChild) | |||||
| } | |||||
| } | |||||
| /** | |||||
| * | |||||
| * @param {*} el | |||||
| * @param {*} name | |||||
| * Adds `name` to the element's class attribute. | |||||
| */ | |||||
| static addClass(el, name) { | |||||
| if (el.classList !== undefined) { | |||||
| let classes = DC.Util.splitWords(name) | |||||
| for (let i = 0, len = classes.length; i < len; i++) { | |||||
| el.classList.add(classes[i]) | |||||
| } | |||||
| } else if (!this.hasClass(el, name)) { | |||||
| let className = this.getClass(el) | |||||
| this.setClass(el, (className ? className + ' ' : '') + name) | |||||
| } | |||||
| } | |||||
| /** | |||||
| * | |||||
| * @param {*} el | |||||
| * @param {*} name | |||||
| * Removes `name` from the element's class attribute. | |||||
| */ | |||||
| static removeClass(el, name) { | |||||
| if (el.classList !== undefined) { | |||||
| el.classList.remove(name) | |||||
| } else { | |||||
| this.setClass(el, DC.Util.trim((' ' + this.getClass(el) + ' ').replace(' ' + name + ' ', ' '))) | |||||
| } | |||||
| } | |||||
| /** | |||||
| * | |||||
| * @param {*} el | |||||
| * @param {*} name | |||||
| * Sets the element's class. | |||||
| */ | |||||
| static setClass(el, name) { | |||||
| if (el.className.baseVal === undefined) { | |||||
| el.className = name | |||||
| } else { | |||||
| // in case of SVG element | |||||
| el.className.baseVal = name | |||||
| } | |||||
| } | |||||
| /** | |||||
| * @param {*} el | |||||
| * Returns the element's class. | |||||
| */ | |||||
| static getClass(el) { | |||||
| // Check if the element is an SVGElementInstance and use the correspondingElement instead | |||||
| // (Required for linked SVG elements in IE11.) | |||||
| if (el.correspondingElement) { | |||||
| el = el.correspondingElement | |||||
| } | |||||
| return el.className.baseVal === undefined ? el.className : el.className.baseVal | |||||
| } | |||||
| } | 
| /* | |||||
| * @Author: Caven | |||||
| * @Date: 2019-12-31 17:58:01 | |||||
| * @Last Modified by: Caven | |||||
| * @Last Modified time: 2020-01-21 15:54:00 | |||||
| */ | |||||
| const CHARS = '0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz'.split('') | |||||
| /** | |||||
| * 工具类 | |||||
| * 部分代码借鉴leaflet | |||||
| * https://github.com/Leaflet/Leaflet/tree/master/src/core | |||||
| */ | |||||
| DC.Util = class { | |||||
| /** | |||||
| * | |||||
| * @param {*} prefix | |||||
| * generate uuid | |||||
| */ | |||||
| static uuid(prefix = 'D') { | |||||
| let uuid = [] | |||||
| uuid[8] = uuid[13] = uuid[18] = uuid[23] = '-' | |||||
| uuid[14] = '4' | |||||
| let r | |||||
| for (let i = 0; i < 36; i++) { | |||||
| if (!uuid[i]) { | |||||
| r = 0 | (Math.random() * 16) | |||||
| uuid[i] = CHARS[i == 19 ? (r & 0x3) | 0x8 : r] | |||||
| } | |||||
| } | |||||
| return prefix + '-' + uuid.join('') | |||||
| } | |||||
| /** | |||||
| * | |||||
| * @param {*} dest | |||||
| * @param {*} sources | |||||
| * Merges the properties of the `src` object (or multiple objects) into `dest` object and returns the latter. | |||||
| */ | |||||
| static merge(dest, ...sources) { | |||||
| let i, j, len, src | |||||
| for (j = 0, len = sources.length; j < len; j++) { | |||||
| src = sources[j] | |||||
| for (i in src) { | |||||
| dest[i] = src[i] | |||||
| } | |||||
| } | |||||
| return dest | |||||
| } | |||||
| /** | |||||
| * | |||||
| * @param {*} str | |||||
| * Compatibility polyfill for [String.prototype.trim](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String/Trim) | |||||
| */ | |||||
| static trim(str) { | |||||
| return str.trim ? str.trim() : str.replace(/^\s+|\s+$/g, '') | |||||
| } | |||||
| /** | |||||
| * | |||||
| * @param {*} str | |||||
| * Trims and splits the string on whitespace and returns the array of parts. | |||||
| */ | |||||
| static splitWords(str) { | |||||
| return this.trim(str).split(/\s+/) | |||||
| } | |||||
| } | 
| /* | |||||
| * @Author: Caven | |||||
| * @Date: 2020-01-06 16:38:49 | |||||
| * @Last Modified by: Caven | |||||
| * @Last Modified time: 2020-01-21 12:15:26 | |||||
| */ | |||||
| import './DC.Util' | |||||
| import './DC.DomUtil' | 
| /* | |||||
| * @Author: Caven | |||||
| * @Date: 2019-12-27 17:13:24 | |||||
| * @Last Modified by: Caven | |||||
| * @Last Modified time: 2020-01-31 14:14:17 | |||||
| */ | |||||
| import Cesium from '@/namespace' | |||||
| import ViewerOption from '../option/ViewerOption' | |||||
| import CameraOption from '../option/CameraOption' | |||||
| import MouseEvent from '../event/MouseEvent' | |||||
| import ViewerEvent from '../event/ViewerEvent' | |||||
| import Popup from '../widget/Popup' | |||||
| import ContextMenu from '../widget/ContextMenu' | |||||
| const DEF_OPTS = { | |||||
| animation: false, //Whether to create animated widgets, lower left corner of the meter | |||||
| baseLayerPicker: false, //Whether to display the layer selector | |||||
| fullscreenButton: false, //Whether to display the full-screen button | |||||
| geocoder: false, //To display the geocoder widget, query the button in the upper right corner | |||||
| homeButton: false, //Whether to display the Home button | |||||
| infoBox: false, //Whether to display the information box | |||||
| sceneModePicker: false, //Whether to display 3D/2D selector | |||||
| selectionIndicator: false, //Whether to display the selection indicator component | |||||
| timeline: false, //Whether to display the timeline | |||||
| navigationHelpButton: false, //Whether to display the help button in the upper right corner | |||||
| navigationInstructionsInitiallyVisible: false, | |||||
| creditContainer: undefined, | |||||
| shouldAnimate: true | |||||
| } | |||||
| DC.Viewer = class { | |||||
| constructor(id, options = {}) { | |||||
| if (!id || !document.getElementById(id)) { | |||||
| throw Error('the id empty') | |||||
| } | |||||
| this._delegate = new Cesium.Viewer(id, { | |||||
| ...options, | |||||
| ...DEF_OPTS | |||||
| }) // Initialize the viewer | |||||
| new MouseEvent(this) // Register global mouse events | |||||
| 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._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 | |||||
| this.on(DC.ViewerEventType.ADD_EFFECT, this._addEffectCallback, this) //Initialize effect add event | |||||
| this.on(DC.ViewerEventType.REMOVE_EFFECT, this._removeEffectCallback, this) //Initialize effect remove event | |||||
| /** | |||||
| * Add default components | |||||
| */ | |||||
| this._popup = new Popup() | |||||
| this._contextMenu = new ContextMenu() | |||||
| this.use(this._popup).use(this._contextMenu) | |||||
| } | |||||
| get delegate() { | |||||
| return this._delegate | |||||
| } | |||||
| get dcContainer() { | |||||
| return this._dcContainer | |||||
| } | |||||
| get scene() { | |||||
| return this._delegate.scene | |||||
| } | |||||
| get camera() { | |||||
| return this._delegate.camera | |||||
| } | |||||
| get canvas() { | |||||
| return this._delegate.scene.canvas | |||||
| } | |||||
| get viewerEvent() { | |||||
| return this._viewerEvent | |||||
| } | |||||
| get popup() { | |||||
| return this._popup | |||||
| } | |||||
| get contextMenu() { | |||||
| return this._contextMenu | |||||
| } | |||||
| _addLayerCallback(layer) { | |||||
| if (layer && layer.layerEvent && layer.state !== DC.LayerState.ADDED) { | |||||
| !this._layerCache[layer.type] && (this._layerCache[layer.type] = {}) | |||||
| layer.layerEvent.fire(DC.LayerEventType.ADD, this) | |||||
| this._layerCache[layer.type][layer.id] = layer | |||||
| } | |||||
| } | |||||
| _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]) { | |||||
| delete this._layerCache[layer.type][layer.id] | |||||
| } | |||||
| } | |||||
| } | |||||
| _addEffectCallback(effect) {} | |||||
| _removeEffectCallback(effect) {} | |||||
| /** | |||||
| * | |||||
| * @param {*} options | |||||
| * set viewer options | |||||
| * | |||||
| */ | |||||
| setOptions(options) { | |||||
| this._viewerOption.setOptions(options) | |||||
| return this | |||||
| } | |||||
| /** | |||||
| * | |||||
| * @param {*} min | |||||
| * @param {*} max | |||||
| * set camera options | |||||
| */ | |||||
| setPitchRange(min = -90, max = -20) { | |||||
| this._cameraOption.setPichRange(min, max) | |||||
| return this | |||||
| } | |||||
| /** | |||||
| * Restrict camera access underground | |||||
| */ | |||||
| limitCameraToGround() { | |||||
| this._cameraOption.limitCameraToGround() | |||||
| return this | |||||
| } | |||||
| /** | |||||
| * | |||||
| * @param {*} baseLayers | |||||
| * Add the baselayer to the viewer. | |||||
| * The baselayer can be a single or an array, | |||||
| * and when the baselayer is an array, the baselayer will be loaded together | |||||
| */ | |||||
| addBaseLayer(baseLayers) { | |||||
| if (!baseLayers) { | |||||
| return this | |||||
| } | |||||
| if (!Array.isArray(baseLayers)) { | |||||
| baseLayers = [baseLayers] | |||||
| } | |||||
| baseLayers.forEach(item => { | |||||
| if ( | |||||
| item instanceof Cesium.UrlTemplateImageryProvider || | |||||
| item instanceof Cesium.ArcGisMapServerImageryProvider || | |||||
| item instanceof Cesium.SingleTileImageryProvider || | |||||
| item instanceof Cesium.WebMapTileServiceImageryProvider | |||||
| ) { | |||||
| this._baseLayerPicker.imageryProviderViewModels.push( | |||||
| new Cesium.ProviderViewModel({ | |||||
| name: '地图', | |||||
| creationFunction: () => { | |||||
| return item | |||||
| } | |||||
| }) | |||||
| ) | |||||
| } | |||||
| }) | |||||
| if (!this._baseLayerPicker.selectedImagery) { | |||||
| this._baseLayerPicker.selectedImagery = this._baseLayerPicker.imageryProviderViewModels[0] | |||||
| } | |||||
| return this | |||||
| } | |||||
| /** | |||||
| * | |||||
| * @param {*} index | |||||
| * Change the current globe display of the baselayer | |||||
| */ | |||||
| changeBaseLayer(index) { | |||||
| if (this._baseLayerPicker && index >= 0) { | |||||
| this._baseLayerPicker.selectedImagery = this._baseLayerPicker.imageryProviderViewModels[index] | |||||
| } | |||||
| return this | |||||
| } | |||||
| /** | |||||
| * | |||||
| * @param {*} layer | |||||
| * Add a layer to the viewer | |||||
| */ | |||||
| addLayer(layer) { | |||||
| this._viewerEvent.fire(DC.ViewerEventType.ADD_LAYER, layer) | |||||
| return this | |||||
| } | |||||
| /** | |||||
| * | |||||
| * @param {*} layer | |||||
| * remove a layer from the viewer | |||||
| */ | |||||
| removeLayer(layer) { | |||||
| this._viewerEvent.fire(DC.ViewerEventType.ADD_LAYER, layer) | |||||
| return this | |||||
| } | |||||
| /** | |||||
| * | |||||
| * @param {*} id | |||||
| * get the layer by id | |||||
| */ | |||||
| getLayer(id) { | |||||
| let layer = undefined | |||||
| for (let type in this._layerCache) { | |||||
| let cache = this._layerCache[type] | |||||
| for (let layerId in cache) { | |||||
| if (layerId === id) { | |||||
| layer = cache[layerId] | |||||
| break | |||||
| } | |||||
| } | |||||
| if (layer) { | |||||
| break | |||||
| } | |||||
| } | |||||
| return layer | |||||
| } | |||||
| /** | |||||
| * get all layers | |||||
| */ | |||||
| getLayers() { | |||||
| let result = [] | |||||
| for (let type in this._layerCache) { | |||||
| let cache = this._layerCache[type] | |||||
| for (let layerId in cache) { | |||||
| result.push(cache[layerId]) | |||||
| } | |||||
| } | |||||
| return result | |||||
| } | |||||
| /** | |||||
| * | |||||
| * @param {*} method | |||||
| * @param {*} context | |||||
| * | |||||
| */ | |||||
| eachLayer(method, context) { | |||||
| for (let type in this._layerCache) { | |||||
| let cache = this._layerCache[type] | |||||
| for (let layerId in cache) { | |||||
| method.call(context, cache[layerId]) | |||||
| } | |||||
| } | |||||
| return this | |||||
| } | |||||
| addEffect(effect) {} | |||||
| removeEffect(effect) {} | |||||
| flyTo(target) { | |||||
| this._delegate.flyTo(target.delegate || target) | |||||
| return this | |||||
| } | |||||
| zoomTo(target) { | |||||
| this._delegate.zoomTo(target.delegate || target) | |||||
| return this | |||||
| } | |||||
| flyToPosition(position, completeCallback) { | |||||
| if (position instanceof DC.Position) { | |||||
| this._delegate.camera.flyTo({ | |||||
| destination: DC.T.transformWSG84ToCartesian(position), | |||||
| orientation: { | |||||
| heading: Cesium.Math.toRadians(position.heading), | |||||
| pitch: Cesium.Math.toRadians(position.pitch), | |||||
| roll: Cesium.Math.toRadians(position.roll) | |||||
| }, | |||||
| complete: completeCallback | |||||
| }) | |||||
| } | |||||
| return this | |||||
| } | |||||
| on(type, callback, context) { | |||||
| this._viewerEvent.on(type, callback, context || this) | |||||
| return this | |||||
| } | |||||
| off(type, callback, context) { | |||||
| this._viewerEvent.off(type, callback, context || this) | |||||
| return this | |||||
| } | |||||
| use(plugin) { | |||||
| if (plugin && plugin.install) { | |||||
| plugin.install(this) | |||||
| } | |||||
| return this | |||||
| } | |||||
| } | 
| /* | |||||
| * @Author: Caven | |||||
| * @Date: 2019-12-31 17:32:01 | |||||
| * @Last Modified by: Caven | |||||
| * @Last Modified time: 2020-01-21 12:15:32 | |||||
| */ | |||||
| import Widget from './Widget' | |||||
| class ContextMenu extends Widget { | |||||
| constructor() { | |||||
| super() | |||||
| this._viewer = undefined | |||||
| this._position = undefined | |||||
| this._wapper = DC.DomUtil.create('div', 'dc-context-menu') | |||||
| this._state = DC.WidgetState.INSTALLED | |||||
| this.type = DC.WidgetType.ContextMenu | |||||
| } | |||||
| _handleRightclick(movement) {} | |||||
| _handleclick(movement) { | |||||
| this.hide() | |||||
| } | |||||
| } | |||||
| export default ContextMenu | 
| /* | |||||
| * @Author: Caven | |||||
| * @Date: 2020-01-15 19:16:45 | |||||
| * @Last Modified by: Caven | |||||
| * @Last Modified time: 2020-01-21 12:15:34 | |||||
| */ | |||||
| class Popup { | |||||
| constructor() { | |||||
| this._viewer = undefined | |||||
| this._position = undefined | |||||
| this._wapper = DC.DomUtil.create('div', 'dc-popup') | |||||
| } | |||||
| _setWindowCoord(windowCoord) {} | |||||
| } | |||||
| export default Popup | 
| /* | |||||
| * @Author: Caven | |||||
| * @Date: 2020-01-15 19:17:52 | |||||
| * @Last Modified by: Caven | |||||
| * @Last Modified time: 2020-01-21 12:13:45 | |||||
| */ | |||||
| import Cesium from '@/namespace' | |||||
| class Widget { | |||||
| constructor() { | |||||
| this._viewer = undefined | |||||
| this._position = undefined | |||||
| this._show = false | |||||
| this._wapper = undefined | |||||
| this._windowCoord = undefined | |||||
| this._state = undefined | |||||
| this.type = undefined | |||||
| } | |||||
| /** | |||||
| * | |||||
| * @param {*} windowCoord | |||||
| * 更新Widget位置需要子类覆盖 | |||||
| */ | |||||
| _updateWindowCoord(windowCoord) {} | |||||
| /** | |||||
| * | |||||
| * @param {*} viewer | |||||
| */ | |||||
| setPosition(position) { | |||||
| this._position = position | |||||
| if (this._viewer) { | |||||
| let self = this | |||||
| let scene = this._viewer.scene | |||||
| scene.postRender.addEventListener(() => { | |||||
| let windowCoord = Cesium.SceneTransforms.wgs84ToWindowCoordinates(scene, self._position) | |||||
| this._setWindowCoord(windowCoord) | |||||
| }) | |||||
| } | |||||
| } | |||||
| /** | |||||
| * | |||||
| * @param {*} viewer | |||||
| */ | |||||
| install(viewer) { | |||||
| this._viewer = viewer | |||||
| this._wapper && this._viewer.dcContainer.appendChild(this._wapper) | |||||
| this._state = DC.WidgetState.INSTALLED | |||||
| } | |||||
| /** | |||||
| * | |||||
| * @param {*} position | |||||
| * 显示组件 | |||||
| */ | |||||
| show(position) { | |||||
| this._show = true | |||||
| position && position instanceof DC.Position && this.setPosition(position) | |||||
| this._wapper && (this._wapper.style.visibility = 'visible') | |||||
| this._state = DC.WidgetState.SHOW | |||||
| } | |||||
| /** | |||||
| * 隐藏组件 | |||||
| */ | |||||
| hide() { | |||||
| this._show = false | |||||
| this._wapper && (this._wapper.style.visibility = 'hidden') | |||||
| this._state = DC.WidgetState.HIDDEN | |||||
| } | |||||
| /** | |||||
| * | |||||
| * @param {*} content | |||||
| */ | |||||
| setContent(content) { | |||||
| if (content && typeof content === 'string') { | |||||
| this._wapper.innerHTML = content | |||||
| } else if (content && content instanceof Element) { | |||||
| this._wapper.appendChild(content) | |||||
| } | |||||
| } | |||||
| } | |||||
| export default Widget | 
| /* | |||||
| * @Author: Caven | |||||
| * @Date: 2020-01-15 19:29:58 | |||||
| * @Last Modified by: Caven | |||||
| * @Last Modified time: 2020-01-21 12:22:56 | |||||
| */ | |||||
| import './ContextMenu' | |||||
| import './Popup' | 
| /* | |||||
| * @Author: Caven | |||||
| * @Date: 2020-01-14 18:24:57 | |||||
| * @Last Modified by: Caven | |||||
| * @Last Modified time: 2020-01-30 23:54:21 | |||||
| */ | |||||
| import './animation/DC.GlobeRotate' | |||||
| import './roaming/DC.Roaming' | 
| /* | |||||
| * @Author: Caven | |||||
| * @Date: 2020-01-14 18:22:10 | |||||
| * @Last Modified by: Caven | |||||
| * @Last Modified time: 2020-01-30 22:32:12 | |||||
| */ | |||||
| ;(function() { | |||||
| let initialized = false | |||||
| if (!DC) { | |||||
| throw new Error('missing dc sdk') | |||||
| } | |||||
| DC.init(() => { | |||||
| !initialized && require('./DC.Pulgins.Loader') | |||||
| initialized = true | |||||
| }) | |||||
| })() | 
| /* | |||||
| * @Author: Caven | |||||
| * @Date: 2020-01-15 20:23:42 | |||||
| * @Last Modified by: Caven | |||||
| * @Last Modified time: 2020-01-18 18:12:00 | |||||
| */ | 
| /* | |||||
| * @Author: Caven | |||||
| * @Date: 2020-01-15 20:23:46 | |||||
| * @Last Modified by: Caven | |||||
| * @Last Modified time: 2020-01-15 20:23:46 | |||||
| */ | 
| /* | |||||
| * @Author: Caven | |||||
| * @Date: 2020-01-14 18:25:41 | |||||
| * @Last Modified by: Caven | |||||
| * @Last Modified time: 2020-01-19 11:09:00 | |||||
| */ | |||||
| import Cesium from '../../namespace' | |||||
| import Effect from './Effect' | |||||
| DC.WaterEffect = class extends Effect { | |||||
| constructor(positions) { | |||||
| super() | |||||
| this._positions = positions | |||||
| } | |||||
| _prepareDelegate() { | |||||
| let geometry = Cesium.PolygonGeometry.fromPositions({}) | |||||
| this._delegate = new Cesium.Primitive({ | |||||
| geometryInstances: new Cesium.GeometryInstance({ | |||||
| geometry | |||||
| }) | |||||
| }) | |||||
| } | |||||
| } | 
| /* | |||||
| * @Author: Caven | |||||
| * @Date: 2020-01-14 18:33:33 | |||||
| * @Last Modified by: Caven | |||||
| * @Last Modified time: 2020-01-19 11:11:08 | |||||
| */ | |||||
| import EffectEvent from '../../core/event/EffectEvent' | |||||
| class Effect { | |||||
| constructor() { | |||||
| this._viewer = undefined | |||||
| this._effectEvent = new EffectEvent() | |||||
| this._delegate = undefined | |||||
| } | |||||
| /** | |||||
| * 准备代理 | |||||
| */ | |||||
| _prepareDelegate() {} | |||||
| /** | |||||
| * | |||||
| * @param {*} viewer | |||||
| * 效果添加的回调函数, | |||||
| */ | |||||
| _addCallback(viewer) {} | |||||
| /** | |||||
| * 效果添加的回调函数 | |||||
| */ | |||||
| _removeCallback() {} | |||||
| /** | |||||
| * | |||||
| * @param {*} viewer | |||||
| * 添加到Viewer | |||||
| */ | |||||
| addToViewer(viewer) {} | |||||
| } | 
| /* | |||||
| * @Author: Caven | |||||
| * @Date: 2020-01-14 18:25:25 | |||||
| * @Last Modified by: Caven | |||||
| * @Last Modified time: 2020-01-15 13:05:24 | |||||
| */ | |||||
| import './DC.WaterEffect' | 
| /* | |||||
| * @Author: Caven | |||||
| * @Date: 2020-01-19 13:38:48 | |||||
| * @Last Modified by: Caven | |||||
| * @Last Modified time: 2020-01-19 13:40:27 | |||||
| */ | |||||
| DC.CzmlLayer = class {} | 
| /* | |||||
| * @Author: Caven | |||||
| * @Date: 2020-01-19 11:03:17 | |||||
| * @Last Modified by: Caven | |||||
| * @Last Modified time: 2020-01-19 11:03:17 | |||||
| */ | 
| /* | |||||
| * @Author: Caven | |||||
| * @Date: 2020-01-19 11:04:45 | |||||
| * @Last Modified by: Caven | |||||
| * @Last Modified time: 2020-01-19 11:13:00 | |||||
| */ | |||||
| import './DC.CzmlLayer' | |||||
| import './DC.KmlLayer' | 
| /* | |||||
| * @Author: Caven | |||||
| * @Date: 2020-01-19 11:13:57 | |||||
| * @Last Modified by: Caven | |||||
| * @Last Modified time: 2020-01-19 11:14:30 | |||||
| */ | 
| /* | |||||
| * @Author: Caven | |||||
| * @Date: 2020-01-19 11:13:53 | |||||
| * @Last Modified by: Caven | |||||
| * @Last Modified time: 2020-01-19 11:13:53 | |||||
| */ | 
| /* | |||||
| * @Author: Caven | |||||
| * @Date: 2020-01-19 11:21:48 | |||||
| * @Last Modified by: Caven | |||||
| * @Last Modified time: 2020-01-31 13:58:36 | |||||
| */ | |||||
| import Cesium from '@/namespace' | |||||
| const DEF_PAHT_STYLE = { | |||||
| resolution: 1, | |||||
| material: new Cesium.PolylineGlowMaterialProperty({ | |||||
| glowPower: 0.1, | |||||
| color: Cesium.Color.YELLOW | |||||
| }), | |||||
| width: 10 | |||||
| } | |||||
| DC.Roaming = class { | |||||
| constructor(viewer, options) { | |||||
| this._viewer = viewer | |||||
| this._positions = [] | |||||
| this._modelPath = options.modelPath | |||||
| this._modelScale = options.modelScale || 1 | |||||
| this._modelShow = options.modelShow || true | |||||
| this._time = options.time || 360 | |||||
| this._startTime = undefined | |||||
| this._endTime = undefined | |||||
| this._showPath = options.showPath || false | |||||
| this._delegate = new Cesium.Entity() | |||||
| this._perspective = options.perspective || 0 | |||||
| this._parsePositions(options.positions) | |||||
| } | |||||
| /** | |||||
| * | |||||
| * @param {*} positions | |||||
| */ | |||||
| _parsePositions(positions) { | |||||
| if (typeof positions === 'string') { | |||||
| if (positions.indexOf('#') >= 0) { | |||||
| throw new Error('the positions invalid') | |||||
| } | |||||
| positions = positions.split(';') | |||||
| } | |||||
| this._positions = positions.map(item => { | |||||
| if (Array.isArray(item)) { | |||||
| return DC.Position.fromCoordArray(item) | |||||
| } else { | |||||
| return DC.Position.fromCoordString(item) | |||||
| } | |||||
| }) | |||||
| } | |||||
| _preparePositionProperty() { | |||||
| var property = new Cesium.SampledPositionProperty() | |||||
| if (this._positions.length) { | |||||
| let timeInterval = this._time - (this._time % this._positions.length) | |||||
| this._startTime = Cesium.JulianDate.now() | |||||
| let increment = timeInterval / this._positions.length | |||||
| this._endTime = Cesium.JulianDate.addSeconds(this._startTime, timeInterval, new Cesium.JulianDate()) | |||||
| this._positions.forEach((item, index) => { | |||||
| let time = Cesium.JulianDate.addSeconds(this._startTime, index * increment, new Cesium.JulianDate()) | |||||
| property.addSample(time, DC.T.transformWSG84ToCartesian(item)) | |||||
| }) | |||||
| } | |||||
| return property | |||||
| } | |||||
| _prepareDelegate() { | |||||
| let property = this._preparePositionProperty() | |||||
| this._delegate.merge({ | |||||
| position: property, | |||||
| orientation: new Cesium.VelocityOrientationProperty(property), | |||||
| model: { | |||||
| uri: this._modelPath, | |||||
| scale: this._modelScale, | |||||
| show: this._modelShow | |||||
| }, | |||||
| path: { | |||||
| ...DEF_PAHT_STYLE, | |||||
| show: this._showPath | |||||
| } | |||||
| }) | |||||
| if (this._startTime && this._endTime) { | |||||
| this._delegate.availability = new Cesium.TimeIntervalCollection([ | |||||
| new Cesium.TimeInterval({ | |||||
| start: this._startTime, | |||||
| stop: this._endTime | |||||
| }) | |||||
| ]) | |||||
| } | |||||
| this._delegate.position.setInterpolationOptions({ | |||||
| interpolationDegree: 5, | |||||
| interpolationAlgorithm: Cesium.LagrangePolynomialApproximation | |||||
| }) | |||||
| } | |||||
| _setClock() { | |||||
| this._viewer.delegate.clock.startTime = this._startTime.clone() | |||||
| this._viewer.delegate.clock.stopTime = this._endTime.clone() | |||||
| this._viewer.delegate.clock.currentTime = this._startTime.clone() | |||||
| this._viewer.delegate.clock.clockRange = Cesium.ClockRange.UNBOUNDED | |||||
| } | |||||
| /** | |||||
| * | |||||
| * @param {*} speed | |||||
| */ | |||||
| setSpeed(speed) { | |||||
| this._viewer.delegate.clock.multiplier = speed | |||||
| } | |||||
| /** | |||||
| * | |||||
| * @param {*} perspective | |||||
| */ | |||||
| setPerspective(perspective) { | |||||
| this._perspective = perspective | |||||
| if (this._delegate.model) { | |||||
| if (perspective === 0) { | |||||
| this._viewer.delegate.trackedEntity = this._delegate | |||||
| } else if (perspective === 1) { | |||||
| this._viewer.delegate.trackedEntity = undefined | |||||
| this._viewer.delegate.zoomTo(this._delegate, new Cesium.HeadingPitchRange(0, Cesium.Math.toRadians(-90))) | |||||
| } | |||||
| } | |||||
| } | |||||
| reset() { | |||||
| this._prepareDelegate() | |||||
| this._setClock() | |||||
| this._viewer.delegate.clock.multiplier = 1 | |||||
| } | |||||
| start() { | |||||
| this._viewer.delegate.entities.remove(this._delegate) | |||||
| this._prepareDelegate() | |||||
| this._setClock() | |||||
| this._viewer.delegate.entities.add(this._delegate) | |||||
| } | |||||
| stop() { | |||||
| this._viewer.delegate.entities.remove(this._delegate) | |||||
| this._viewer.delegate.clock.multiplier = 1 | |||||
| this._viewer.delegate.trackedEntity = undefined | |||||
| } | |||||
| } | 
| * @Author: Caven | * @Author: Caven | ||||
| * @Date: 2019-12-27 17:18:52 | * @Date: 2019-12-27 17:18:52 | ||||
| * @Last Modified by: Caven | * @Last Modified by: Caven | ||||
| * @Last Modified time: 2020-01-18 19:06:43 | |||||
| * @Last Modified time: 2020-01-31 15:09:38 | |||||
| */ | */ | ||||
| import './const' | import './const' | ||||
| import './utils' | import './utils' | ||||
| import './postion/DC.Position' | import './postion/DC.Position' | ||||
| import './transform/DC.T' | import './transform/DC.T' | ||||
| import './imagery' | |||||
| import './layer' | import './layer' | ||||
| import './overlay' | import './overlay' | ||||
| import './viewer/DC.Viewer' | import './viewer/DC.Viewer' | 
| * @Author: Caven | * @Author: Caven | ||||
| * @Date: 2019-12-27 14:29:05 | * @Date: 2019-12-27 14:29:05 | ||||
| * @Last Modified by: Caven | * @Last Modified by: Caven | ||||
| * @Last Modified time: 2020-01-19 21:10:19 | |||||
| * @Last Modified time: 2020-01-31 15:09:26 | |||||
| */ | */ | ||||
| ;(function() { | ;(function() { | ||||
| let namespace = {} | let namespace = {} | ||||
| let initialized = false | |||||
| let DC = { | let DC = { | ||||
| Http: undefined, | Http: undefined, | ||||
| Version: '1.0.0', | Version: '1.0.0', | ||||
| */ | */ | ||||
| DC.ready = function(callback) { | DC.ready = function(callback) { | ||||
| try { | try { | ||||
| requireCesium().then(() => { | |||||
| require('./DC.Loader') | |||||
| delete window.Cesium //删除winow下的Cesium | |||||
| callback && callback() | |||||
| }) | |||||
| if (!initialized) { | |||||
| requireCesium().then(() => { | |||||
| require('./DC.Loader') | |||||
| delete window.Cesium //删除winow下的Cesium | |||||
| }) | |||||
| } | |||||
| callback && callback() | |||||
| initialized = true | |||||
| } catch (e) { | } catch (e) { | ||||
| delete window.Cesium | delete window.Cesium | ||||
| initialized = false | |||||
| } | } | ||||
| } | } | ||||
| })() | })() | 
| * @Author: Caven | * @Author: Caven | ||||
| * @Date: 2020-01-03 10:09:19 | * @Date: 2020-01-03 10:09:19 | ||||
| * @Last Modified by: Caven | * @Last Modified by: Caven | ||||
| * @Last Modified time: 2020-01-19 10:38:14 | |||||
| * @Last Modified time: 2020-01-31 15:03:45 | |||||
| */ | */ | ||||
| import Cesium from '../../namespace' | |||||
| import Cesium from '@/namespace' | |||||
| DC.MouseEventType = { | DC.MouseEventType = { | ||||
| CLICK: Cesium.ScreenSpaceEventType.LEFT_CLICK, | CLICK: Cesium.ScreenSpaceEventType.LEFT_CLICK, | ||||
| RIGHT_CLICK: Cesium.ScreenSpaceEventType.RIGHT_CLICK, | RIGHT_CLICK: Cesium.ScreenSpaceEventType.RIGHT_CLICK, | ||||
| DB_CLICK: Cesium.ScreenSpaceEventType.LEFT_DOUBLE_CLICK, | DB_CLICK: Cesium.ScreenSpaceEventType.LEFT_DOUBLE_CLICK, | ||||
| MOUSE_MOVE: Cesium.ScreenSpaceEventType.MOUSE_MOVE, | MOUSE_MOVE: Cesium.ScreenSpaceEventType.MOUSE_MOVE, | ||||
| WHEEL: Cesium.ScreenSpaceEventType.WHEEL | |||||
| WHEEL: Cesium.ScreenSpaceEventType.WHEEL, | |||||
| MOUSE_OVER: 'mouseover', | |||||
| MOUSE_OUT: 'mouseout' | |||||
| } | } | ||||
| DC.ViewerEventType = { | DC.ViewerEventType = { | ||||
| ADD_LAYER: 'addLayer', | ADD_LAYER: 'addLayer', | ||||
| REMOVE_LAYER: 'removeLayer', | REMOVE_LAYER: 'removeLayer', | ||||
| ADD_IMAGERY_LAYER: 'addImageryLayer', | |||||
| CHANGE_IMAGERY_LAYER: 'changeImageryLayer', | |||||
| ADD_EFFECT: 'addEffect', | ADD_EFFECT: 'addEffect', | ||||
| REMOVE_EFFECT: 'removeEffect' | REMOVE_EFFECT: 'removeEffect' | ||||
| } | } | 
| * @Author: Caven | * @Author: Caven | ||||
| * @Date: 2020-01-02 14:26:35 | * @Date: 2020-01-02 14:26:35 | ||||
| * @Last Modified by: Caven | * @Last Modified by: Caven | ||||
| * @Last Modified time: 2020-01-19 10:21:54 | |||||
| * @Last Modified time: 2020-01-31 15:03:49 | |||||
| */ | */ | ||||
| import Cesium from '@/namespace' | import Cesium from '@/namespace' | ||||
| * @Author: Caven | * @Author: Caven | ||||
| * @Date: 2020-01-02 15:24:38 | * @Date: 2020-01-02 15:24:38 | ||||
| * @Last Modified by: Caven | * @Last Modified by: Caven | ||||
| * @Last Modified time: 2020-01-19 10:22:01 | |||||
| * @Last Modified time: 2020-01-31 15:03:52 | |||||
| */ | */ | ||||
| class Event { | class Event { | ||||
| constructor() { | constructor() { | 
| * @Author: Caven | * @Author: Caven | ||||
| * @Date: 2020-01-02 14:26:35 | * @Date: 2020-01-02 14:26:35 | ||||
| * @Last Modified by: Caven | * @Last Modified by: Caven | ||||
| * @Last Modified time: 2020-01-19 10:21:58 | |||||
| * @Last Modified time: 2020-01-31 15:03:58 | |||||
| */ | */ | ||||
| import Cesium from '@/namespace' | import Cesium from '@/namespace' | ||||
| * @Author: Caven | * @Author: Caven | ||||
| * @Date: 2019-12-31 16:58:31 | * @Date: 2019-12-31 16:58:31 | ||||
| * @Last Modified by: Caven | * @Last Modified by: Caven | ||||
| * @Last Modified time: 2020-01-19 10:22:05 | |||||
| * @Last Modified time: 2020-01-31 15:04:36 | |||||
| */ | */ | ||||
| import Cesium from '@/namespace' | import Cesium from '@/namespace' | ||||
| import Event from './Event' | import Event from './Event' | ||||
| class MouseEvent extends Event { | class MouseEvent extends Event { | ||||
| this._viewer = viewer | this._viewer = viewer | ||||
| this._handler = new Cesium.ScreenSpaceEventHandler(this._viewer.canvas) | this._handler = new Cesium.ScreenSpaceEventHandler(this._viewer.canvas) | ||||
| this._registerEvent() | 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) | |||||
| } | } | ||||
| /** | /** | ||||
| * 注册全局鼠标事件 | |||||
| * Register Cesium mouse events | |||||
| */ | */ | ||||
| _registerEvent() { | _registerEvent() { | ||||
| for (let key in Cesium.ScreenSpaceEventType) { | for (let key in Cesium.ScreenSpaceEventType) { | ||||
| this._eventCache[type].raiseEvent(movement) | this._eventCache[type].raiseEvent(movement) | ||||
| }, type) | }, type) | ||||
| } | } | ||||
| this.on('click', this._clickCallback, this) | |||||
| this.on('rightclick', this._rightClickCallback, this) | |||||
| this.on('mousemove', this._mouseMoveCallback, this) | |||||
| this.on('dbclick', this._dbclickCallback, this) | |||||
| } | } | ||||
| /** | /** | ||||
| * | * | ||||
| * @param {*} target | * @param {*} target | ||||
| * 获取鼠标事件的目标信息 | |||||
| * gets the target information for the mouse event | |||||
| */ | */ | ||||
| _getTargetInfo(target) { | _getTargetInfo(target) { | ||||
| let overlay = undefined | let overlay = undefined | ||||
| * @param {*} type | * @param {*} type | ||||
| * @param {*} target | * @param {*} target | ||||
| */ | */ | ||||
| _raiseEvent(type, target, position = null) { | _raiseEvent(type, target, position = null) { | ||||
| let stopPropagation = false | let stopPropagation = false | ||||
| if (target) { | if (target) { | ||||
| let result = this._getTargetInfo(target) | |||||
| let overlay = result.overlay | |||||
| let targetInfo = this._getTargetInfo(target) | |||||
| let overlay = targetInfo.overlay | |||||
| if (overlay && overlay.overlayEvent) { | if (overlay && overlay.overlayEvent) { | ||||
| let event = overlay.overlayEvent.getEvent(type) | let event = overlay.overlayEvent.getEvent(type) | ||||
| if (event && event.numberOfListeners > 0) { | if (event && event.numberOfListeners > 0) { | ||||
| event.raiseEvent({ | event.raiseEvent({ | ||||
| layer: result.layer, | |||||
| layer: targetInfo.layer, | |||||
| overlay: overlay, | overlay: overlay, | ||||
| feature: result.feature, | |||||
| feature: targetInfo.feature, | |||||
| position: position | position: position | ||||
| }) | }) | ||||
| stopPropagation = true | stopPropagation = true | ||||
| if (!stopPropagation) { | if (!stopPropagation) { | ||||
| let event = this._viewer.viewerEvent.getEvent(type) | let event = this._viewer.viewerEvent.getEvent(type) | ||||
| if (event && event.numberOfListeners > 0) { | if (event && event.numberOfListeners > 0) { | ||||
| event.raiseEvent({ position: position }) | |||||
| event.raiseEvent({ position: position, overlay: undefined }) | |||||
| } | } | ||||
| } | } | ||||
| } | } | ||||
| /** | /** | ||||
| * | * | ||||
| * @param {*} movement | * @param {*} movement | ||||
| * 单击默认事件 | |||||
| * default click event callback | |||||
| */ | */ | ||||
| _clickCallback(movement) { | _clickCallback(movement) { | ||||
| if (!movement || !movement.position) { | if (!movement || !movement.position) { | ||||
| } | } | ||||
| let target = this._viewer.scene.pick(movement.position) | let target = this._viewer.scene.pick(movement.position) | ||||
| let cartesian = this._viewer.scene.pickPosition(movement.position) | let cartesian = this._viewer.scene.pickPosition(movement.position) | ||||
| this._raiseEvent('click', target, cartesian) | |||||
| this._raiseEvent(Cesium.ScreenSpaceEventType.LEFT_CLICK, target, cartesian) | |||||
| } | } | ||||
| /** | /** | ||||
| * | * | ||||
| * @param {*} movement | * @param {*} movement | ||||
| * 双击默认事件 | |||||
| * default dbclick event callback | |||||
| */ | */ | ||||
| _dbclickCallback(movement) { | _dbclickCallback(movement) { | ||||
| if (!movement || !movement.position) { | if (!movement || !movement.position) { | ||||
| } | } | ||||
| let target = this._viewer.scene.pick(movement.position) | let target = this._viewer.scene.pick(movement.position) | ||||
| let cartesian = this._viewer.scene.pickPosition(movement.position) | let cartesian = this._viewer.scene.pickPosition(movement.position) | ||||
| this._raiseEvent('dbclick', target, cartesian) | |||||
| this._raiseEvent(Cesium.ScreenSpaceEventType.LEFT_DOUBLE_CLICK, target, cartesian) | |||||
| } | } | ||||
| /** | /** | ||||
| * @param {*} movement | * @param {*} movement | ||||
| * 右击默认事件 | |||||
| * default rightclick event callback | |||||
| */ | */ | ||||
| _rightClickCallback(movement) { | _rightClickCallback(movement) { | ||||
| if (!movement || !movement.position) { | if (!movement || !movement.position) { | ||||
| } | } | ||||
| let target = this._viewer.scene.pick(movement.position) | let target = this._viewer.scene.pick(movement.position) | ||||
| let cartesian = this._viewer.scene.pickPosition(movement.position) | let cartesian = this._viewer.scene.pickPosition(movement.position) | ||||
| this._raiseEvent('rightclick', target, cartesian) | |||||
| this._raiseEvent(Cesium.ScreenSpaceEventType.RIGHT_CLICK, target, cartesian) | |||||
| } | } | ||||
| /** | |||||
| * | |||||
| * @param {*} movement | |||||
| * default mousemove event callback | |||||
| */ | |||||
| _mouseMoveCallback(movement) { | _mouseMoveCallback(movement) { | ||||
| if (!movement || !movement.endPosition) { | if (!movement || !movement.endPosition) { | ||||
| return | return | ||||
| } | } | ||||
| let target = this._viewer.scene.pick(movement.endPosition) | let target = this._viewer.scene.pick(movement.endPosition) | ||||
| if (target) { | |||||
| this._viewer.canvas.style.cursor = 'pointer' | |||||
| } | |||||
| let cartesian = this._viewer.scene.pickPosition(movement.endPosition) | let cartesian = this._viewer.scene.pickPosition(movement.endPosition) | ||||
| this._raiseEvent('mousemove', target, cartesian) | |||||
| this._raiseEvent(Cesium.ScreenSpaceEventType.MOUSE_MOVE, target, cartesian) | |||||
| } | } | ||||
| } | } | ||||
| * @Author: Caven | * @Author: Caven | ||||
| * @Date: 2020-01-02 14:26:35 | * @Date: 2020-01-02 14:26:35 | ||||
| * @Last Modified by: Caven | * @Last Modified by: Caven | ||||
| * @Last Modified time: 2020-01-19 10:22:10 | |||||
| * @Last Modified time: 2020-01-31 15:04:41 | |||||
| */ | */ | ||||
| import Cesium from '@/namespace' | import Cesium from '@/namespace' | ||||
| * @Author: Caven | * @Author: Caven | ||||
| * @Date: 2020-01-02 14:26:35 | * @Date: 2020-01-02 14:26:35 | ||||
| * @Last Modified by: Caven | * @Last Modified by: Caven | ||||
| * @Last Modified time: 2020-01-19 10:22:11 | |||||
| * @Last Modified time: 2020-01-31 15:04:41 | |||||
| */ | */ | ||||
| import Cesium from '@/namespace' | import Cesium from '@/namespace' | ||||
| * @Author: Caven | * @Author: Caven | ||||
| * @Date: 2020-01-15 20:31:28 | * @Date: 2020-01-15 20:31:28 | ||||
| * @Last Modified by: Caven | * @Last Modified by: Caven | ||||
| * @Last Modified time: 2020-01-21 16:12:42 | |||||
| * @Last Modified time: 2020-01-31 15:04:49 | |||||
| */ | */ | ||||
| import Cesium from '@/namespace' | import Cesium from '@/namespace' | 
| * @Author: Caven | * @Author: Caven | ||||
| * @Date: 2020-01-13 10:13:53 | * @Date: 2020-01-13 10:13:53 | ||||
| * @Last Modified by: Caven | * @Last Modified by: Caven | ||||
| * @Last Modified time: 2020-01-21 10:03:33 | |||||
| * @Last Modified time: 2020-01-31 15:05:07 | |||||
| */ | */ | ||||
| import Cesium from '../../namespace' | |||||
| import Cesium from '@/namespace' | |||||
| import Layer from './Layer' | import Layer from './Layer' | ||||
| DC.GeoJsonLayer = class extends Layer { | DC.GeoJsonLayer = class extends Layer { | ||||
| } | } | ||||
| } | } | ||||
| _createBillboard(entity) { | |||||
| if (entity.position && entity.billboard) { | |||||
| return DC.Billboard.fromEntity(entity) | |||||
| } | |||||
| } | |||||
| _createPolyline(entity) { | |||||
| if (entity.polyline) { | |||||
| return DC.Polyline.fromEntity(entity) | |||||
| } | |||||
| } | |||||
| _createPolygon(entity) { | |||||
| if (entity.polygon) { | |||||
| return DC.Polygon.fromEntity(entity) | |||||
| } | |||||
| } | |||||
| eachOverlay(method, context) { | eachOverlay(method, context) { | ||||
| if (this._delegate) { | if (this._delegate) { | ||||
| this._delegate.then(dataSource => { | this._delegate.then(dataSource => { | ||||
| }) | }) | ||||
| return layer | return layer | ||||
| } | } | ||||
| _createBillboard(entity) { | |||||
| if (entity.position && entity.billboard) { | |||||
| return DC.Billboard.fromEntity(entity) | |||||
| } | |||||
| } | |||||
| _createPolyline(entity) { | |||||
| if (entity.polyline) { | |||||
| return DC.Polyline.fromEntity(entity) | |||||
| } | |||||
| } | |||||
| _createPolygon(entity) { | |||||
| if (entity.polygon) { | |||||
| return DC.Polygon.fromEntity(entity) | |||||
| } | |||||
| } | |||||
| } | } | 
| * @Author: Caven | * @Author: Caven | ||||
| * @Date: 2020-01-09 09:16:27 | * @Date: 2020-01-09 09:16:27 | ||||
| * @Last Modified by: Caven | * @Last Modified by: Caven | ||||
| * @Last Modified time: 2020-01-19 10:18:54 | |||||
| * @Last Modified time: 2020-01-31 15:05:09 | |||||
| */ | */ | ||||
| import Cesium from '@/namespace' | import Cesium from '@/namespace' | ||||
| import Layer from './Layer' | import Layer from './Layer' | ||||
| /** | |||||
| * TilesetLayer is used to add various tileset | |||||
| */ | |||||
| DC.TilesetLayer = class extends Layer { | DC.TilesetLayer = class extends Layer { | ||||
| constructor(id) { | constructor(id) { | ||||
| super(id) | super(id) | 
| * @Author: Caven | * @Author: Caven | ||||
| * @Date: 2020-01-02 16:42:03 | * @Date: 2020-01-02 16:42:03 | ||||
| * @Last Modified by: Caven | * @Last Modified by: Caven | ||||
| * @Last Modified time: 2020-01-19 10:19:02 | |||||
| * @Last Modified time: 2020-01-31 15:05:19 | |||||
| */ | */ | ||||
| import Cesium from '@/namespace' | import Cesium from '@/namespace' | ||||
| import Layer from './Layer' | import Layer from './Layer' | ||||
| /** | |||||
| * The vector layer is used to add various enitity, which is essentially a CustomDataSource | |||||
| * that is used to place entities of the same class or business attribute into the same layer | |||||
| */ | |||||
| DC.VectorLayer = class extends Layer { | DC.VectorLayer = class extends Layer { | ||||
| constructor(id) { | constructor(id) { | ||||
| super(id) | super(id) | 
| * @Author: Caven | * @Author: Caven | ||||
| * @Date: 2020-01-03 09:38:21 | * @Date: 2020-01-03 09:38:21 | ||||
| * @Last Modified by: Caven | * @Last Modified by: Caven | ||||
| * @Last Modified time: 2020-01-19 10:19:08 | |||||
| * @Last Modified time: 2020-01-31 15:05:35 | |||||
| */ | */ | ||||
| import LayerEvent from '../event/LayerEvent' | import LayerEvent from '../event/LayerEvent' | ||||
| return this._state | return this._state | ||||
| } | } | ||||
| // 子类需要覆盖重写 | |||||
| /** | |||||
| * | |||||
| * @param {*} veiwer | |||||
| * the layer added callback function | |||||
| * subclasses need to be overridden | |||||
| */ | |||||
| _addCallback(veiwer) {} | _addCallback(veiwer) {} | ||||
| // 子类需要覆盖重写 | |||||
| /** | |||||
| * the layer removed callback function | |||||
| * subclasses need to be overridden | |||||
| */ | |||||
| _removeCallback() {} | _removeCallback() {} | ||||
| /** | |||||
| * | |||||
| * @param {*} overlay | |||||
| * the layer add overlay callback function | |||||
| */ | |||||
| _addOverlayCallback(overlay) { | _addOverlayCallback(overlay) { | ||||
| if (overlay && overlay.overlayEvent && overlay.state !== DC.OverlayState.ADDED) { | if (overlay && overlay.overlayEvent && overlay.state !== DC.OverlayState.ADDED) { | ||||
| overlay.overlayEvent.fire(DC.OverlayEventType.ADD, this) | overlay.overlayEvent.fire(DC.OverlayEventType.ADD, this) | ||||
| } | } | ||||
| } | } | ||||
| /** | |||||
| * | |||||
| * @param {*} overlay | |||||
| * the layer remove overlay callback function | |||||
| */ | |||||
| _removeOverlayCallback(overlay) { | _removeOverlayCallback(overlay) { | ||||
| if (overlay && overlay.overlayEvent && overlay.state !== DC.OverlayState.REMOVED) { | if (overlay && overlay.overlayEvent && overlay.state !== DC.OverlayState.REMOVED) { | ||||
| overlay.overlayEvent.fire(DC.OverlayEventType.REMOVE, this) | overlay.overlayEvent.fire(DC.OverlayEventType.REMOVE, this) | ||||
| } | } | ||||
| } | } | ||||
| /** | |||||
| * | |||||
| * @param {*} overlay | |||||
| * the layer add overlay | |||||
| */ | |||||
| addOverlay(overlay) { | addOverlay(overlay) { | ||||
| this._addOverlayCallback(overlay) | this._addOverlayCallback(overlay) | ||||
| return this | return this | ||||
| return this | return this | ||||
| } | } | ||||
| // 子类需要覆盖重写 | |||||
| clear() {} | clear() {} | ||||
| remove() { | remove() { | 
| * @Author: Caven | * @Author: Caven | ||||
| * @Date: 2020-01-03 11:06:26 | * @Date: 2020-01-03 11:06:26 | ||||
| * @Last Modified by: Caven | * @Last Modified by: Caven | ||||
| * @Last Modified time: 2020-01-19 10:19:08 | |||||
| * @Last Modified time: 2020-01-31 15:05:24 | |||||
| */ | */ | ||||
| import './DC.VectorLayer' | import './DC.VectorLayer' | ||||
| import './DC.TilesetLayer' | import './DC.TilesetLayer' | 
| * @Author: Caven | * @Author: Caven | ||||
| * @Date: 2020-01-21 15:33:52 | * @Date: 2020-01-21 15:33:52 | ||||
| * @Last Modified by: Caven | * @Last Modified by: Caven | ||||
| * @Last Modified time: 2020-01-21 17:17:26 | |||||
| * @Last Modified time: 2020-01-31 15:05:49 | |||||
| */ | */ | ||||
| import Cesium from '@/namespace' | import Cesium from '@/namespace' | ||||
| * @Author: Caven | * @Author: Caven | ||||
| * @Date: 2019-12-30 09:24:37 | * @Date: 2019-12-30 09:24:37 | ||||
| * @Last Modified by: Caven | * @Last Modified by: Caven | ||||
| * @Last Modified time: 2020-01-30 21:28:37 | |||||
| * @Last Modified time: 2020-01-31 15:05:52 | |||||
| */ | */ | ||||
| import Cesium from '@/namespace' | import Cesium from '@/namespace' | ||||
| _init() { | _init() { | ||||
| this._viewer.delegate._cesiumWidget._creditContainer.style.display = 'none' | this._viewer.delegate._cesiumWidget._creditContainer.style.display = 'none' | ||||
| this._viewer.delegate.scene.backgroundColor = Cesium.Color.TRANSPARENT | this._viewer.delegate.scene.backgroundColor = Cesium.Color.TRANSPARENT | ||||
| this._viewer.delegate.cesiumWidget.screenSpaceEventHandler.removeInputAction( | |||||
| Cesium.ScreenSpaceEventType.LEFT_DOUBLE_CLICK | |||||
| ) | |||||
| this._viewer.delegate.cesiumWidget.screenSpaceEventHandler.removeInputAction(Cesium.ScreenSpaceEventType.LEFT_DOUBLE_CLICK) | |||||
| } | } | ||||
| _setViewerOption(options) { | _setViewerOption(options) { | 
| * @Author: Caven | * @Author: Caven | ||||
| * @Date: 2020-01-03 12:18:17 | * @Date: 2020-01-03 12:18:17 | ||||
| * @Last Modified by: Caven | * @Last Modified by: Caven | ||||
| * @Last Modified time: 2020-01-21 10:17:17 | |||||
| * @Last Modified time: 2020-01-31 15:06:56 | |||||
| */ | */ | ||||
| import OverlayEvent from '../event/OverlayEvent' | import OverlayEvent from '../event/OverlayEvent' | ||||
| class Overlay { | class Overlay { | 
| * @Author: Caven | * @Author: Caven | ||||
| * @Date: 2020-01-19 10:18:23 | * @Date: 2020-01-19 10:18:23 | ||||
| * @Last Modified by: Caven | * @Last Modified by: Caven | ||||
| * @Last Modified time: 2020-01-21 10:18:28 | |||||
| * @Last Modified time: 2020-01-31 15:06:03 | |||||
| */ | */ | ||||
| import Cesium from '@/namespace' | import Cesium from '@/namespace' | ||||
| if (!position || !(position instanceof DC.Position)) { | if (!position || !(position instanceof DC.Position)) { | ||||
| throw new Error('the position invalid') | throw new Error('the position invalid') | ||||
| } | } | ||||
| super() | |||||
| this._position = position | this._position = position | ||||
| this._icon = icon | this._icon = icon | ||||
| this._size = [32, 32] | this._size = [32, 32] | ||||
| } | } | ||||
| _prepareDelegate() { | _prepareDelegate() { | ||||
| // 设置位置 | |||||
| /** | |||||
| * set the location | |||||
| */ | |||||
| this._delegate.position = new Cesium.CallbackProperty(time => { | this._delegate.position = new Cesium.CallbackProperty(time => { | ||||
| return DC.T.transformWSG84ToCartesian(this._position) | return DC.T.transformWSG84ToCartesian(this._position) | ||||
| }) | }) | ||||
| // 设置朝向 | |||||
| /** | |||||
| * set the orientation | |||||
| */ | |||||
| this._delegate.orientation = new Cesium.CallbackProperty(time => { | this._delegate.orientation = new Cesium.CallbackProperty(time => { | ||||
| return Cesium.Transforms.headingPitchRollQuaternion( | return Cesium.Transforms.headingPitchRollQuaternion( | ||||
| DC.T.transformWSG84ToCartesian(this._position), | DC.T.transformWSG84ToCartesian(this._position), | ||||
| ) | ) | ||||
| ) | ) | ||||
| }) | }) | ||||
| // 初始化Overlay参数 | |||||
| /** | |||||
| * initialize the Overlay parameter | |||||
| */ | |||||
| this._delegate.billboard = { | this._delegate.billboard = { | ||||
| ...this._style, | ...this._style, | ||||
| image: new Cesium.CallbackProperty(time => { | image: new Cesium.CallbackProperty(time => { | 
| * @Author: Caven | * @Author: Caven | ||||
| * @Date: 2020-01-06 15:03:25 | * @Date: 2020-01-06 15:03:25 | ||||
| * @Last Modified by: Caven | * @Last Modified by: Caven | ||||
| * @Last Modified time: 2020-01-21 10:17:55 | |||||
| * @Last Modified time: 2020-01-31 15:06:13 | |||||
| */ | */ | ||||
| import Cesium from '@/namespace' | import Cesium from '@/namespace' | ||||
| const DEF_STYLE = { | const DEF_STYLE = { | ||||
| pixelSize: 8, | pixelSize: 8, | ||||
| outlineColor: DC.Color.BLUE, | |||||
| outlineColor: Cesium.Color.BLUE, | |||||
| outlineWidth: 2 | outlineWidth: 2 | ||||
| } | } | ||||
| } | } | ||||
| _prepareDelegate() { | _prepareDelegate() { | ||||
| // 设置位置 | |||||
| /** | |||||
| * set the location | |||||
| */ | |||||
| this._delegate.position = new Cesium.CallbackProperty(time => { | this._delegate.position = new Cesium.CallbackProperty(time => { | ||||
| return DC.T.transformWSG84ToCartesian(this._position) | return DC.T.transformWSG84ToCartesian(this._position) | ||||
| }) | }) | ||||
| // 设置朝向 | |||||
| /** | |||||
| * set the orientation | |||||
| */ | |||||
| this._delegate.orientation = new Cesium.CallbackProperty(time => { | this._delegate.orientation = new Cesium.CallbackProperty(time => { | ||||
| return Cesium.Transforms.headingPitchRollQuaternion( | return Cesium.Transforms.headingPitchRollQuaternion( | ||||
| DC.T.transformWSG84ToCartesian(this._position), | DC.T.transformWSG84ToCartesian(this._position), | ||||
| ) | ) | ||||
| ) | ) | ||||
| }) | }) | ||||
| // 初始化Overlay参数 | |||||
| /** | |||||
| * initialize the Overlay parameter | |||||
| */ | |||||
| this._delegate.point = { | this._delegate.point = { | ||||
| ...DEF_STYLE, | ...DEF_STYLE, | ||||
| ...this._style | ...this._style | 
| * @Author: Caven | * @Author: Caven | ||||
| * @Date: 2020-01-09 09:10:37 | * @Date: 2020-01-09 09:10:37 | ||||
| * @Last Modified by: Caven | * @Last Modified by: Caven | ||||
| * @Last Modified time: 2020-01-21 10:19:13 | |||||
| * @Last Modified time: 2020-01-31 15:06:25 | |||||
| */ | */ | ||||
| import Overlay from '../Overlay' | import Overlay from '../Overlay' | ||||
| import Cesium from '@/namespace' | import Cesium from '@/namespace' | ||||
| } | } | ||||
| _prepareDelegate() { | _prepareDelegate() { | ||||
| // 初始化Overlay参数 | |||||
| /** | |||||
| * initialize the Overlay parameter | |||||
| */ | |||||
| this._delegate.polygon = { | this._delegate.polygon = { | ||||
| ...this._style, | ...this._style, | ||||
| hierarchy: new Cesium.CallbackProperty(time => { | hierarchy: new Cesium.CallbackProperty(time => { | 
| * @Author: Caven | * @Author: Caven | ||||
| * @Date: 2020-01-06 15:03:25 | * @Date: 2020-01-06 15:03:25 | ||||
| * @Last Modified by: Caven | * @Last Modified by: Caven | ||||
| * @Last Modified time: 2020-01-21 10:22:39 | |||||
| * @Last Modified time: 2020-01-31 15:06:25 | |||||
| */ | */ | ||||
| import Overlay from '../Overlay' | import Overlay from '../Overlay' | ||||
| } | } | ||||
| _prepareDelegate() { | _prepareDelegate() { | ||||
| // 初始化Overlay参数 | |||||
| /** | |||||
| * initialize the Overlay parameter | |||||
| */ | |||||
| this._delegate.polyline = { | this._delegate.polyline = { | ||||
| ...this._style, | ...this._style, | ||||
| positions: new Cesium.CallbackProperty(time => { | positions: new Cesium.CallbackProperty(time => { | 
| * @Author: Caven | * @Author: Caven | ||||
| * @Date: 2020-01-06 15:04:15 | * @Date: 2020-01-06 15:04:15 | ||||
| * @Last Modified by: Caven | * @Last Modified by: Caven | ||||
| * @Last Modified time: 2020-01-15 14:11:35 | |||||
| * @Last Modified time: 2020-01-31 15:06:48 | |||||
| */ | */ | ||||
| import './base/DC.Point' | import './base/DC.Point' | 
| * @Author: Caven | * @Author: Caven | ||||
| * @Date: 2020-01-06 15:03:25 | * @Date: 2020-01-06 15:03:25 | ||||
| * @Last Modified by: Caven | * @Last Modified by: Caven | ||||
| * @Last Modified time: 2020-01-21 10:19:38 | |||||
| * @Last Modified time: 2020-01-31 15:06:39 | |||||
| */ | */ | ||||
| import Overlay from '../Overlay' | import Overlay from '../Overlay' | 
| * @Author: Caven | * @Author: Caven | ||||
| * @Date: 2020-01-07 08:51:56 | * @Date: 2020-01-07 08:51:56 | ||||
| * @Last Modified by: Caven | * @Last Modified by: Caven | ||||
| * @Last Modified time: 2020-01-21 10:23:23 | |||||
| * @Last Modified time: 2020-01-31 15:06:39 | |||||
| */ | */ | ||||
| import Cesium from '@/namespace' | import Cesium from '@/namespace' | ||||
| import Overlay from '../Overlay' | import Overlay from '../Overlay' | 
| * @Author: Caven | * @Author: Caven | ||||
| * @Date: 2019-12-27 14:35:02 | * @Date: 2019-12-27 14:35:02 | ||||
| * @Last Modified by: Caven | * @Last Modified by: Caven | ||||
| * @Last Modified time: 2020-01-15 13:02:26 | |||||
| * @Last Modified time: 2020-01-31 15:07:00 | |||||
| */ | */ | ||||
| DC.Position = class { | DC.Position = class { | ||||
| } | } | ||||
| serialize() { | 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) | return JSON.stringify(position) | ||||
| } | } | ||||
| /* | |||||
| * @Author: Caven | |||||
| * @Date: 2019-12-30 09:24:37 | |||||
| * @Last Modified by: Caven | |||||
| * @Last Modified time: 2020-01-19 10:19:53 | |||||
| */ | |||||
| import Cesium from '@/namespace' | |||||
| class ViewerStyle { | |||||
| constructor(viewer) { | |||||
| this._viewer = viewer | |||||
| this._init() | |||||
| } | |||||
| _init() { | |||||
| this._viewer.delegate._cesiumWidget._creditContainer.style.display = 'none' | |||||
| this._viewer.delegate.scene.backgroundColor = Cesium.Color.TRANSPARENT | |||||
| this._viewer.delegate.cesiumWidget.screenSpaceEventHandler.removeInputAction(Cesium.ScreenSpaceEventType.LEFT_DOUBLE_CLICK) | |||||
| } | |||||
| _setViewerStyle(option) { | |||||
| this._viewer.delegate.shadows = Cesium.defaultValue(option.shadows, false) | |||||
| } | |||||
| _setCanvasStyle(option) {} | |||||
| _setSceneStyle(option) {} | |||||
| _setGlobeStyle(option) {} | |||||
| _setClockStyle(option) { | |||||
| this._viewer.delegate.clock.shouldAnimate = Cesium.defaultValue(option.shouldAnimate, false) | |||||
| } | |||||
| setOption(option) { | |||||
| this._setViewerStyle(option) //设置viewer样式 | |||||
| ._setCanvasStyle(option) //设置画布样式 | |||||
| ._setSceneStyle(option) //设置场景样式 | |||||
| ._setGlobeStyle(option) //设置地球样式 | |||||
| ._setClockStyle(option) //设置事件样式 | |||||
| return this | |||||
| } | |||||
| } | |||||
| export default ViewerStyle | 
| /* | |||||
| * @Author: Caven | |||||
| * @Date: 2020-01-15 20:31:28 | |||||
| * @Last Modified by: Caven | |||||
| * @Last Modified time: 2020-01-15 20:33:05 | |||||
| */ | 
| /* | |||||
| * @Author: Caven | |||||
| * @Date: 2020-01-15 20:27:27 | |||||
| * @Last Modified by: Caven | |||||
| * @Last Modified time: 2020-01-15 20:27:27 | |||||
| */ | 
| /* | |||||
| * @Author: Caven | |||||
| * @Date: 2020-01-15 20:31:46 | |||||
| * @Last Modified by: Caven | |||||
| * @Last Modified time: 2020-01-15 20:31:46 | |||||
| */ | 
| * @Author: Caven | * @Author: Caven | ||||
| * @Date: 2020-01-07 09:00:32 | * @Date: 2020-01-07 09:00:32 | ||||
| * @Last Modified by: Caven | * @Last Modified by: Caven | ||||
| * @Last Modified time: 2020-01-19 10:20:45 | |||||
| * @Last Modified time: 2020-01-31 15:07:55 | |||||
| */ | */ | ||||
| import Cesium from '@/namespace' | import Cesium from '@/namespace' | ||||
| * @Author: Caven | * @Author: Caven | ||||
| * @Date: 2019-12-31 17:50:13 | * @Date: 2019-12-31 17:50:13 | ||||
| * @Last Modified by: Caven | * @Last Modified by: Caven | ||||
| * @Last Modified time: 2020-01-15 13:03:13 | |||||
| * @Last Modified time: 2020-01-31 15:07:59 | |||||
| */ | */ | ||||
| /** | /** | ||||
| if (el.classList !== undefined) { | if (el.classList !== undefined) { | ||||
| el.classList.remove(name) | el.classList.remove(name) | ||||
| } else { | } else { | ||||
| this.setClass( | |||||
| el, | |||||
| DC.Util.trim( | |||||
| (' ' + this.getClass(el) + ' ').replace(' ' + name + ' ', ' ') | |||||
| ) | |||||
| ) | |||||
| this.setClass(el, DC.Util.trim((' ' + this.getClass(el) + ' ').replace(' ' + name + ' ', ' '))) | |||||
| } | } | ||||
| } | } | ||||
| if (el.correspondingElement) { | if (el.correspondingElement) { | ||||
| el = el.correspondingElement | el = el.correspondingElement | ||||
| } | } | ||||
| return el.className.baseVal === undefined | |||||
| ? el.className | |||||
| : el.className.baseVal | |||||
| return el.className.baseVal === undefined ? el.className : el.className.baseVal | |||||
| } | } | ||||
| } | } | 
| * @Author: Caven | * @Author: Caven | ||||
| * @Date: 2019-12-31 17:58:01 | * @Date: 2019-12-31 17:58:01 | ||||
| * @Last Modified by: Caven | * @Last Modified by: Caven | ||||
| * @Last Modified time: 2020-01-15 13:03:22 | |||||
| * @Last Modified time: 2020-01-31 15:08:11 | |||||
| */ | */ | ||||
| const CHARS = '0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz'.split( | |||||
| '' | |||||
| ) | |||||
| const CHARS = '0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz'.split('') | |||||
| /** | /** | ||||
| * 工具类 | * 工具类 | ||||
| * 部分代码借鉴leaflet | * 部分代码借鉴leaflet | 
| * @Author: Caven | * @Author: Caven | ||||
| * @Date: 2020-01-06 16:38:49 | * @Date: 2020-01-06 16:38:49 | ||||
| * @Last Modified by: Caven | * @Last Modified by: Caven | ||||
| * @Last Modified time: 2020-01-15 13:03:30 | |||||
| * @Last Modified time: 2020-01-31 15:08:17 | |||||
| */ | */ | ||||
| import './DC.Util' | import './DC.Util' | ||||
| import './DC.DomUtil' | import './DC.DomUtil' | 
| * @Author: Caven | * @Author: Caven | ||||
| * @Date: 2019-12-27 17:13:24 | * @Date: 2019-12-27 17:13:24 | ||||
| * @Last Modified by: Caven | * @Last Modified by: Caven | ||||
| * @Last Modified time: 2020-01-19 10:34:16 | |||||
| * @Last Modified time: 2020-01-31 15:09:00 | |||||
| */ | */ | ||||
| import Cesium from '@/namespace' | import Cesium from '@/namespace' | ||||
| import ViewerStyle from '../style/ViewerStyle' | |||||
| import ViewerOption from '../option/ViewerOption' | |||||
| import CameraOption from '../option/CameraOption' | |||||
| import MouseEvent from '../event/MouseEvent' | import MouseEvent from '../event/MouseEvent' | ||||
| import ViewerEvent from '../event/ViewerEvent' | import ViewerEvent from '../event/ViewerEvent' | ||||
| import Popup from '../widget/Popup' | import Popup from '../widget/Popup' | ||||
| import ContextMenu from '../widget/ContextMenu' | import ContextMenu from '../widget/ContextMenu' | ||||
| const DEF_OPTS = { | const DEF_OPTS = { | ||||
| animation: false, //是否创建动画小器件,左下角仪表 | |||||
| baseLayerPicker: false, //是否显示图层选择器 | |||||
| fullscreenButton: false, //是否显示全屏按钮 | |||||
| geocoder: false, //是否显示geocoder小器件,右上角查询按钮 | |||||
| homeButton: false, //是否显示Home按钮 | |||||
| infoBox: false, //是否显示信息框 | |||||
| sceneModePicker: false, //是否显示3D/2D选择器 | |||||
| selectionIndicator: false, //是否显示选取指示器组件 | |||||
| timeline: false, //是否显示时间轴 | |||||
| navigationHelpButton: false, //是否显示右上角的帮助按钮 | |||||
| navigationInstructionsInitiallyVisible: false | |||||
| animation: false, //Whether to create animated widgets, lower left corner of the meter | |||||
| baseLayerPicker: false, //Whether to display the layer selector | |||||
| fullscreenButton: false, //Whether to display the full-screen button | |||||
| geocoder: false, //To display the geocoder widget, query the button in the upper right corner | |||||
| homeButton: false, //Whether to display the Home button | |||||
| infoBox: false, //Whether to display the information box | |||||
| sceneModePicker: false, //Whether to display 3D/2D selector | |||||
| selectionIndicator: false, //Whether to display the selection indicator component | |||||
| timeline: false, //Whether to display the timeline | |||||
| navigationHelpButton: false, //Whether to display the help button in the upper right corner | |||||
| navigationInstructionsInitiallyVisible: false, | |||||
| creditContainer: undefined, | |||||
| shouldAnimate: true | |||||
| } | } | ||||
| DC.Viewer = class { | DC.Viewer = class { | ||||
| constructor(id, options = {}) { | constructor(id, options = {}) { | ||||
| if (!id) { | |||||
| if (!id || !document.getElementById(id)) { | |||||
| throw Error('the id empty') | throw Error('the id empty') | ||||
| } | } | ||||
| this._delegate = new Cesium.Viewer(id, { | this._delegate = new Cesium.Viewer(id, { | ||||
| ...options, | ...options, | ||||
| ...DEF_OPTS | ...DEF_OPTS | ||||
| }) // 初始化 viewer | |||||
| new MouseEvent(this) // 注册全局鼠标事件 | |||||
| this._style = new ViewerStyle(this) // 设置viewer样式 | |||||
| this._viewerEvent = new ViewerEvent() //注册viewer事件 | |||||
| this._dcContainer = DC.DomUtil.create('div', 'dc-container', document.getElementById(id)) //添加自定义容器 | |||||
| }) // Initialize the viewer | |||||
| new MouseEvent(this) // Register global mouse events | |||||
| 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._layerCache = {} | this._layerCache = {} | ||||
| this.on(DC.ViewerEventType.ADD_IMAGERY_LAYER, this._addImageryLayerCallback, this) | |||||
| this.on(DC.ViewerEventType.CHANGE_IMAGERY_LAYER, this._changeImageryLayerCallback, this) | |||||
| this.on(DC.ViewerEventType.ADD_LAYER, this._addLayerCallback, this) //添加图层事件监听 | |||||
| this.on(DC.ViewerEventType.REMOVE_LAYER, this._removeLayerCallback, this) //移除图层事件监听 | |||||
| this.on(DC.ViewerEventType.ADD_EFFECT, this._addEffectCallback, this) //添加效果事件监听 | |||||
| this.on(DC.ViewerEventType.REMOVE_EFFECT, this._removeEffectCallback, this) //移除效果事件监听 | |||||
| //添加默认组件 | |||||
| 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 | |||||
| this.on(DC.ViewerEventType.ADD_EFFECT, this._addEffectCallback, this) //Initialize effect add event | |||||
| this.on(DC.ViewerEventType.REMOVE_EFFECT, this._removeEffectCallback, this) //Initialize effect remove event | |||||
| /** | |||||
| * Add default components | |||||
| */ | |||||
| this._popup = new Popup() | this._popup = new Popup() | ||||
| this._contextMenu = new ContextMenu() | this._contextMenu = new ContextMenu() | ||||
| this.use(this._popup).use(this._contextMenu) | this.use(this._popup).use(this._contextMenu) | ||||
| return this._contextMenu | return this._contextMenu | ||||
| } | } | ||||
| _addImageryLayerCallback(imagerLayer) {} | |||||
| _changeImageryLayerCallback(index) {} | |||||
| _addLayerCallback(layer) { | _addLayerCallback(layer) { | ||||
| if (layer && layer.layerEvent && layer.state !== DC.LayerState.ADDED) { | if (layer && layer.layerEvent && layer.state !== DC.LayerState.ADDED) { | ||||
| !this._layerCache[layer.type] && (this._layerCache[layer.type] = {}) | !this._layerCache[layer.type] && (this._layerCache[layer.type] = {}) | ||||
| _removeEffectCallback(effect) {} | _removeEffectCallback(effect) {} | ||||
| setStyle(style = {}) {} | |||||
| /** | |||||
| * | |||||
| * @param {*} options | |||||
| * set viewer options | |||||
| * | |||||
| */ | |||||
| setOptions(options) { | |||||
| this._viewerOption.setOptions(options) | |||||
| return this | |||||
| } | |||||
| /** | |||||
| * | |||||
| * @param {*} min | |||||
| * @param {*} max | |||||
| * set camera options | |||||
| */ | |||||
| setPitchRange(min = -90, max = -20) { | |||||
| this._cameraOption.setPichRange(min, max) | |||||
| return this | |||||
| } | |||||
| /** | |||||
| * Restrict camera access underground | |||||
| */ | |||||
| limitCameraToGround() { | |||||
| this._cameraOption.limitCameraToGround() | |||||
| return this | |||||
| } | |||||
| /** | |||||
| * | |||||
| * @param {*} baseLayers | |||||
| * Add the baselayer to the viewer. | |||||
| * The baselayer can be a single or an array, | |||||
| * and when the baselayer is an array, the baselayer will be loaded together | |||||
| */ | |||||
| addBaseLayer(baseLayers) { | |||||
| if (!baseLayers) { | |||||
| return this | |||||
| } | |||||
| if (!Array.isArray(baseLayers)) { | |||||
| baseLayers = [baseLayers] | |||||
| } | |||||
| baseLayers.forEach(item => { | |||||
| if ( | |||||
| item instanceof Cesium.UrlTemplateImageryProvider || | |||||
| item instanceof Cesium.ArcGisMapServerImageryProvider || | |||||
| item instanceof Cesium.SingleTileImageryProvider || | |||||
| item instanceof Cesium.WebMapTileServiceImageryProvider | |||||
| ) { | |||||
| this._baseLayerPicker.imageryProviderViewModels.push( | |||||
| new Cesium.ProviderViewModel({ | |||||
| name: '地图', | |||||
| creationFunction: () => { | |||||
| return item | |||||
| } | |||||
| }) | |||||
| ) | |||||
| } | |||||
| }) | |||||
| if (!this._baseLayerPicker.selectedImagery) { | |||||
| this._baseLayerPicker.selectedImagery = this._baseLayerPicker.imageryProviderViewModels[0] | |||||
| } | |||||
| return this | |||||
| } | |||||
| /** | |||||
| * | |||||
| * @param {*} index | |||||
| * Change the current globe display of the baselayer | |||||
| */ | |||||
| changeBaseLayer(index) { | |||||
| if (this._baseLayerPicker && index >= 0) { | |||||
| this._baseLayerPicker.selectedImagery = this._baseLayerPicker.imageryProviderViewModels[index] | |||||
| } | |||||
| return this | |||||
| } | |||||
| /** | |||||
| * | |||||
| * @param {*} layer | |||||
| * Add a layer to the viewer | |||||
| */ | |||||
| addLayer(layer) { | addLayer(layer) { | ||||
| this._viewerEvent.fire(DC.ViewerEventType.ADD_LAYER, layer) | this._viewerEvent.fire(DC.ViewerEventType.ADD_LAYER, layer) | ||||
| return this | return this | ||||
| } | } | ||||
| /** | |||||
| * | |||||
| * @param {*} layer | |||||
| * remove a layer from the viewer | |||||
| */ | |||||
| removeLayer(layer) { | removeLayer(layer) { | ||||
| this._viewerEvent.fire(DC.ViewerEventType.ADD_LAYER, layer) | this._viewerEvent.fire(DC.ViewerEventType.ADD_LAYER, layer) | ||||
| return this | return this | ||||
| } | } | ||||
| /** | |||||
| * | |||||
| * @param {*} id | |||||
| * get the layer by id | |||||
| */ | |||||
| getLayer(id) { | getLayer(id) { | ||||
| let layer = undefined | let layer = undefined | ||||
| for (let type in this._layerCache) { | for (let type in this._layerCache) { | ||||
| return layer | return layer | ||||
| } | } | ||||
| /** | |||||
| * get all layers | |||||
| */ | |||||
| getLayers() { | |||||
| let result = [] | |||||
| for (let type in this._layerCache) { | |||||
| let cache = this._layerCache[type] | |||||
| for (let layerId in cache) { | |||||
| result.push(cache[layerId]) | |||||
| } | |||||
| } | |||||
| return result | |||||
| } | |||||
| /** | |||||
| * | |||||
| * @param {*} method | |||||
| * @param {*} context | |||||
| * | |||||
| */ | |||||
| eachLayer(method, context) { | eachLayer(method, context) { | ||||
| for (let type in this._layerCache) { | for (let type in this._layerCache) { | ||||
| let cache = this._layerCache[type] | let cache = this._layerCache[type] | ||||
| method.call(context, cache[layerId]) | method.call(context, cache[layerId]) | ||||
| } | } | ||||
| } | } | ||||
| return this | |||||
| } | } | ||||
| addEffect(effect) {} | addEffect(effect) {} | ||||
| flyToPosition(position, completeCallback) { | flyToPosition(position, completeCallback) { | ||||
| if (position instanceof DC.Position) { | if (position instanceof DC.Position) { | ||||
| this._delegate.flyTo({ | |||||
| this._delegate.camera.flyTo({ | |||||
| destination: DC.T.transformWSG84ToCartesian(position), | destination: DC.T.transformWSG84ToCartesian(position), | ||||
| orientation: { | orientation: { | ||||
| heading: Cesium.Math.toRadians(position.heading), | heading: Cesium.Math.toRadians(position.heading), | ||||
| } | } | ||||
| on(type, callback, context) { | on(type, callback, context) { | ||||
| this._viewerEvent.on(type, callback, context) | |||||
| this._viewerEvent.on(type, callback, context || this) | |||||
| return this | return this | ||||
| } | } | ||||
| off(type, callback, context) { | off(type, callback, context) { | ||||
| this._viewerEvent.off(type, callback, context) | |||||
| this._viewerEvent.off(type, callback, context || this) | |||||
| return this | return this | ||||
| } | } | ||||
| * @Author: Caven | * @Author: Caven | ||||
| * @Date: 2019-12-31 17:32:01 | * @Date: 2019-12-31 17:32:01 | ||||
| * @Last Modified by: Caven | * @Last Modified by: Caven | ||||
| * @Last Modified time: 2020-01-15 20:23:08 | |||||
| * @Last Modified time: 2020-01-31 15:09:03 | |||||
| */ | */ | ||||
| import Widget from './Widget' | import Widget from './Widget' | 
| * @Author: Caven | * @Author: Caven | ||||
| * @Date: 2020-01-15 19:16:45 | * @Date: 2020-01-15 19:16:45 | ||||
| * @Last Modified by: Caven | * @Last Modified by: Caven | ||||
| * @Last Modified time: 2020-01-15 20:33:37 | |||||
| * @Last Modified time: 2020-01-31 15:09:12 | |||||
| */ | */ | ||||
| class Popup { | class Popup { | ||||
| constructor() { | constructor() { | ||||
| _setWindowCoord(windowCoord) {} | _setWindowCoord(windowCoord) {} | ||||
| } | } | ||||
| export default Popup | 
| * @Author: Caven | * @Author: Caven | ||||
| * @Date: 2020-01-15 19:17:52 | * @Date: 2020-01-15 19:17:52 | ||||
| * @Last Modified by: Caven | * @Last Modified by: Caven | ||||
| <<<<<<< HEAD | |||||
| * @Last Modified time: 2020-01-15 20:14:22 | * @Last Modified time: 2020-01-15 20:14:22 | ||||
| */ | */ | ||||
| ======= | |||||
| * @Last Modified time: 2020-01-21 12:13:45 | |||||
| */ | |||||
| import Cesium from '@/namespace' | |||||
| >>>>>>> 816784032383a4443bfb8de96a7b70447d385628 | |||||
| class Widget { | class Widget { | ||||
| constructor() { | constructor() { | ||||
| this._viewer = undefined | this._viewer = undefined | ||||
| if (this._viewer) { | if (this._viewer) { | ||||
| let self = this | let self = this | ||||
| let scene = this._viewer.scene | let scene = this._viewer.scene | ||||
| <<<<<<< HEAD | |||||
| scene.preRender.addEventListener(() => { | scene.preRender.addEventListener(() => { | ||||
| let windowCoord = Cesium.SceneTransforms.wgs84ToWindowCoordinates( | let windowCoord = Cesium.SceneTransforms.wgs84ToWindowCoordinates( | ||||
| scene, | scene, | ||||
| self._position | self._position | ||||
| ) | ) | ||||
| ======= | |||||
| scene.postRender.addEventListener(() => { | |||||
| let windowCoord = Cesium.SceneTransforms.wgs84ToWindowCoordinates(scene, self._position) | |||||
| >>>>>>> 816784032383a4443bfb8de96a7b70447d385628 | |||||
| this._setWindowCoord(windowCoord) | this._setWindowCoord(windowCoord) | ||||
| }) | }) | ||||
| } | } | 
| * @Author: Caven | * @Author: Caven | ||||
| * @Date: 2020-01-15 19:29:58 | * @Date: 2020-01-15 19:29:58 | ||||
| * @Last Modified by: Caven | * @Last Modified by: Caven | ||||
| * @Last Modified time: 2020-01-15 19:30:19 | |||||
| * @Last Modified time: 2020-01-31 15:09:07 | |||||
| */ | */ | ||||
| import './ContextMenu' | import './ContextMenu' | ||||
| import './Popup' | import './Popup' | 
| * @Author: Caven | * @Author: Caven | ||||
| * @Date: 2020-01-14 18:24:57 | * @Date: 2020-01-14 18:24:57 | ||||
| * @Last Modified by: Caven | * @Last Modified by: Caven | ||||
| * @Last Modified time: 2020-01-18 18:19:19 | |||||
| * @Last Modified time: 2020-01-31 15:09:50 | |||||
| */ | */ | ||||
| import './animation/DC.GlobeRotate' | |||||
| import './roaming/DC.Roaming' | 
| * @Author: Caven | * @Author: Caven | ||||
| * @Date: 2020-01-14 18:22:10 | * @Date: 2020-01-14 18:22:10 | ||||
| * @Last Modified by: Caven | * @Last Modified by: Caven | ||||
| * @Last Modified time: 2020-01-15 13:05:34 | |||||
| * @Last Modified time: 2020-01-31 15:09:47 | |||||
| */ | */ | ||||
| ;(function() { | ;(function() { | ||||
| let initialized = false | |||||
| if (!DC) { | if (!DC) { | ||||
| throw new Error('missing dc sdk') | throw new Error('missing dc sdk') | ||||
| } | } | ||||
| require('./DC.Pulgins.Loader') | |||||
| DC.init(() => { | |||||
| !initialized && require('./DC.Pulgins.Loader') | |||||
| initialized = true | |||||
| }) | |||||
| })() | })() | 
| * @Author: Caven | * @Author: Caven | ||||
| * @Date: 2020-01-19 11:21:48 | * @Date: 2020-01-19 11:21:48 | ||||
| * @Last Modified by: Caven | * @Last Modified by: Caven | ||||
| * @Last Modified time: 2020-01-19 14:59:26 | |||||
| * @Last Modified time: 2020-01-31 15:09:56 | |||||
| */ | */ | ||||
| import Cesium from '@/namespace' | import Cesium from '@/namespace' | ||||
| const DEF_PAHT_STYLE = { | |||||
| resolution: 1, | |||||
| material: new Cesium.PolylineGlowMaterialProperty({ | |||||
| glowPower: 0.1, | |||||
| color: Cesium.Color.YELLOW | |||||
| }), | |||||
| width: 10 | |||||
| } | |||||
| DC.Roaming = class { | DC.Roaming = class { | ||||
| constructor(options) { | |||||
| this._viewer = undefined | |||||
| constructor(viewer, options) { | |||||
| this._viewer = viewer | |||||
| this._positions = [] | this._positions = [] | ||||
| this._time = Cesium.defaultValue(option.time, 360) | |||||
| this._modelPath = options.modelPath | |||||
| this._modelScale = options.modelScale || 1 | |||||
| this._modelShow = options.modelShow || true | |||||
| this._time = options.time || 360 | |||||
| this._startTime = undefined | |||||
| this._endTime = undefined | |||||
| this._showPath = options.showPath || false | |||||
| this._delegate = new Cesium.Entity() | |||||
| this._perspective = options.perspective || 0 | |||||
| this._parsePositions(options.positions) | |||||
| } | } | ||||
| setPostions(postions) {} | |||||
| /** | |||||
| * | |||||
| * @param {*} positions | |||||
| */ | |||||
| _parsePositions(positions) { | |||||
| if (typeof positions === 'string') { | |||||
| if (positions.indexOf('#') >= 0) { | |||||
| throw new Error('the positions invalid') | |||||
| } | |||||
| positions = positions.split(';') | |||||
| } | |||||
| this._positions = positions.map(item => { | |||||
| if (Array.isArray(item)) { | |||||
| return DC.Position.fromCoordArray(item) | |||||
| } else { | |||||
| return DC.Position.fromCoordString(item) | |||||
| } | |||||
| }) | |||||
| } | |||||
| addToViewer(viewer) { | |||||
| this._viewer = viewer | |||||
| _preparePositionProperty() { | |||||
| var property = new Cesium.SampledPositionProperty() | |||||
| if (this._positions.length) { | |||||
| let timeInterval = this._time - (this._time % this._positions.length) | |||||
| this._startTime = Cesium.JulianDate.now() | |||||
| let increment = timeInterval / this._positions.length | |||||
| this._endTime = Cesium.JulianDate.addSeconds(this._startTime, timeInterval, new Cesium.JulianDate()) | |||||
| this._positions.forEach((item, index) => { | |||||
| let time = Cesium.JulianDate.addSeconds(this._startTime, index * increment, new Cesium.JulianDate()) | |||||
| property.addSample(time, DC.T.transformWSG84ToCartesian(item)) | |||||
| }) | |||||
| } | |||||
| return property | |||||
| } | |||||
| _prepareDelegate() { | |||||
| let property = this._preparePositionProperty() | |||||
| this._delegate.merge({ | |||||
| position: property, | |||||
| orientation: new Cesium.VelocityOrientationProperty(property), | |||||
| model: { | |||||
| uri: this._modelPath, | |||||
| scale: this._modelScale, | |||||
| show: this._modelShow | |||||
| }, | |||||
| path: { | |||||
| ...DEF_PAHT_STYLE, | |||||
| show: this._showPath | |||||
| } | |||||
| }) | |||||
| if (this._startTime && this._endTime) { | |||||
| this._delegate.availability = new Cesium.TimeIntervalCollection([ | |||||
| new Cesium.TimeInterval({ | |||||
| start: this._startTime, | |||||
| stop: this._endTime | |||||
| }) | |||||
| ]) | |||||
| } | |||||
| this._delegate.position.setInterpolationOptions({ | |||||
| interpolationDegree: 5, | |||||
| interpolationAlgorithm: Cesium.LagrangePolynomialApproximation | |||||
| }) | |||||
| } | |||||
| _setClock() { | |||||
| this._viewer.delegate.clock.startTime = this._startTime.clone() | |||||
| this._viewer.delegate.clock.stopTime = this._endTime.clone() | |||||
| this._viewer.delegate.clock.currentTime = this._startTime.clone() | |||||
| this._viewer.delegate.clock.clockRange = Cesium.ClockRange.UNBOUNDED | |||||
| } | |||||
| /** | |||||
| * | |||||
| * @param {*} speed | |||||
| */ | |||||
| setSpeed(speed) { | |||||
| this._viewer.delegate.clock.multiplier = speed | |||||
| } | |||||
| /** | |||||
| * | |||||
| * @param {*} perspective | |||||
| */ | |||||
| setPerspective(perspective) { | |||||
| this._perspective = perspective | |||||
| if (this._delegate.model) { | |||||
| if (perspective === 0) { | |||||
| this._viewer.delegate.trackedEntity = this._delegate | |||||
| } else if (perspective === 1) { | |||||
| this._viewer.delegate.trackedEntity = undefined | |||||
| this._viewer.delegate.zoomTo(this._delegate, new Cesium.HeadingPitchRange(0, Cesium.Math.toRadians(-90))) | |||||
| } | |||||
| } | |||||
| } | |||||
| reset() { | |||||
| this._prepareDelegate() | |||||
| this._setClock() | |||||
| this._viewer.delegate.clock.multiplier = 1 | |||||
| } | |||||
| start() { | |||||
| this._viewer.delegate.entities.remove(this._delegate) | |||||
| this._prepareDelegate() | |||||
| this._setClock() | |||||
| this._viewer.delegate.entities.add(this._delegate) | |||||
| } | |||||
| stop() { | |||||
| this._viewer.delegate.entities.remove(this._delegate) | |||||
| this._viewer.delegate.clock.multiplier = 1 | |||||
| this._viewer.delegate.trackedEntity = undefined | |||||
| } | } | ||||
| } | } | 
| /* | |||||
| * @Author: Caven | |||||
| * @Date: 2020-01-21 10:48:50 | |||||
| * @Last Modified by: Caven | |||||
| * @Last Modified time: 2020-01-21 12:29:21 | |||||
| */ | |||||
| import './index.scss' | |||||
| import 'cesium/Widgets/widgets.css' |