| @@ -2,7 +2,7 @@ | |||
| * @Author: Caven | |||
| * @Date: 2019-12-27 17:18:52 | |||
| * @Last Modified by: Caven | |||
| * @Last Modified time: 2020-02-29 00:48:55 | |||
| * @Last Modified time: 2020-03-22 00:18:59 | |||
| */ | |||
| import './const' | |||
| @@ -13,4 +13,5 @@ import './overlay' | |||
| import './terrain/DC.TerrainFactory' | |||
| import './position/DC.Position' | |||
| import './transform/DC.T' | |||
| import './parse/DC.P' | |||
| import './viewer/DC.Viewer' | |||
| @@ -2,7 +2,7 @@ | |||
| * @Author: Caven | |||
| * @Date: 2020-01-21 15:54:56 | |||
| * @Last Modified by: Caven | |||
| * @Last Modified time: 2020-03-05 22:00:03 | |||
| * @Last Modified time: 2020-03-21 23:52:50 | |||
| */ | |||
| import Cesium from '@/namespace' | |||
| import AmapImageryProvider from './provider/AmapImageryProvider' | |||
| @@ -2,7 +2,7 @@ | |||
| * @Author: Caven | |||
| * @Date: 2020-01-19 10:18:23 | |||
| * @Last Modified by: Caven | |||
| * @Last Modified time: 2020-03-14 14:03:54 | |||
| * @Last Modified time: 2020-03-22 00:19:03 | |||
| */ | |||
| import Cesium from '@/namespace' | |||
| @@ -2,7 +2,7 @@ | |||
| * @Author: Caven | |||
| * @Date: 2020-01-31 18:57:02 | |||
| * @Last Modified by: Caven | |||
| * @Last Modified time: 2020-03-20 12:32:05 | |||
| * @Last Modified time: 2020-03-22 00:39:02 | |||
| */ | |||
| import Cesium from '@/namespace' | |||
| import Overlay from '../Overlay' | |||
| @@ -2,7 +2,7 @@ | |||
| * @Author: Caven | |||
| * @Date: 2020-01-09 09:10:37 | |||
| * @Last Modified by: Caven | |||
| * @Last Modified time: 2020-03-06 17:02:29 | |||
| * @Last Modified time: 2020-03-22 00:45:08 | |||
| */ | |||
| import Overlay from '../Overlay' | |||
| import Cesium from '@/namespace' | |||
| @@ -16,16 +16,15 @@ DC.Polygon = class extends Overlay { | |||
| throw new Error('the positions invalid') | |||
| } | |||
| super() | |||
| this._positions = this._preparePositions(positions) | |||
| this._positions = DC.P.parsePositions(positions) | |||
| this._holes = [] | |||
| this._delegate = new Cesium.Entity() | |||
| this._state = DC.OverlayState.INITIALIZED | |||
| this.type = DC.OverlayType.POLYGON | |||
| } | |||
| set positions(positions) { | |||
| this._positions = this._preparePositions(positions) | |||
| this._positions = DC.P.parsePositions(positions) | |||
| } | |||
| get positions() { | |||
| @@ -34,7 +33,7 @@ DC.Polygon = class extends Overlay { | |||
| set holes(holes) { | |||
| if (holes && holes.length) { | |||
| this._holes = holes.map(item => this._preparePositions(item)) | |||
| this._holes = holes.map(item => DC.P.parsePositions(item)) | |||
| } | |||
| } | |||
| @@ -71,26 +70,8 @@ DC.Polygon = class extends Overlay { | |||
| } | |||
| /** | |||
| * prepare entity | |||
| * | |||
| */ | |||
| _preparePositions(positions) { | |||
| if (typeof positions === 'string') { | |||
| if (positions.indexOf('#') >= 0) { | |||
| throw new Error('the positions invalid') | |||
| } | |||
| positions = positions.split(';') | |||
| } | |||
| return positions.map(item => { | |||
| if (Array.isArray(item)) { | |||
| return DC.Position.fromCoordArray(item) | |||
| } else if (item instanceof DC.Position) { | |||
| return item | |||
| } else { | |||
| return DC.Position.fromCoordString(item) | |||
| } | |||
| }) | |||
| } | |||
| _prepareHierarchy() { | |||
| let result = new Cesium.PolygonHierarchy() | |||
| result.positions = DC.T.transformWSG84ArrayToCartesianArray(this._positions) | |||
| @@ -2,7 +2,7 @@ | |||
| * @Author: Caven | |||
| * @Date: 2020-01-06 15:03:25 | |||
| * @Last Modified by: Caven | |||
| * @Last Modified time: 2020-03-06 17:02:38 | |||
| * @Last Modified time: 2020-03-22 00:43:10 | |||
| */ | |||
| import Overlay from '../Overlay' | |||
| @@ -17,15 +17,14 @@ DC.Polyline = class extends Overlay { | |||
| throw new Error('the positions invalid') | |||
| } | |||
| super() | |||
| this._positions = [] | |||
| this._preparePositions(positions) | |||
| this._positions = DC.P.parsePositions(positions) | |||
| this._delegate = new Cesium.Entity() | |||
| this._state = DC.OverlayState.INITIALIZED | |||
| this.type = DC.OverlayType.POLYLINE | |||
| } | |||
| set positions(positions) { | |||
| this._preparePositions(positions) | |||
| this._positions = DC.P.parsePositions(positions) | |||
| } | |||
| get positions() { | |||
| @@ -60,24 +59,6 @@ DC.Polyline = class extends Overlay { | |||
| 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 if (item instanceof DC.Position) { | |||
| return item | |||
| } else { | |||
| return DC.Position.fromCoordString(item) | |||
| } | |||
| }) | |||
| } | |||
| /** | |||
| * prepare entity | |||
| */ | |||
| @@ -0,0 +1,25 @@ | |||
| /* | |||
| * @Author: Caven | |||
| * @Date: 2020-03-22 00:10:25 | |||
| * @Last Modified by: Caven | |||
| * @Last Modified time: 2020-03-22 00:47:45 | |||
| */ | |||
| DC.P = class { | |||
| static parsePositions(positions) { | |||
| if (typeof positions === 'string') { | |||
| if (positions.indexOf('#') >= 0) { | |||
| throw new Error('the positions invalid') | |||
| } | |||
| positions = positions.split(';') | |||
| } | |||
| return positions.map(item => { | |||
| if (Array.isArray(item)) { | |||
| return DC.Position.fromCoordArray(item) | |||
| } else if (item instanceof DC.Position) { | |||
| return item | |||
| } else { | |||
| return DC.Position.fromCoordString(item) | |||
| } | |||
| }) | |||
| } | |||
| } | |||
| @@ -2,17 +2,19 @@ | |||
| * @Author: Caven | |||
| * @Date: 2019-12-27 14:35:02 | |||
| * @Last Modified by: Caven | |||
| * @Last Modified time: 2020-03-16 16:25:20 | |||
| * @Last Modified time: 2020-03-22 00:15:31 | |||
| */ | |||
| import Cesium from '@/namespace' | |||
| 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 | |||
| constructor(lng, lat, alt, heading, pitch, roll) { | |||
| this._lng = lng || 0 | |||
| this._lat = lat || 0 | |||
| this._alt = alt || 0 | |||
| this._heading = heading || 0 | |||
| this._pitch = pitch || 0 | |||
| this._roll = roll || 0 | |||
| } | |||
| set lng(lng) { | |||
| @@ -75,6 +77,20 @@ DC.Position = class { | |||
| return JSON.stringify(position) | |||
| } | |||
| /** | |||
| * | |||
| * @param {*} target | |||
| */ | |||
| distance(target) { | |||
| if (!target || !(target instanceof DC.Position)) { | |||
| return 0 | |||
| } | |||
| return Cesium.Cartesian3.distance( | |||
| DC.T.transformWSG84ToCartesian(this), | |||
| DC.T.transformWSG84ToCartesian(target) | |||
| ) | |||
| } | |||
| /** | |||
| * | |||
| * @param {*} src | |||
| @@ -91,6 +107,7 @@ DC.Position = class { | |||
| } | |||
| return position | |||
| } | |||
| /** | |||
| * | |||
| * @param {*} valStr | |||
| @@ -110,19 +127,22 @@ DC.Position = class { | |||
| return position | |||
| } | |||
| /** | |||
| * | |||
| * @param {*} str | |||
| */ | |||
| 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 | |||
| } | |||
| position = this.fromCoordArray(str.split(',')) | |||
| } | |||
| return position | |||
| } | |||
| /** | |||
| * | |||
| * @param {*} arr | |||
| */ | |||
| static fromCoordArray(arr) { | |||
| let position = new DC.Position() | |||
| if (Array.isArray(arr)) { | |||
| @@ -2,7 +2,7 @@ | |||
| * @Author: Caven | |||
| * @Date: 2019-12-31 17:50:13 | |||
| * @Last Modified by: Caven | |||
| * @Last Modified time: 2020-03-19 13:27:27 | |||
| * @Last Modified time: 2020-03-22 01:00:54 | |||
| */ | |||
| /** | |||
| @@ -11,6 +11,33 @@ | |||
| * https://github.com/Leaflet/Leaflet/tree/master/src/core | |||
| */ | |||
| DC.DomUtil = class { | |||
| /** | |||
| * @function get(id: String|HTMLElement): HTMLElement | |||
| * Returns an element given its DOM id, or returns the element itself | |||
| * if it was passed directly. | |||
| * @param {*} id | |||
| */ | |||
| static get(id) { | |||
| return typeof id === 'string' ? document.getElementById(id) : id | |||
| } | |||
| /** | |||
| * @function getStyle(el: HTMLElement, styleAttrib: String): String | |||
| * Returns the value for a certain style attribute on an element, | |||
| * including computed values or values set through CSS. | |||
| * @param {*} el | |||
| * @param {*} style | |||
| */ | |||
| static getStyle(el, style) { | |||
| var value = el.style[style] || (el.currentStyle && el.currentStyle[style]) | |||
| if ((!value || value === 'auto') && document.defaultView) { | |||
| var css = document.defaultView.getComputedStyle(el, null) | |||
| value = css ? css[style] : null | |||
| } | |||
| return value === 'auto' ? null : value | |||
| } | |||
| /** | |||
| * | |||
| * @param {*} tagName | |||
| @@ -50,6 +77,23 @@ DC.DomUtil = class { | |||
| } | |||
| } | |||
| /** | |||
| * @function hasClass(el: HTMLElement, name: String): Boolean | |||
| * Returns `true` if the element's class attribute contains `name`. | |||
| * @param {*} el | |||
| * @param {*} name | |||
| */ | |||
| hasClass(el, name) { | |||
| if (el.classList !== undefined) { | |||
| return el.classList.contains(name) | |||
| } | |||
| var className = getClass(el) | |||
| return ( | |||
| className.length > 0 && | |||
| new RegExp('(^|\\s)' + name + '(\\s|$)').test(className) | |||
| ) | |||
| } | |||
| /** | |||
| * | |||
| * @param {*} el | |||
| @@ -2,10 +2,12 @@ | |||
| * @Author: Caven | |||
| * @Date: 2019-12-31 17:58:01 | |||
| * @Last Modified by: Caven | |||
| * @Last Modified time: 2020-01-31 15:08:11 | |||
| * @Last Modified time: 2020-03-22 01:03:49 | |||
| */ | |||
| const CHARS = '0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz'.split('') | |||
| const CHARS = '0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz'.split( | |||
| '' | |||
| ) | |||
| /** | |||
| * 工具类 | |||
| * 部分代码借鉴leaflet | |||
| @@ -13,9 +15,9 @@ const CHARS = '0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz'.s | |||
| */ | |||
| DC.Util = class { | |||
| /** | |||
| * | |||
| * @param {*} prefix | |||
| * generate uuid | |||
| * @param {*} prefix | |||
| * | |||
| */ | |||
| static uuid(prefix = 'D') { | |||
| let uuid = [] | |||
| @@ -33,9 +35,10 @@ DC.Util = class { | |||
| /** | |||
| * | |||
| * Merges the properties of the `src` object (or multiple objects) into `dest` object and returns the latter. | |||
| * @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) { | |||
| @@ -51,19 +54,38 @@ DC.Util = class { | |||
| /** | |||
| * | |||
| * @param {*} str | |||
| * @function trim(str: String): String | |||
| * Compatibility polyfill for [String.prototype.trim](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String/Trim) | |||
| * @param {*} str | |||
| * | |||
| */ | |||
| static trim(str) { | |||
| return str.trim ? str.trim() : str.replace(/^\s+|\s+$/g, '') | |||
| } | |||
| /** | |||
| * | |||
| * @function splitWords(str: String): String[] | |||
| * Trims and splits the string on whitespace and returns the array of parts. | |||
| * @param {*} str | |||
| * Trims and splits the string on whitespace and returns the array of parts. | |||
| * | |||
| */ | |||
| static splitWords(str) { | |||
| return this.trim(str).split(/\s+/) | |||
| } | |||
| /** | |||
| * @function setOptions(obj: Object, options: Object): Object | |||
| * Merges the given properties to the `options` of the `obj` object, returning the resulting options. See `Class options`. | |||
| * @param {*} obj | |||
| * @param {*} options | |||
| */ | |||
| static setOptions(obj, options) { | |||
| if (!obj.hasOwnProperty('options')) { | |||
| obj.options = obj.options ? create(obj.options) : {} | |||
| } | |||
| for (var i in options) { | |||
| obj.options[i] = options[i] | |||
| } | |||
| return obj.options | |||
| } | |||
| } | |||
| @@ -2,7 +2,7 @@ | |||
| * @Author: Caven | |||
| * @Date: 2020-02-12 21:43:33 | |||
| * @Last Modified by: Caven | |||
| * @Last Modified time: 2020-02-29 18:12:48 | |||
| * @Last Modified time: 2020-03-21 23:52:31 | |||
| */ | |||
| import Cesium from '@/namespace' | |||
| @@ -2,7 +2,7 @@ | |||
| * @Author: Caven | |||
| * @Date: 2020-02-13 20:19:54 | |||
| * @Last Modified by: Caven | |||
| * @Last Modified time: 2020-03-03 22:30:35 | |||
| * @Last Modified time: 2020-03-21 12:46:56 | |||
| */ | |||
| import Layer from '@/core/layer/Layer' | |||