| @@ -1,5 +1,12 @@ | |||
| # 更新 | |||
| ## 1.7.1 | |||
| ### 2020-6-3 | |||
| > 1. 删除 Cesium 无效文件 | |||
| > 2. 修改覆盖物属性设置和样式设置 | |||
| ## 1.7.0 | |||
| ### 2020-6-3 | |||
| @@ -1,6 +1,6 @@ | |||
| { | |||
| "name": "@dvgis/dc-sdk", | |||
| "version": "1.7.0", | |||
| "version": "1.7.1", | |||
| "description": " The SDK is a secondary development based on the open source project Cesium, which optimizes some operations of Cesium and enables developers to quickly develop 3D applications through the framework.", | |||
| "main": "index.js", | |||
| "repository": "https://github.com/Digital-Visual/dc-sdk.git", | |||
| @@ -2,7 +2,7 @@ | |||
| * @Author: Caven | |||
| * @Date: 2020-04-22 09:44:30 | |||
| * @Last Modified by: Caven | |||
| * @Last Modified time: 2020-06-02 09:02:32 | |||
| * @Last Modified time: 2020-06-04 22:17:46 | |||
| */ | |||
| import { initMixin, initUse } from './global-api' | |||
| @@ -11,7 +11,7 @@ let DC = { | |||
| Author: 'Caven Chen', | |||
| GitHub: 'https://github.com/Digital-Visual', | |||
| Home: 'https://www.dvgis.cn', | |||
| Version: '1.7.0', | |||
| Version: '1.7.1', | |||
| Namespace: {}, | |||
| Initialized: false | |||
| } | |||
| @@ -2,7 +2,7 @@ | |||
| * @Author: Caven | |||
| * @Date: 2020-01-03 12:18:17 | |||
| * @Last Modified by: Caven | |||
| * @Last Modified time: 2020-05-27 08:50:09 | |||
| * @Last Modified time: 2020-06-04 22:01:03 | |||
| */ | |||
| import { Util } from '../utils' | |||
| import { OverlayEventType, OverlayEvent } from '../event' | |||
| @@ -12,10 +12,10 @@ import OverlayType from './OverlayType' | |||
| class Overlay { | |||
| constructor() { | |||
| this._id = Util.uuid() | |||
| this._bid = Util.uuid() // Business id | |||
| this._delegate = undefined | |||
| this._layer = undefined | |||
| this._state = undefined | |||
| this._delegate = undefined | |||
| this._bid = Util.uuid() // Business id | |||
| this._show = true | |||
| this._style = {} | |||
| this._attr = {} | |||
| @@ -31,6 +31,7 @@ class Overlay { | |||
| set id(id) { | |||
| this._bid = id | |||
| return this | |||
| } | |||
| get id() { | |||
| @@ -40,6 +41,7 @@ class Overlay { | |||
| set show(show) { | |||
| this._show = show | |||
| this._delegate && (this._delegate.show = this._show) | |||
| return this | |||
| } | |||
| get show() { | |||
| @@ -48,6 +50,7 @@ class Overlay { | |||
| set attr(attr) { | |||
| this._attr = attr | |||
| return this | |||
| } | |||
| get attr() { | |||
| @@ -2,11 +2,12 @@ | |||
| * @Author: Caven | |||
| * @Date: 2020-01-19 10:18:23 | |||
| * @Last Modified by: Caven | |||
| * @Last Modified time: 2020-06-03 13:52:37 | |||
| * @Last Modified time: 2020-06-04 22:04:16 | |||
| */ | |||
| import { Util } from '../../utils' | |||
| import Transform from '../../transform/Transform' | |||
| import Parse from '../../parse/Parse' | |||
| import State from '../../state/State' | |||
| import Overlay from '../Overlay' | |||
| @@ -14,23 +15,21 @@ const { Cesium } = DC.Namespace | |||
| class Billboard extends Overlay { | |||
| constructor(position, icon) { | |||
| if (!Util.checkPosition(position)) { | |||
| throw new Error('Billboard: the position invalid') | |||
| } | |||
| super() | |||
| this._position = position | |||
| this._delegate = new Cesium.Entity({ billboard: {} }) | |||
| this._position = Parse.parsePosition(position) | |||
| this._icon = icon | |||
| this._size = [32, 32] | |||
| this._delegate = new Cesium.Entity() | |||
| this.type = Overlay.getOverlayType('billboard') | |||
| this._state = State.INITIALIZED | |||
| } | |||
| set position(position) { | |||
| if (!Util.checkPosition(position)) { | |||
| throw new Error('Billboard: the position invalid') | |||
| } | |||
| this._position = position | |||
| this._position = Parse.parsePosition(position) | |||
| this._delegate.position = Transform.transformWGS84ToCartesian( | |||
| this._position | |||
| ) | |||
| return this | |||
| } | |||
| get position() { | |||
| @@ -39,6 +38,8 @@ class Billboard extends Overlay { | |||
| set icon(icon) { | |||
| this._icon = icon | |||
| this._delegate.billboard.image = this._icon | |||
| return this | |||
| } | |||
| get icon() { | |||
| @@ -50,6 +51,9 @@ class Billboard extends Overlay { | |||
| throw new Error('Billboard: the size invalid') | |||
| } | |||
| this._size = size | |||
| this._delegate.billboard.width = this._size[0] || 32 | |||
| this._delegate.billboard.height = this._size[0] || 32 | |||
| return this | |||
| } | |||
| get size() { | |||
| @@ -60,24 +64,15 @@ class Billboard extends Overlay { | |||
| /** | |||
| * set the location | |||
| */ | |||
| this._delegate.position = new Cesium.CallbackProperty(time => { | |||
| return Transform.transformWGS84ToCartesian(this._position) | |||
| }) | |||
| this.position = this._position | |||
| /** | |||
| * 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 | |||
| }) | |||
| } | |||
| Util.merge(this._delegate.billboard, { | |||
| image: this._icon, | |||
| width: this._size[0] || 32, | |||
| height: this._size[1] || 32 | |||
| }) | |||
| } | |||
| /** | |||
| @@ -98,12 +93,12 @@ class Billboard extends Overlay { | |||
| * @param {*} style | |||
| */ | |||
| setStyle(style) { | |||
| if (Object.keys(style).length === 0) { | |||
| if (!style || Object.keys(style).length === 0) { | |||
| return this | |||
| } | |||
| delete style['image'] && delete style['width'] && delete style['height'] | |||
| this._style = style | |||
| this._delegate.billboard && | |||
| Util.merge(this._delegate.billboard, this._style) | |||
| Util.merge(this._delegate.billboard, this._style) | |||
| return this | |||
| } | |||
| @@ -2,11 +2,12 @@ | |||
| * @Author: Caven | |||
| * @Date: 2020-01-31 18:57:02 | |||
| * @Last Modified by: Caven | |||
| * @Last Modified time: 2020-05-19 22:05:48 | |||
| * @Last Modified time: 2020-06-04 22:37:13 | |||
| */ | |||
| import { Util } from '../../utils' | |||
| import Transform from '../../transform/Transform' | |||
| import Parse from '../../parse/Parse' | |||
| import State from '../../state/State' | |||
| import Overlay from '../Overlay' | |||
| @@ -14,13 +15,10 @@ const { Cesium } = DC.Namespace | |||
| class Circle extends Overlay { | |||
| constructor(center, radius) { | |||
| if (!Util.checkPosition(center)) { | |||
| throw new Error('Circle: the center invalid') | |||
| } | |||
| super() | |||
| this._center = center | |||
| this._radius = radius || 0 | |||
| this._delegate = new Cesium.Entity() | |||
| this._delegate = new Cesium.Entity({ ellipse: {} }) | |||
| this._center = Parse.parsePosition(center) | |||
| this._radius = +radius || 0 | |||
| this._rotateAmount = 0 | |||
| this._stRotation = 0 | |||
| this.type = Overlay.getOverlayType('circle') | |||
| @@ -28,10 +26,9 @@ class Circle extends Overlay { | |||
| } | |||
| set center(center) { | |||
| if (!Util.checkPosition(center)) { | |||
| throw new Error('Circle: the center invalid') | |||
| } | |||
| this._center = center | |||
| this._center = Parse.parsePosition(center) | |||
| this._delegate.position = Transform.transformWGS84ToCartesian(this._center) | |||
| return this | |||
| } | |||
| get center() { | |||
| @@ -39,7 +36,10 @@ class Circle extends Overlay { | |||
| } | |||
| set radius(radius) { | |||
| this._radius = radius | |||
| this._radius = +radius | |||
| this._delegate.ellipse.semiMajorAxis = this._radius | |||
| this._delegate.ellipse.semiMinorAxis = this._radius | |||
| return this | |||
| } | |||
| get radius() { | |||
| @@ -47,7 +47,19 @@ class Circle extends Overlay { | |||
| } | |||
| set rotateAmount(amount) { | |||
| this._rotateAmount = amount | |||
| this._rotateAmount = +amount | |||
| if (this._rotateAmount > 0) { | |||
| this._delegate.ellipse.stRotation = new Cesium.CallbackProperty(time => { | |||
| if (this._rotateAmount > 0) { | |||
| this._stRotation += this._rotateAmount | |||
| if (this._stRotation >= 360) { | |||
| this._stRotation = 0 | |||
| } | |||
| } | |||
| return this._stRotation | |||
| }) | |||
| } | |||
| return this | |||
| } | |||
| get rotateAmount() { | |||
| @@ -58,44 +70,12 @@ class Circle extends Overlay { | |||
| /** | |||
| * set the location | |||
| */ | |||
| this._delegate.position = new Cesium.CallbackProperty(time => { | |||
| return Transform.transformWGS84ToCartesian(this._center) | |||
| }) | |||
| /** | |||
| * set the orientation | |||
| */ | |||
| this._delegate.orientation = new Cesium.CallbackProperty(time => { | |||
| return Cesium.Transforms.headingPitchRollQuaternion( | |||
| Transform.transformWGS84ToCartesian(this._center), | |||
| new Cesium.HeadingPitchRoll( | |||
| Cesium.Math.toRadians(this._center.heading), | |||
| Cesium.Math.toRadians(this._center.pitch), | |||
| Cesium.Math.toRadians(this._center.roll) | |||
| ) | |||
| ) | |||
| }) | |||
| this.center = this._center | |||
| /** | |||
| * initialize the Overlay parameter | |||
| */ | |||
| this._delegate.ellipse = { | |||
| ...this._style, | |||
| semiMajorAxis: new Cesium.CallbackProperty(time => { | |||
| return this._radius | |||
| }), | |||
| semiMinorAxis: new Cesium.CallbackProperty(time => { | |||
| return this._radius | |||
| }), | |||
| stRotation: new Cesium.CallbackProperty(time => { | |||
| if (this._rotateAmount > 0) { | |||
| this._stRotation += this._rotateAmount | |||
| if (this._stRotation >= 360) { | |||
| this._stRotation = 0 | |||
| } | |||
| } | |||
| return this._stRotation | |||
| }) | |||
| } | |||
| this.radius = this._radius | |||
| } | |||
| /** | |||
| @@ -116,11 +96,12 @@ class Circle extends Overlay { | |||
| * @param {*} style | |||
| */ | |||
| setStyle(style) { | |||
| if (Object.keys(style).length === 0) { | |||
| if (!style || Object.keys(style).length === 0) { | |||
| return this | |||
| } | |||
| delete style['semiMajorAxis'] && delete style['semiMinorAxis'] | |||
| this._style = style | |||
| this._delegate.ellipse && Util.merge(this._delegate.ellipse, this._style) | |||
| Util.merge(this._delegate.ellipse, this._style) | |||
| return this | |||
| } | |||
| } | |||
| @@ -2,23 +2,21 @@ | |||
| * @Author: Caven | |||
| * @Date: 2020-02-12 21:46:22 | |||
| * @Last Modified by: Caven | |||
| * @Last Modified time: 2020-05-11 23:35:31 | |||
| * @Last Modified time: 2020-06-04 21:50:47 | |||
| */ | |||
| import { DomUtil, Util } from '../../utils' | |||
| import { isBetween } from '../../math' | |||
| import Transform from '../../transform/Transform' | |||
| import Parse from '../../parse/Parse' | |||
| import State from '../../state/State' | |||
| import Overlay from '../Overlay' | |||
| class DivIcon extends Overlay { | |||
| constructor(position, content) { | |||
| if (!Util.checkPosition(position)) { | |||
| throw new Error('DivIcon: the position invalid') | |||
| } | |||
| super() | |||
| this._position = position | |||
| this._delegate = DomUtil.create('div', 'div-icon') | |||
| this._position = Parse.parsePosition(position) | |||
| this._delegate.setAttribute('id', this._id) | |||
| Util.merge(this._delegate.style, { | |||
| position: 'absolute', | |||
| @@ -33,6 +31,7 @@ class DivIcon extends Overlay { | |||
| set show(show) { | |||
| this._show = show | |||
| this._delegate.style.visibility = this._show ? 'visible' : 'hidden' | |||
| return this | |||
| } | |||
| get show() { | |||
| @@ -40,10 +39,8 @@ class DivIcon extends Overlay { | |||
| } | |||
| set position(position) { | |||
| if (!Util.checkPosition(position)) { | |||
| throw new Error('DivIcon: the position invalid') | |||
| } | |||
| this._position = position | |||
| this._position = Parse.parsePosition(position) | |||
| return this | |||
| } | |||
| get position() { | |||
| @@ -56,6 +53,7 @@ class DivIcon extends Overlay { | |||
| } else if (content && content instanceof Element) { | |||
| this._delegate.appendChild(content) | |||
| } | |||
| return this | |||
| } | |||
| _updateStyle(style, distance) { | |||
| @@ -126,7 +124,7 @@ class DivIcon extends Overlay { | |||
| * @param {*} name | |||
| */ | |||
| setStyle(style) { | |||
| if (Object.keys(style).length === 0) { | |||
| if (!style || Object.keys(style).length === 0) { | |||
| return this | |||
| } | |||
| this._style = style | |||
| @@ -2,11 +2,12 @@ | |||
| * @Author: Caven | |||
| * @Date: 2020-02-01 11:59:28 | |||
| * @Last Modified by: Caven | |||
| * @Last Modified time: 2020-05-11 22:38:18 | |||
| * @Last Modified time: 2020-06-04 21:53:38 | |||
| */ | |||
| import { Util } from '../../utils' | |||
| import Transform from '../../transform/Transform' | |||
| import Parse from '../../parse/Parse' | |||
| import State from '../../state/State' | |||
| import Overlay from '../Overlay' | |||
| @@ -14,22 +15,20 @@ const { Cesium } = DC.Namespace | |||
| class Label extends Overlay { | |||
| constructor(position, text) { | |||
| if (!Util.checkPosition(position)) { | |||
| throw new Error('Label: the position invalid') | |||
| } | |||
| super() | |||
| this._position = position | |||
| this._delegate = new Cesium.Entity({ label: {} }) | |||
| this._position = Parse.parsePosition(position) | |||
| this._text = text | |||
| this._delegate = new Cesium.Entity() | |||
| this.type = Overlay.getOverlayType('label') | |||
| this._state = State.INITIALIZED | |||
| } | |||
| set position(position) { | |||
| if (!Util.checkPosition(position)) { | |||
| throw new Error('Label: the position invalid') | |||
| } | |||
| this._position = position | |||
| this._position = Parse.parsePosition(position) | |||
| this._delegate.position = Transform.transformWGS84ToCartesian( | |||
| this._position | |||
| ) | |||
| return this | |||
| } | |||
| get position() { | |||
| @@ -38,6 +37,8 @@ class Label extends Overlay { | |||
| set text(text) { | |||
| this._text = text | |||
| this._delegate.label.text = this._text | |||
| return this | |||
| } | |||
| get text() { | |||
| @@ -48,19 +49,12 @@ class Label extends Overlay { | |||
| /** | |||
| * set the location | |||
| */ | |||
| this._delegate.position = new Cesium.CallbackProperty(time => { | |||
| return Transform.transformWGS84ToCartesian(this._position) | |||
| }) | |||
| this.position = this._position | |||
| /** | |||
| * initialize the Overlay parameter | |||
| */ | |||
| this._delegate.label = { | |||
| ...this._style, | |||
| text: new Cesium.CallbackProperty(time => { | |||
| return this._text | |||
| }) | |||
| } | |||
| this.text = this._text | |||
| } | |||
| /** | |||
| @@ -68,11 +62,12 @@ class Label extends Overlay { | |||
| * @param {*} style | |||
| */ | |||
| setStyle(style) { | |||
| if (Object.keys(style).length === 0) { | |||
| if (!style || Object.keys(style).length === 0) { | |||
| return this | |||
| } | |||
| delete style['text'] | |||
| this._style = style | |||
| this._delegate.label && Util.merge(this._delegate.label, this._style) | |||
| Util.merge(this._delegate.label, this._style) | |||
| return this | |||
| } | |||
| @@ -2,11 +2,12 @@ | |||
| * @Author: Caven | |||
| * @Date: 2020-01-06 15:03:25 | |||
| * @Last Modified by: Caven | |||
| * @Last Modified time: 2020-05-11 22:07:14 | |||
| * @Last Modified time: 2020-06-04 21:53:31 | |||
| */ | |||
| import { Util } from '../../utils' | |||
| import Transform from '../../transform/Transform' | |||
| import Parse from '../../parse/Parse' | |||
| import State from '../../state/State' | |||
| import Overlay from '../Overlay' | |||
| @@ -20,12 +21,9 @@ const DEF_STYLE = { | |||
| class Point extends Overlay { | |||
| constructor(position) { | |||
| if (!Util.checkPosition(position)) { | |||
| throw new Error('Point: the position invalid') | |||
| } | |||
| super() | |||
| this._position = position | |||
| this._delegate = new Cesium.Entity() | |||
| this._delegate = new Cesium.Entity({ point: {} }) | |||
| this._position = Parse.parsePosition(position) | |||
| this.type = Overlay.getOverlayType('point') | |||
| this._state = State.INITIALIZED | |||
| } | |||
| @@ -34,7 +32,11 @@ class Point extends Overlay { | |||
| if (!Util.checkPosition(position)) { | |||
| throw new Error('Point: the position invalid') | |||
| } | |||
| this._position = position | |||
| this._position = Parse.parsePosition(position) | |||
| this._delegate.position = Transform.transformWGS84ToCartesian( | |||
| this._position | |||
| ) | |||
| return this | |||
| } | |||
| get position() { | |||
| @@ -45,17 +47,12 @@ class Point extends Overlay { | |||
| /** | |||
| * set the location | |||
| */ | |||
| this._delegate.position = new Cesium.CallbackProperty(time => { | |||
| return Transform.transformWGS84ToCartesian(this._position) | |||
| }) | |||
| this.position = this._position | |||
| /** | |||
| * initialize the Overlay parameter | |||
| */ | |||
| this._delegate.point = { | |||
| ...DEF_STYLE, | |||
| ...this._style | |||
| } | |||
| Util.merge(this._delegate.point, DEF_STYLE, this._style) | |||
| } | |||
| /** | |||
| @@ -63,12 +60,12 @@ class Point extends Overlay { | |||
| * @param {*} style | |||
| */ | |||
| setStyle(style) { | |||
| if (Object.keys(style).length === 0) { | |||
| if (!style || Object.keys(style).length === 0) { | |||
| return this | |||
| } | |||
| delete style['position'] | |||
| this._style = style | |||
| this._delegate.point && | |||
| Util.merge(this._delegate.point, DEF_STYLE, this._style) | |||
| Util.merge(this._delegate.point, DEF_STYLE, this._style) | |||
| return this | |||
| } | |||
| } | |||
| @@ -2,7 +2,7 @@ | |||
| * @Author: Caven | |||
| * @Date: 2020-01-09 09:10:37 | |||
| * @Last Modified by: Caven | |||
| * @Last Modified time: 2020-06-03 13:52:31 | |||
| * @Last Modified time: 2020-06-04 22:05:41 | |||
| */ | |||
| import { Util } from '../../utils' | |||
| @@ -16,22 +16,18 @@ const { Cesium } = DC.Namespace | |||
| class Polygon extends Overlay { | |||
| constructor(positions) { | |||
| if (!Util.checkPositions(positions)) { | |||
| throw new Error('Polygon: the positions invalid') | |||
| } | |||
| super() | |||
| this._delegate = new Cesium.Entity({ polygon: {} }) | |||
| this._positions = Parse.parsePositions(positions) | |||
| this._holes = [] | |||
| this._delegate = new Cesium.Entity() | |||
| this.type = Overlay.getOverlayType('polygon') | |||
| this._state = State.INITIALIZED | |||
| } | |||
| set positions(positions) { | |||
| if (!Util.checkPositions(positions)) { | |||
| throw new Error('Polygon: the positions invalid') | |||
| } | |||
| this._positions = Parse.parsePositions(positions) | |||
| this._delegate.polygon.hierarchy = this._prepareHierarchy() | |||
| return this | |||
| } | |||
| get positions() { | |||
| @@ -41,7 +37,9 @@ class Polygon extends Overlay { | |||
| set holes(holes) { | |||
| if (holes && holes.length) { | |||
| this._holes = holes.map(item => Parse.parsePositions(item)) | |||
| this._delegate.polygon.hierarchy = this._prepareHierarchy() | |||
| } | |||
| return this | |||
| } | |||
| get holes() { | |||
| @@ -77,12 +75,7 @@ class Polygon extends Overlay { | |||
| /** | |||
| * initialize the Overlay parameter | |||
| */ | |||
| this._delegate.polygon = { | |||
| ...this._style, | |||
| hierarchy: new Cesium.CallbackProperty(time => { | |||
| return this._prepareHierarchy() | |||
| }) | |||
| } | |||
| this.positions = this._positions | |||
| } | |||
| /** | |||
| @@ -93,8 +86,9 @@ class Polygon extends Overlay { | |||
| if (!style || Object.keys(style).length === 0) { | |||
| return this | |||
| } | |||
| delete style['positions'] | |||
| this._style = style | |||
| this._delegate.polygon && Util.merge(this._delegate.polygon, this._style) | |||
| Util.merge(this._delegate.polygon, this._style) | |||
| return this | |||
| } | |||
| @@ -114,7 +108,6 @@ class Polygon extends Overlay { | |||
| ...entity.properties.getValue(now) | |||
| } | |||
| } | |||
| return polygon | |||
| } | |||
| } | |||
| @@ -2,7 +2,7 @@ | |||
| * @Author: Caven | |||
| * @Date: 2020-01-06 15:03:25 | |||
| * @Last Modified by: Caven | |||
| * @Last Modified time: 2020-06-03 13:52:44 | |||
| * @Last Modified time: 2020-06-04 22:05:39 | |||
| */ | |||
| import { Util } from '../../utils' | |||
| @@ -16,21 +16,19 @@ const { Cesium } = DC.Namespace | |||
| class Polyline extends Overlay { | |||
| constructor(positions) { | |||
| if (!Util.checkPositions(positions)) { | |||
| throw new Error('Polyline: the positions invalid') | |||
| } | |||
| super() | |||
| this._positions = Parse.parsePositions(positions) | |||
| this._delegate = new Cesium.Entity() | |||
| this._delegate = new Cesium.Entity({ polyline: {} }) | |||
| this.type = Overlay.getOverlayType('polyline') | |||
| this._state = State.INITIALIZED | |||
| } | |||
| set positions(positions) { | |||
| if (!Util.checkPositions(positions)) { | |||
| throw new Error('Polyline: the positions invalid') | |||
| } | |||
| this._positions = Parse.parsePositions(positions) | |||
| this._delegate.polyline.positions = Transform.transformWGS84ArrayToCartesianArray( | |||
| this._positions | |||
| ) | |||
| return this | |||
| } | |||
| get positions() { | |||
| @@ -49,12 +47,7 @@ class Polyline extends Overlay { | |||
| /** | |||
| * initialize the Overlay parameter | |||
| */ | |||
| this._delegate.polyline = { | |||
| ...this._style, | |||
| positions: new Cesium.CallbackProperty(time => { | |||
| return Transform.transformWGS84ArrayToCartesianArray(this._positions) | |||
| }) | |||
| } | |||
| this.positions = this._positions | |||
| } | |||
| /** | |||
| @@ -62,11 +55,12 @@ class Polyline extends Overlay { | |||
| * @param {*} style | |||
| */ | |||
| setStyle(style) { | |||
| if (Object.keys(style).length == 0) { | |||
| if (!style || Object.keys(style).length === 0) { | |||
| return this | |||
| } | |||
| delete style['positions'] | |||
| this._style = style | |||
| this._delegate.polyline && Util.merge(this._delegate.polyline, this._style) | |||
| Util.merge(this._delegate.polyline, this._style) | |||
| return this | |||
| } | |||
| @@ -2,7 +2,7 @@ | |||
| * @Author: Caven | |||
| * @Date: 2020-01-06 15:04:15 | |||
| * @Last Modified by: Caven | |||
| * @Last Modified time: 2020-05-19 22:05:56 | |||
| * @Last Modified time: 2020-06-04 22:01:23 | |||
| */ | |||
| export { default as OverlayType } from './OverlayType' | |||
| export { default as Overlay } from './Overlay' | |||
| @@ -2,11 +2,12 @@ | |||
| * @Author: Caven | |||
| * @Date: 2020-01-06 15:03:25 | |||
| * @Last Modified by: Caven | |||
| * @Last Modified time: 2020-06-03 13:52:52 | |||
| * @Last Modified time: 2020-06-04 22:37:20 | |||
| */ | |||
| import { Util } from '../../utils' | |||
| import Transform from '../../transform/Transform' | |||
| import Parse from '../../parse/Parse' | |||
| import State from '../../state/State' | |||
| import Overlay from '../Overlay' | |||
| @@ -14,23 +15,31 @@ const { Cesium } = DC.Namespace | |||
| class Model extends Overlay { | |||
| constructor(position, modelUrl) { | |||
| if (!Util.checkPosition(position)) { | |||
| throw new Error('Model: the position invalid') | |||
| } | |||
| super() | |||
| this._position = position | |||
| this._delegate = new Cesium.Entity({ model: {} }) | |||
| this._position = Parse.parsePosition(position) | |||
| this._modelUrl = modelUrl | |||
| this._delegate = new Cesium.Entity() | |||
| this._rotateAmount = 0 | |||
| this.type = Overlay.getOverlayType('model') | |||
| this._state = State.INITIALIZED | |||
| } | |||
| set position(position) { | |||
| if (!Util.checkPosition(position)) { | |||
| throw new Error('Model: the position invalid') | |||
| this._position = Parse.parsePosition(position) | |||
| this._delegate.position = Transform.transformWGS84ToCartesian( | |||
| this._position | |||
| ) | |||
| if (this._rotateAmount === 0) { | |||
| this._delegate.orientation = Cesium.Transforms.headingPitchRollQuaternion( | |||
| Transform.transformWGS84ToCartesian(this._position), | |||
| new Cesium.HeadingPitchRoll( | |||
| Cesium.Math.toRadians(this._position.heading), | |||
| Cesium.Math.toRadians(this._position.pitch), | |||
| Cesium.Math.toRadians(this._position.roll) | |||
| ) | |||
| ) | |||
| } | |||
| this._position = position | |||
| return this | |||
| } | |||
| get position() { | |||
| @@ -39,6 +48,8 @@ class Model extends Overlay { | |||
| set modelUrl(modelUrl) { | |||
| this._modelUrl = modelUrl | |||
| this._delegate.model.uri = this._modelUrl | |||
| return this | |||
| } | |||
| get modelUrl() { | |||
| @@ -46,7 +57,24 @@ class Model extends Overlay { | |||
| } | |||
| set rotateAmount(amount) { | |||
| this._rotateAmount = amount | |||
| this._rotateAmount = +amount | |||
| if (this._rotateAmount > 0) { | |||
| this._delegate.orientation = new Cesium.CallbackProperty(time => { | |||
| this._position.heading += this._rotateAmount | |||
| if (this._position.heading === 360) { | |||
| this._position.heading = 0 | |||
| } | |||
| return Cesium.Transforms.headingPitchRollQuaternion( | |||
| Transform.transformWGS84ToCartesian(this._position), | |||
| new Cesium.HeadingPitchRoll( | |||
| Cesium.Math.toRadians(this._position.heading), | |||
| Cesium.Math.toRadians(this._position.pitch), | |||
| Cesium.Math.toRadians(this._position.roll) | |||
| ) | |||
| ) | |||
| }) | |||
| } | |||
| return this | |||
| } | |||
| get rotateAmount() { | |||
| @@ -57,37 +85,11 @@ class Model extends Overlay { | |||
| /** | |||
| * set the location | |||
| */ | |||
| this._delegate.position = new Cesium.CallbackProperty(time => { | |||
| return Transform.transformWGS84ToCartesian(this._position) | |||
| }) | |||
| /** | |||
| * set the orientation | |||
| */ | |||
| this._delegate.orientation = new Cesium.CallbackProperty(time => { | |||
| if (this._rotateAmount > 0) { | |||
| this._position.heading += this._rotateAmount | |||
| if (this._position.heading === 360) { | |||
| this._position.heading = 0 | |||
| } | |||
| } | |||
| return Cesium.Transforms.headingPitchRollQuaternion( | |||
| Transform.transformWGS84ToCartesian(this._position), | |||
| new Cesium.HeadingPitchRoll( | |||
| Cesium.Math.toRadians(this._position.heading), | |||
| Cesium.Math.toRadians(this._position.pitch), | |||
| Cesium.Math.toRadians(this._position.roll) | |||
| ) | |||
| ) | |||
| }) | |||
| this.position = this._position | |||
| /** | |||
| * initialize the Overlay parameter | |||
| */ | |||
| this._delegate.model = { | |||
| ...this._style, | |||
| uri: new Cesium.CallbackProperty(time => { | |||
| return this._modelUrl | |||
| }) | |||
| } | |||
| this.modelUrl = this._modelUrl | |||
| } | |||
| /** | |||
| @@ -108,11 +110,11 @@ class Model extends Overlay { | |||
| * @param {*} style | |||
| */ | |||
| setStyle(style) { | |||
| if (Object.keys(style).length == 0) { | |||
| if (!style || Object.keys(style).length === 0) { | |||
| return this | |||
| } | |||
| this._style = style | |||
| this._delegate.model && Util.merge(this._delegate.model, this._style) | |||
| Util.merge(this._delegate.model, this._style) | |||
| return this | |||
| } | |||
| @@ -2,10 +2,10 @@ | |||
| * @Author: Caven | |||
| * @Date: 2020-01-07 08:51:56 | |||
| * @Last Modified by: Caven | |||
| * @Last Modified time: 2020-05-11 22:07:45 | |||
| * @Last Modified time: 2020-06-04 22:00:12 | |||
| */ | |||
| import { Util } from '../../utils' | |||
| import Parse from '../../parse/Parse' | |||
| import State from '../../state/State' | |||
| import Overlay from '../Overlay' | |||
| @@ -145,9 +145,7 @@ class Tileset extends Overlay { | |||
| * @param {*} position | |||
| */ | |||
| setPosition(position) { | |||
| if (!Util.checkPosition(position)) { | |||
| return this | |||
| } | |||
| position = Parse.parsePosition(position) | |||
| this._delegate.readyPromise.then(tileset => { | |||
| let modelMatrix = Cesium.Transforms.eastNorthUpToFixedFrame( | |||
| Cesium.Cartesian3.fromDegrees(position.lng, position.lat, position.alt) | |||
| @@ -215,7 +213,7 @@ class Tileset extends Overlay { | |||
| setStyle(style) { | |||
| if (style && style instanceof Cesium.Cesium3DTileStyle) { | |||
| this._style = style | |||
| this._delegate && (this._delegate.style = this._style) | |||
| this._delegate.style = this._style | |||
| } | |||
| return this | |||
| } | |||