| # 更新 | # 更新 | ||||
| ## 1.7.1 | |||||
| ### 2020-6-3 | |||||
| > 1. 删除 Cesium 无效文件 | |||||
| > 2. 修改覆盖物属性设置和样式设置 | |||||
| ## 1.7.0 | ## 1.7.0 | ||||
| ### 2020-6-3 | ### 2020-6-3 |
| { | { | ||||
| "name": "@dvgis/dc-sdk", | "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.", | "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", | "main": "index.js", | ||||
| "repository": "https://github.com/Digital-Visual/dc-sdk.git", | "repository": "https://github.com/Digital-Visual/dc-sdk.git", |
| * @Author: Caven | * @Author: Caven | ||||
| * @Date: 2020-04-22 09:44:30 | * @Date: 2020-04-22 09:44:30 | ||||
| * @Last Modified by: Caven | * @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' | import { initMixin, initUse } from './global-api' | ||||
| Author: 'Caven Chen', | Author: 'Caven Chen', | ||||
| GitHub: 'https://github.com/Digital-Visual', | GitHub: 'https://github.com/Digital-Visual', | ||||
| Home: 'https://www.dvgis.cn', | Home: 'https://www.dvgis.cn', | ||||
| Version: '1.7.0', | |||||
| Version: '1.7.1', | |||||
| Namespace: {}, | Namespace: {}, | ||||
| Initialized: false | Initialized: false | ||||
| } | } |
| * @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-05-27 08:50:09 | |||||
| * @Last Modified time: 2020-06-04 22:01:03 | |||||
| */ | */ | ||||
| import { Util } from '../utils' | import { Util } from '../utils' | ||||
| import { OverlayEventType, OverlayEvent } from '../event' | import { OverlayEventType, OverlayEvent } from '../event' | ||||
| class Overlay { | class Overlay { | ||||
| constructor() { | constructor() { | ||||
| this._id = Util.uuid() | this._id = Util.uuid() | ||||
| this._bid = Util.uuid() // Business id | |||||
| this._delegate = undefined | |||||
| this._layer = undefined | this._layer = undefined | ||||
| this._state = undefined | this._state = undefined | ||||
| this._delegate = undefined | |||||
| this._bid = Util.uuid() // Business id | |||||
| this._show = true | this._show = true | ||||
| this._style = {} | this._style = {} | ||||
| this._attr = {} | this._attr = {} | ||||
| set id(id) { | set id(id) { | ||||
| this._bid = id | this._bid = id | ||||
| return this | |||||
| } | } | ||||
| get id() { | get id() { | ||||
| set show(show) { | set show(show) { | ||||
| this._show = show | this._show = show | ||||
| this._delegate && (this._delegate.show = this._show) | this._delegate && (this._delegate.show = this._show) | ||||
| return this | |||||
| } | } | ||||
| get show() { | get show() { | ||||
| set attr(attr) { | set attr(attr) { | ||||
| this._attr = attr | this._attr = attr | ||||
| return this | |||||
| } | } | ||||
| get attr() { | get attr() { |
| * @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-06-03 13:52:37 | |||||
| * @Last Modified time: 2020-06-04 22:04:16 | |||||
| */ | */ | ||||
| import { Util } from '../../utils' | import { Util } from '../../utils' | ||||
| import Transform from '../../transform/Transform' | import Transform from '../../transform/Transform' | ||||
| import Parse from '../../parse/Parse' | |||||
| import State from '../../state/State' | import State from '../../state/State' | ||||
| import Overlay from '../Overlay' | import Overlay from '../Overlay' | ||||
| class Billboard extends Overlay { | class Billboard extends Overlay { | ||||
| constructor(position, icon) { | constructor(position, icon) { | ||||
| if (!Util.checkPosition(position)) { | |||||
| throw new Error('Billboard: the position invalid') | |||||
| } | |||||
| super() | super() | ||||
| this._position = position | |||||
| this._delegate = new Cesium.Entity({ billboard: {} }) | |||||
| this._position = Parse.parsePosition(position) | |||||
| this._icon = icon | this._icon = icon | ||||
| this._size = [32, 32] | this._size = [32, 32] | ||||
| this._delegate = new Cesium.Entity() | |||||
| this.type = Overlay.getOverlayType('billboard') | this.type = Overlay.getOverlayType('billboard') | ||||
| this._state = State.INITIALIZED | this._state = State.INITIALIZED | ||||
| } | } | ||||
| set position(position) { | 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() { | get position() { | ||||
| set icon(icon) { | set icon(icon) { | ||||
| this._icon = icon | this._icon = icon | ||||
| this._delegate.billboard.image = this._icon | |||||
| return this | |||||
| } | } | ||||
| get icon() { | get icon() { | ||||
| throw new Error('Billboard: the size invalid') | throw new Error('Billboard: the size invalid') | ||||
| } | } | ||||
| this._size = size | this._size = size | ||||
| this._delegate.billboard.width = this._size[0] || 32 | |||||
| this._delegate.billboard.height = this._size[0] || 32 | |||||
| return this | |||||
| } | } | ||||
| get size() { | get size() { | ||||
| /** | /** | ||||
| * set the location | * set the location | ||||
| */ | */ | ||||
| this._delegate.position = new Cesium.CallbackProperty(time => { | |||||
| return Transform.transformWGS84ToCartesian(this._position) | |||||
| }) | |||||
| this.position = this._position | |||||
| /** | /** | ||||
| * initialize the Overlay parameter | * 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 | |||||
| }) | |||||
| } | } | ||||
| /** | /** | ||||
| * @param {*} style | * @param {*} style | ||||
| */ | */ | ||||
| setStyle(style) { | setStyle(style) { | ||||
| if (Object.keys(style).length === 0) { | |||||
| if (!style || Object.keys(style).length === 0) { | |||||
| return this | return this | ||||
| } | } | ||||
| delete style['image'] && delete style['width'] && delete style['height'] | |||||
| this._style = style | this._style = style | ||||
| this._delegate.billboard && | |||||
| Util.merge(this._delegate.billboard, this._style) | |||||
| Util.merge(this._delegate.billboard, this._style) | |||||
| return this | return this | ||||
| } | } | ||||
| * @Author: Caven | * @Author: Caven | ||||
| * @Date: 2020-01-31 18:57:02 | * @Date: 2020-01-31 18:57:02 | ||||
| * @Last Modified by: Caven | * @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 { Util } from '../../utils' | ||||
| import Transform from '../../transform/Transform' | import Transform from '../../transform/Transform' | ||||
| import Parse from '../../parse/Parse' | |||||
| import State from '../../state/State' | import State from '../../state/State' | ||||
| import Overlay from '../Overlay' | import Overlay from '../Overlay' | ||||
| class Circle extends Overlay { | class Circle extends Overlay { | ||||
| constructor(center, radius) { | constructor(center, radius) { | ||||
| if (!Util.checkPosition(center)) { | |||||
| throw new Error('Circle: the center invalid') | |||||
| } | |||||
| super() | 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._rotateAmount = 0 | ||||
| this._stRotation = 0 | this._stRotation = 0 | ||||
| this.type = Overlay.getOverlayType('circle') | this.type = Overlay.getOverlayType('circle') | ||||
| } | } | ||||
| set center(center) { | 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() { | get center() { | ||||
| } | } | ||||
| set radius(radius) { | 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() { | get radius() { | ||||
| } | } | ||||
| set rotateAmount(amount) { | 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() { | get rotateAmount() { | ||||
| /** | /** | ||||
| * set the location | * 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 | * 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 | |||||
| } | } | ||||
| /** | /** | ||||
| * @param {*} style | * @param {*} style | ||||
| */ | */ | ||||
| setStyle(style) { | setStyle(style) { | ||||
| if (Object.keys(style).length === 0) { | |||||
| if (!style || Object.keys(style).length === 0) { | |||||
| return this | return this | ||||
| } | } | ||||
| delete style['semiMajorAxis'] && delete style['semiMinorAxis'] | |||||
| this._style = style | this._style = style | ||||
| this._delegate.ellipse && Util.merge(this._delegate.ellipse, this._style) | |||||
| Util.merge(this._delegate.ellipse, this._style) | |||||
| return this | return this | ||||
| } | } | ||||
| } | } |
| * @Author: Caven | * @Author: Caven | ||||
| * @Date: 2020-02-12 21:46:22 | * @Date: 2020-02-12 21:46:22 | ||||
| * @Last Modified by: Caven | * @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 { DomUtil, Util } from '../../utils' | ||||
| import { isBetween } from '../../math' | import { isBetween } from '../../math' | ||||
| import Transform from '../../transform/Transform' | import Transform from '../../transform/Transform' | ||||
| import Parse from '../../parse/Parse' | |||||
| import State from '../../state/State' | import State from '../../state/State' | ||||
| import Overlay from '../Overlay' | import Overlay from '../Overlay' | ||||
| class DivIcon extends Overlay { | class DivIcon extends Overlay { | ||||
| constructor(position, content) { | constructor(position, content) { | ||||
| if (!Util.checkPosition(position)) { | |||||
| throw new Error('DivIcon: the position invalid') | |||||
| } | |||||
| super() | super() | ||||
| this._position = position | |||||
| this._delegate = DomUtil.create('div', 'div-icon') | this._delegate = DomUtil.create('div', 'div-icon') | ||||
| this._position = Parse.parsePosition(position) | |||||
| this._delegate.setAttribute('id', this._id) | this._delegate.setAttribute('id', this._id) | ||||
| Util.merge(this._delegate.style, { | Util.merge(this._delegate.style, { | ||||
| position: 'absolute', | position: 'absolute', | ||||
| set show(show) { | set show(show) { | ||||
| this._show = show | this._show = show | ||||
| this._delegate.style.visibility = this._show ? 'visible' : 'hidden' | this._delegate.style.visibility = this._show ? 'visible' : 'hidden' | ||||
| return this | |||||
| } | } | ||||
| get show() { | get show() { | ||||
| } | } | ||||
| set position(position) { | 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() { | get position() { | ||||
| } else if (content && content instanceof Element) { | } else if (content && content instanceof Element) { | ||||
| this._delegate.appendChild(content) | this._delegate.appendChild(content) | ||||
| } | } | ||||
| return this | |||||
| } | } | ||||
| _updateStyle(style, distance) { | _updateStyle(style, distance) { | ||||
| * @param {*} name | * @param {*} name | ||||
| */ | */ | ||||
| setStyle(style) { | setStyle(style) { | ||||
| if (Object.keys(style).length === 0) { | |||||
| if (!style || Object.keys(style).length === 0) { | |||||
| return this | return this | ||||
| } | } | ||||
| this._style = style | this._style = style |
| * @Author: Caven | * @Author: Caven | ||||
| * @Date: 2020-02-01 11:59:28 | * @Date: 2020-02-01 11:59:28 | ||||
| * @Last Modified by: Caven | * @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 { Util } from '../../utils' | ||||
| import Transform from '../../transform/Transform' | import Transform from '../../transform/Transform' | ||||
| import Parse from '../../parse/Parse' | |||||
| import State from '../../state/State' | import State from '../../state/State' | ||||
| import Overlay from '../Overlay' | import Overlay from '../Overlay' | ||||
| class Label extends Overlay { | class Label extends Overlay { | ||||
| constructor(position, text) { | constructor(position, text) { | ||||
| if (!Util.checkPosition(position)) { | |||||
| throw new Error('Label: the position invalid') | |||||
| } | |||||
| super() | super() | ||||
| this._position = position | |||||
| this._delegate = new Cesium.Entity({ label: {} }) | |||||
| this._position = Parse.parsePosition(position) | |||||
| this._text = text | this._text = text | ||||
| this._delegate = new Cesium.Entity() | |||||
| this.type = Overlay.getOverlayType('label') | this.type = Overlay.getOverlayType('label') | ||||
| this._state = State.INITIALIZED | this._state = State.INITIALIZED | ||||
| } | } | ||||
| set position(position) { | 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() { | get position() { | ||||
| set text(text) { | set text(text) { | ||||
| this._text = text | this._text = text | ||||
| this._delegate.label.text = this._text | |||||
| return this | |||||
| } | } | ||||
| get text() { | get text() { | ||||
| /** | /** | ||||
| * set the location | * set the location | ||||
| */ | */ | ||||
| this._delegate.position = new Cesium.CallbackProperty(time => { | |||||
| return Transform.transformWGS84ToCartesian(this._position) | |||||
| }) | |||||
| this.position = this._position | |||||
| /** | /** | ||||
| * initialize the Overlay parameter | * initialize the Overlay parameter | ||||
| */ | */ | ||||
| this._delegate.label = { | |||||
| ...this._style, | |||||
| text: new Cesium.CallbackProperty(time => { | |||||
| return this._text | |||||
| }) | |||||
| } | |||||
| this.text = this._text | |||||
| } | } | ||||
| /** | /** | ||||
| * @param {*} style | * @param {*} style | ||||
| */ | */ | ||||
| setStyle(style) { | setStyle(style) { | ||||
| if (Object.keys(style).length === 0) { | |||||
| if (!style || Object.keys(style).length === 0) { | |||||
| return this | return this | ||||
| } | } | ||||
| delete style['text'] | |||||
| this._style = style | this._style = style | ||||
| this._delegate.label && Util.merge(this._delegate.label, this._style) | |||||
| Util.merge(this._delegate.label, this._style) | |||||
| return this | return this | ||||
| } | } | ||||
| * @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-05-11 22:07:14 | |||||
| * @Last Modified time: 2020-06-04 21:53:31 | |||||
| */ | */ | ||||
| import { Util } from '../../utils' | import { Util } from '../../utils' | ||||
| import Transform from '../../transform/Transform' | import Transform from '../../transform/Transform' | ||||
| import Parse from '../../parse/Parse' | |||||
| import State from '../../state/State' | import State from '../../state/State' | ||||
| import Overlay from '../Overlay' | import Overlay from '../Overlay' | ||||
| class Point extends Overlay { | class Point extends Overlay { | ||||
| constructor(position) { | constructor(position) { | ||||
| if (!Util.checkPosition(position)) { | |||||
| throw new Error('Point: the position invalid') | |||||
| } | |||||
| super() | 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.type = Overlay.getOverlayType('point') | ||||
| this._state = State.INITIALIZED | this._state = State.INITIALIZED | ||||
| } | } | ||||
| if (!Util.checkPosition(position)) { | if (!Util.checkPosition(position)) { | ||||
| throw new Error('Point: the position invalid') | 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() { | get position() { | ||||
| /** | /** | ||||
| * set the location | * set the location | ||||
| */ | */ | ||||
| this._delegate.position = new Cesium.CallbackProperty(time => { | |||||
| return Transform.transformWGS84ToCartesian(this._position) | |||||
| }) | |||||
| this.position = this._position | |||||
| /** | /** | ||||
| * initialize the Overlay parameter | * initialize the Overlay parameter | ||||
| */ | */ | ||||
| this._delegate.point = { | |||||
| ...DEF_STYLE, | |||||
| ...this._style | |||||
| } | |||||
| Util.merge(this._delegate.point, DEF_STYLE, this._style) | |||||
| } | } | ||||
| /** | /** | ||||
| * @param {*} style | * @param {*} style | ||||
| */ | */ | ||||
| setStyle(style) { | setStyle(style) { | ||||
| if (Object.keys(style).length === 0) { | |||||
| if (!style || Object.keys(style).length === 0) { | |||||
| return this | return this | ||||
| } | } | ||||
| delete style['position'] | |||||
| this._style = style | 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 | return this | ||||
| } | } | ||||
| } | } |
| * @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-06-03 13:52:31 | |||||
| * @Last Modified time: 2020-06-04 22:05:41 | |||||
| */ | */ | ||||
| import { Util } from '../../utils' | import { Util } from '../../utils' | ||||
| class Polygon extends Overlay { | class Polygon extends Overlay { | ||||
| constructor(positions) { | constructor(positions) { | ||||
| if (!Util.checkPositions(positions)) { | |||||
| throw new Error('Polygon: the positions invalid') | |||||
| } | |||||
| super() | super() | ||||
| this._delegate = new Cesium.Entity({ polygon: {} }) | |||||
| this._positions = Parse.parsePositions(positions) | this._positions = Parse.parsePositions(positions) | ||||
| this._holes = [] | this._holes = [] | ||||
| this._delegate = new Cesium.Entity() | |||||
| this.type = Overlay.getOverlayType('polygon') | this.type = Overlay.getOverlayType('polygon') | ||||
| this._state = State.INITIALIZED | this._state = State.INITIALIZED | ||||
| } | } | ||||
| set positions(positions) { | set positions(positions) { | ||||
| if (!Util.checkPositions(positions)) { | |||||
| throw new Error('Polygon: the positions invalid') | |||||
| } | |||||
| this._positions = Parse.parsePositions(positions) | this._positions = Parse.parsePositions(positions) | ||||
| this._delegate.polygon.hierarchy = this._prepareHierarchy() | |||||
| return this | |||||
| } | } | ||||
| get positions() { | get positions() { | ||||
| set holes(holes) { | set holes(holes) { | ||||
| if (holes && holes.length) { | if (holes && holes.length) { | ||||
| this._holes = holes.map(item => Parse.parsePositions(item)) | this._holes = holes.map(item => Parse.parsePositions(item)) | ||||
| this._delegate.polygon.hierarchy = this._prepareHierarchy() | |||||
| } | } | ||||
| return this | |||||
| } | } | ||||
| get holes() { | get holes() { | ||||
| /** | /** | ||||
| * initialize the Overlay parameter | * initialize the Overlay parameter | ||||
| */ | */ | ||||
| this._delegate.polygon = { | |||||
| ...this._style, | |||||
| hierarchy: new Cesium.CallbackProperty(time => { | |||||
| return this._prepareHierarchy() | |||||
| }) | |||||
| } | |||||
| this.positions = this._positions | |||||
| } | } | ||||
| /** | /** | ||||
| if (!style || Object.keys(style).length === 0) { | if (!style || Object.keys(style).length === 0) { | ||||
| return this | return this | ||||
| } | } | ||||
| delete style['positions'] | |||||
| this._style = style | this._style = style | ||||
| this._delegate.polygon && Util.merge(this._delegate.polygon, this._style) | |||||
| Util.merge(this._delegate.polygon, this._style) | |||||
| return this | return this | ||||
| } | } | ||||
| ...entity.properties.getValue(now) | ...entity.properties.getValue(now) | ||||
| } | } | ||||
| } | } | ||||
| return polygon | return polygon | ||||
| } | } | ||||
| } | } |
| * @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-06-03 13:52:44 | |||||
| * @Last Modified time: 2020-06-04 22:05:39 | |||||
| */ | */ | ||||
| import { Util } from '../../utils' | import { Util } from '../../utils' | ||||
| class Polyline extends Overlay { | class Polyline extends Overlay { | ||||
| constructor(positions) { | constructor(positions) { | ||||
| if (!Util.checkPositions(positions)) { | |||||
| throw new Error('Polyline: the positions invalid') | |||||
| } | |||||
| super() | super() | ||||
| this._positions = Parse.parsePositions(positions) | this._positions = Parse.parsePositions(positions) | ||||
| this._delegate = new Cesium.Entity() | |||||
| this._delegate = new Cesium.Entity({ polyline: {} }) | |||||
| this.type = Overlay.getOverlayType('polyline') | this.type = Overlay.getOverlayType('polyline') | ||||
| this._state = State.INITIALIZED | this._state = State.INITIALIZED | ||||
| } | } | ||||
| set positions(positions) { | set positions(positions) { | ||||
| if (!Util.checkPositions(positions)) { | |||||
| throw new Error('Polyline: the positions invalid') | |||||
| } | |||||
| this._positions = Parse.parsePositions(positions) | this._positions = Parse.parsePositions(positions) | ||||
| this._delegate.polyline.positions = Transform.transformWGS84ArrayToCartesianArray( | |||||
| this._positions | |||||
| ) | |||||
| return this | |||||
| } | } | ||||
| get positions() { | get positions() { | ||||
| /** | /** | ||||
| * initialize the Overlay parameter | * initialize the Overlay parameter | ||||
| */ | */ | ||||
| this._delegate.polyline = { | |||||
| ...this._style, | |||||
| positions: new Cesium.CallbackProperty(time => { | |||||
| return Transform.transformWGS84ArrayToCartesianArray(this._positions) | |||||
| }) | |||||
| } | |||||
| this.positions = this._positions | |||||
| } | } | ||||
| /** | /** | ||||
| * @param {*} style | * @param {*} style | ||||
| */ | */ | ||||
| setStyle(style) { | setStyle(style) { | ||||
| if (Object.keys(style).length == 0) { | |||||
| if (!style || Object.keys(style).length === 0) { | |||||
| return this | return this | ||||
| } | } | ||||
| delete style['positions'] | |||||
| this._style = style | this._style = style | ||||
| this._delegate.polyline && Util.merge(this._delegate.polyline, this._style) | |||||
| Util.merge(this._delegate.polyline, this._style) | |||||
| return this | return this | ||||
| } | } | ||||
| * @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-05-19 22:05:56 | |||||
| * @Last Modified time: 2020-06-04 22:01:23 | |||||
| */ | */ | ||||
| export { default as OverlayType } from './OverlayType' | export { default as OverlayType } from './OverlayType' | ||||
| export { default as Overlay } from './Overlay' | export { default as Overlay } from './Overlay' |
| * @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-06-03 13:52:52 | |||||
| * @Last Modified time: 2020-06-04 22:37:20 | |||||
| */ | */ | ||||
| import { Util } from '../../utils' | import { Util } from '../../utils' | ||||
| import Transform from '../../transform/Transform' | import Transform from '../../transform/Transform' | ||||
| import Parse from '../../parse/Parse' | |||||
| import State from '../../state/State' | import State from '../../state/State' | ||||
| import Overlay from '../Overlay' | import Overlay from '../Overlay' | ||||
| class Model extends Overlay { | class Model extends Overlay { | ||||
| constructor(position, modelUrl) { | constructor(position, modelUrl) { | ||||
| if (!Util.checkPosition(position)) { | |||||
| throw new Error('Model: the position invalid') | |||||
| } | |||||
| super() | super() | ||||
| this._position = position | |||||
| this._delegate = new Cesium.Entity({ model: {} }) | |||||
| this._position = Parse.parsePosition(position) | |||||
| this._modelUrl = modelUrl | this._modelUrl = modelUrl | ||||
| this._delegate = new Cesium.Entity() | |||||
| this._rotateAmount = 0 | this._rotateAmount = 0 | ||||
| this.type = Overlay.getOverlayType('model') | this.type = Overlay.getOverlayType('model') | ||||
| this._state = State.INITIALIZED | this._state = State.INITIALIZED | ||||
| } | } | ||||
| set position(position) { | 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() { | get position() { | ||||
| set modelUrl(modelUrl) { | set modelUrl(modelUrl) { | ||||
| this._modelUrl = modelUrl | this._modelUrl = modelUrl | ||||
| this._delegate.model.uri = this._modelUrl | |||||
| return this | |||||
| } | } | ||||
| get modelUrl() { | get modelUrl() { | ||||
| } | } | ||||
| set rotateAmount(amount) { | 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() { | get rotateAmount() { | ||||
| /** | /** | ||||
| * set the location | * 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 | * initialize the Overlay parameter | ||||
| */ | */ | ||||
| this._delegate.model = { | |||||
| ...this._style, | |||||
| uri: new Cesium.CallbackProperty(time => { | |||||
| return this._modelUrl | |||||
| }) | |||||
| } | |||||
| this.modelUrl = this._modelUrl | |||||
| } | } | ||||
| /** | /** | ||||
| * @param {*} style | * @param {*} style | ||||
| */ | */ | ||||
| setStyle(style) { | setStyle(style) { | ||||
| if (Object.keys(style).length == 0) { | |||||
| if (!style || Object.keys(style).length === 0) { | |||||
| return this | return this | ||||
| } | } | ||||
| this._style = style | this._style = style | ||||
| this._delegate.model && Util.merge(this._delegate.model, this._style) | |||||
| Util.merge(this._delegate.model, this._style) | |||||
| return this | return this | ||||
| } | } | ||||
| * @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-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 State from '../../state/State' | ||||
| import Overlay from '../Overlay' | import Overlay from '../Overlay' | ||||
| * @param {*} position | * @param {*} position | ||||
| */ | */ | ||||
| setPosition(position) { | setPosition(position) { | ||||
| if (!Util.checkPosition(position)) { | |||||
| return this | |||||
| } | |||||
| position = Parse.parsePosition(position) | |||||
| this._delegate.readyPromise.then(tileset => { | this._delegate.readyPromise.then(tileset => { | ||||
| let modelMatrix = Cesium.Transforms.eastNorthUpToFixedFrame( | let modelMatrix = Cesium.Transforms.eastNorthUpToFixedFrame( | ||||
| Cesium.Cartesian3.fromDegrees(position.lng, position.lat, position.alt) | Cesium.Cartesian3.fromDegrees(position.lng, position.lat, position.alt) | ||||
| setStyle(style) { | setStyle(style) { | ||||
| if (style && style instanceof Cesium.Cesium3DTileStyle) { | if (style && style instanceof Cesium.Cesium3DTileStyle) { | ||||
| this._style = style | this._style = style | ||||
| this._delegate && (this._delegate.style = this._style) | |||||
| this._delegate.style = this._style | |||||
| } | } | ||||
| return this | return this | ||||
| } | } |