Browse Source

添加公用方法

tags/1.0.0
Caven 5 years ago
parent
commit
2789fa2d2c

+ 2
- 1
src/core/DC.Loader.js View File

* @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-02-29 00:48:55
* @Last Modified time: 2020-03-22 00:18:59
*/ */


import './const' import './const'
import './terrain/DC.TerrainFactory' import './terrain/DC.TerrainFactory'
import './position/DC.Position' import './position/DC.Position'
import './transform/DC.T' import './transform/DC.T'
import './parse/DC.P'
import './viewer/DC.Viewer' import './viewer/DC.Viewer'

+ 1
- 1
src/core/imagery/DC.ImageryLayerFactory.js View File

* @Author: Caven * @Author: Caven
* @Date: 2020-01-21 15:54:56 * @Date: 2020-01-21 15:54:56
* @Last Modified by: Caven * @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 Cesium from '@/namespace'
import AmapImageryProvider from './provider/AmapImageryProvider' import AmapImageryProvider from './provider/AmapImageryProvider'

+ 1
- 1
src/core/overlay/base/DC.Billboard.js View File

* @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-03-14 14:03:54
* @Last Modified time: 2020-03-22 00:19:03
*/ */


import Cesium from '@/namespace' import Cesium from '@/namespace'

+ 1
- 1
src/core/overlay/base/DC.Cricle.js View File

* @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-03-20 12:32:05
* @Last Modified time: 2020-03-22 00:39:02
*/ */
import Cesium from '@/namespace' import Cesium from '@/namespace'
import Overlay from '../Overlay' import Overlay from '../Overlay'

+ 5
- 24
src/core/overlay/base/DC.Polygon.js View File

* @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-03-06 17:02:29
* @Last Modified time: 2020-03-22 00:45:08
*/ */
import Overlay from '../Overlay' import Overlay from '../Overlay'
import Cesium from '@/namespace' import Cesium from '@/namespace'
throw new Error('the positions invalid') throw new Error('the positions invalid')
} }
super() super()
this._positions = this._preparePositions(positions)
this._positions = DC.P.parsePositions(positions)
this._holes = [] this._holes = []

this._delegate = new Cesium.Entity() this._delegate = new Cesium.Entity()
this._state = DC.OverlayState.INITIALIZED this._state = DC.OverlayState.INITIALIZED
this.type = DC.OverlayType.POLYGON this.type = DC.OverlayType.POLYGON
} }


set positions(positions) { set positions(positions) {
this._positions = this._preparePositions(positions)
this._positions = DC.P.parsePositions(positions)
} }


get positions() { get positions() {


set holes(holes) { set holes(holes) {
if (holes && holes.length) { if (holes && holes.length) {
this._holes = holes.map(item => this._preparePositions(item))
this._holes = holes.map(item => DC.P.parsePositions(item))
} }
} }


} }


/** /**
* 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() { _prepareHierarchy() {
let result = new Cesium.PolygonHierarchy() let result = new Cesium.PolygonHierarchy()
result.positions = DC.T.transformWSG84ArrayToCartesianArray(this._positions) result.positions = DC.T.transformWSG84ArrayToCartesianArray(this._positions)

+ 3
- 22
src/core/overlay/base/DC.Polyline.js View File

* @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-03-06 17:02:38
* @Last Modified time: 2020-03-22 00:43:10
*/ */


import Overlay from '../Overlay' import Overlay from '../Overlay'
throw new Error('the positions invalid') throw new Error('the positions invalid')
} }
super() super()
this._positions = []
this._preparePositions(positions)
this._positions = DC.P.parsePositions(positions)
this._delegate = new Cesium.Entity() this._delegate = new Cesium.Entity()
this._state = DC.OverlayState.INITIALIZED this._state = DC.OverlayState.INITIALIZED
this.type = DC.OverlayType.POLYLINE this.type = DC.OverlayType.POLYLINE
} }


set positions(positions) { set positions(positions) {
this._preparePositions(positions)
this._positions = DC.P.parsePositions(positions)
} }


get positions() { get positions() {
return result > 0 ? result.toFixed(2) : result 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 * prepare entity
*/ */

+ 25
- 0
src/core/parse/DC.P.js View File

/*
* @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)
}
})
}
}

+ 34
- 14
src/core/position/DC.Position.js View File

* @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-03-16 16:25:20
* @Last Modified time: 2020-03-22 00:15:31
*/ */


import Cesium from '@/namespace'

DC.Position = class { 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) { set lng(lng) {
return JSON.stringify(position) 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 * @param {*} src
} }
return position return position
} }

/** /**
* *
* @param {*} valStr * @param {*} valStr
return position return position
} }


/**
*
* @param {*} str
*/
static fromCoordString(str) { static fromCoordString(str) {
let position = new DC.Position() let position = new DC.Position()
if (str && typeof str === 'string') { 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 return position
} }


/**
*
* @param {*} arr
*/
static fromCoordArray(arr) { static fromCoordArray(arr) {
let position = new DC.Position() let position = new DC.Position()
if (Array.isArray(arr)) { if (Array.isArray(arr)) {

+ 45
- 1
src/core/utils/DC.DomUtil.js View File

* @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-03-19 13:27:27
* @Last Modified time: 2020-03-22 01:00:54
*/ */


/** /**
* https://github.com/Leaflet/Leaflet/tree/master/src/core * https://github.com/Leaflet/Leaflet/tree/master/src/core
*/ */
DC.DomUtil = class { 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 * @param {*} tagName
} }
} }


/**
* @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 * @param {*} el

+ 30
- 8
src/core/utils/DC.Util.js View File

* @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-31 15:08:11
* @Last Modified time: 2020-03-22 01:03:49
*/ */


const CHARS = '0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz'.split('')
const CHARS = '0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz'.split(
''
)
/** /**
* 工具类 * 工具类
* 部分代码借鉴leaflet * 部分代码借鉴leaflet
*/ */
DC.Util = class { DC.Util = class {
/** /**
*
* @param {*} prefix
* generate uuid * generate uuid
* @param {*} prefix
*
*/ */
static uuid(prefix = 'D') { static uuid(prefix = 'D') {
let uuid = [] let uuid = []


/** /**
* *
* Merges the properties of the `src` object (or multiple objects) into `dest` object and returns the latter.
* @param {*} dest * @param {*} dest
* @param {*} sources * @param {*} sources
* Merges the properties of the `src` object (or multiple objects) into `dest` object and returns the latter.
*
*/ */


static merge(dest, ...sources) { static merge(dest, ...sources) {


/** /**
* *
* @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) * Compatibility polyfill for [String.prototype.trim](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String/Trim)
* @param {*} str
*
*/ */
static trim(str) { static trim(str) {
return str.trim ? str.trim() : str.replace(/^\s+|\s+$/g, '') 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 * @param {*} str
* Trims and splits the string on whitespace and returns the array of parts.
*
*/ */
static splitWords(str) { static splitWords(str) {
return this.trim(str).split(/\s+/) 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
}
} }

+ 1
- 1
src/plugins/layer/DC.HtmlLayer.js View File

* @Author: Caven * @Author: Caven
* @Date: 2020-02-12 21:43:33 * @Date: 2020-02-12 21:43:33
* @Last Modified by: Caven * @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' import Cesium from '@/namespace'

+ 1
- 1
src/plugins/layer/DC.MapvLayer.js View File

* @Author: Caven * @Author: Caven
* @Date: 2020-02-13 20:19:54 * @Date: 2020-02-13 20:19:54
* @Last Modified by: Caven * @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' import Layer from '@/core/layer/Layer'



Loading…
Cancel
Save