| @@ -11,20 +11,13 @@ export default function distance(positions) { | |||
| let distance = 0 | |||
| if (positions && Array.isArray(positions)) { | |||
| for (let i = 0; i < positions.length - 1; i++) { | |||
| let point1cartographic = Transform.transformWGS84ToCartographic( | |||
| positions[i] | |||
| ) | |||
| let point2cartographic = Transform.transformWGS84ToCartographic( | |||
| positions[i + 1] | |||
| ) | |||
| let c1 = Transform.transformWGS84ToCartographic(positions[i]) | |||
| let c2 = Transform.transformWGS84ToCartographic(positions[i + 1]) | |||
| let geodesic = new Cesium.EllipsoidGeodesic() | |||
| geodesic.setEndPoints(point1cartographic, point2cartographic) | |||
| geodesic.setEndPoints(c1, c2) | |||
| let s = geodesic.surfaceDistance | |||
| s = Math.sqrt( | |||
| Math.pow(s, 2) + | |||
| Math.pow(point2cartographic.height - point1cartographic.height, 2) | |||
| ) | |||
| distance = distance + s | |||
| s = Math.sqrt(Math.pow(s, 2) + Math.pow(c2.height - c1.height, 2)) | |||
| distance += s | |||
| } | |||
| } | |||
| @@ -22,7 +22,7 @@ class DivIcon extends Overlay { | |||
| top: '0', | |||
| left: '0' | |||
| }) | |||
| this.content = content | |||
| this._content = content | |||
| this.type = Overlay.getOverlayType('div_icon') | |||
| this._state = State.INITIALIZED | |||
| } | |||
| @@ -47,6 +47,7 @@ class DivIcon extends Overlay { | |||
| } | |||
| set content(content) { | |||
| this._content = content | |||
| if (content && typeof content === 'string') { | |||
| this._delegate.innerHTML = content | |||
| } else if (content && content instanceof Element) { | |||
| @@ -24,7 +24,7 @@ class Polygon extends Overlay { | |||
| set positions(positions) { | |||
| this._positions = Parse.parsePositions(positions) | |||
| this._delegate.polygon.hierarchy = this._prepareHierarchy() | |||
| this._delegate.polygon.hierarchy = this._computeHierarchy() | |||
| return this | |||
| } | |||
| @@ -35,7 +35,7 @@ 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() | |||
| this._delegate.polygon.hierarchy = this._computeHierarchy() | |||
| } | |||
| return this | |||
| } | |||
| @@ -54,8 +54,9 @@ class Polygon extends Overlay { | |||
| /** | |||
| * | |||
| * @private | |||
| */ | |||
| _prepareHierarchy() { | |||
| _computeHierarchy() { | |||
| let result = new Cesium.PolygonHierarchy() | |||
| result.positions = Transform.transformWGS84ArrayToCartesianArray( | |||
| this._positions | |||
| @@ -36,11 +36,11 @@ class Parse { | |||
| positions = positions.split(';') | |||
| } | |||
| return positions.map(item => { | |||
| if (Array.isArray(item)) { | |||
| if (Array.isArray(item) && item.length) { | |||
| return Position.fromCoordArray(item) | |||
| } else if (item instanceof Position) { | |||
| return item | |||
| } else { | |||
| } else if (typeof item === 'string' && item) { | |||
| return Position.fromCoordString(item) | |||
| } | |||
| }) | |||
| @@ -107,6 +107,33 @@ class Position { | |||
| return position | |||
| } | |||
| /** | |||
| * | |||
| * @returns {string} | |||
| */ | |||
| toString() { | |||
| return `${this.lng},${this.lat},${this.alt},${this.heading},${this.pitch},${this.roll}` | |||
| } | |||
| /** | |||
| * | |||
| * @param str | |||
| * @returns {Position} | |||
| */ | |||
| static fromString(str) { | |||
| let position = new Position() | |||
| if (str && typeof str === 'string') { | |||
| let arr = str.split(',') | |||
| position.lng = arr[0] || 0 | |||
| position.lat = arr[1] || 0 | |||
| position.alt = arr[2] || 0 | |||
| position.heading = arr[3] || 0 | |||
| position.pitch = arr[4] || 0 | |||
| position.roll = arr[5] || 0 | |||
| } | |||
| return position | |||
| } | |||
| /** | |||
| * Deserialize | |||
| * @param valStr | |||
| @@ -124,6 +124,10 @@ class Viewer { | |||
| return this._delegate.dataSources | |||
| } | |||
| get imageryLayers() { | |||
| return this._delegate.imageryLayers | |||
| } | |||
| get entities() { | |||
| return this._delegate.entities | |||
| } | |||
| @@ -361,9 +365,7 @@ class Viewer { | |||
| if (!this._baseLayerPicker.selectedImagery) { | |||
| this._baseLayerPicker.selectedImagery = this._baseLayerPicker.imageryProviderViewModels[0] | |||
| } | |||
| this._comps.mapSwitch.addMap(options) | |||
| return this | |||
| } | |||
| @@ -26,12 +26,12 @@ class ContextMenu extends Widget { | |||
| } | |||
| _bindEvent() { | |||
| this._viewer.on(MouseEventType.RIGHT_CLICK, this._rightclickHandler, this) | |||
| this._viewer.on(MouseEventType.RIGHT_CLICK, this._rightClickHandler, this) | |||
| this._viewer.on(MouseEventType.CLICK, this._clickHandler, this) | |||
| } | |||
| _unbindEvent() { | |||
| this._viewer.off(MouseEventType.RIGHT_CLICK, this._rightclickHandler, this) | |||
| this._viewer.off(MouseEventType.RIGHT_CLICK, this._rightClickHandler, this) | |||
| this._viewer.off(MouseEventType.CLICK, this._clickHandler, this) | |||
| } | |||
| @@ -49,7 +49,7 @@ class ContextMenu extends Widget { | |||
| } | |||
| } | |||
| _rightclickHandler(e) { | |||
| _rightClickHandler(e) { | |||
| if (e && e.windowPosition && this._enable) { | |||
| this._updateWindowCoord(e.windowPosition) | |||
| } | |||
| @@ -46,7 +46,7 @@ class LocationBar extends Widget { | |||
| <span>海拔:${alt.toFixed(2)} 米</span>` | |||
| } | |||
| _cameraHandler(e) { | |||
| _cameraHandler() { | |||
| let cameraPosition = this._viewer.cameraPosition | |||
| this._cameraEl.innerHTML = ` | |||
| <span>视角:${(+cameraPosition.pitch).toFixed(2)}</span> | |||
| @@ -45,7 +45,7 @@ class MapSwitch extends Widget { | |||
| let mapEl = DomUtil.create('div', 'map-item', this._wrapper) | |||
| let index = this._cache.length ? this._cache.length - 1 : 0 | |||
| index === 0 && DomUtil.addClass(mapEl, 'active') | |||
| mapEl.setAttribute('data-index', index) | |||
| mapEl.setAttribute('data-index', String(index)) | |||
| mapEl.onclick = e => { | |||
| let old = document.getElementsByClassName('map-item active') | |||
| if (old && old.length) { | |||
| @@ -76,6 +76,6 @@ class MapSwitch extends Widget { | |||
| } | |||
| } | |||
| Widget.registerType('mapswitch') | |||
| Widget.registerType('map_switch') | |||
| export default MapSwitch | |||