Sfoglia il codice sorgente

Revert "add fps and ms #92"

This reverts commit 1f53f1a887.
tags/2.12.0
Caven Chen 3 anni fa
parent
commit
4bb1dc30ff
2 ha cambiato i file con 15 aggiunte e 59 eliminazioni
  1. 1
    7
      modules/themes/locationbar.scss
  2. 14
    52
      modules/widget/type/LocationBar.js

+ 1
- 7
modules/themes/locationbar.scss Vedi File

@@ -13,16 +13,10 @@
margin: 0 8px;
display: inline-block;
}
.mouse-bar{
.mouse-location{
span{
min-width: 100px;
}
}

.ms-bar,.fps-bar{
span{
min-width: 70px;
}
}

}

+ 14
- 52
modules/widget/type/LocationBar.js Vedi File

@@ -15,15 +15,9 @@ class LocationBar extends Widget {
this._wrapper = DomUtil.create('div', 'dc-location-bar')
this._mouseEl = undefined
this._cameraEl = undefined
this._fpsEl = undefined
this._msEl = undefined
this._lastMouseSampleTime = Cesium.getTimestamp()
this._lastCameraSampleTime = Cesium.getTimestamp()
this._lastFpsSampleTime = Cesium.getTimestamp()
this._lastMsSampleTime = Cesium.getTimestamp()
this._fpsFrameCount = 0
this._msFrameCount = 0
this._state = State.INITIALIZED
this._lastMouseUpdate = Cesium.getTimestamp()
this._lastCameraUpdate = Cesium.getTimestamp()
}

get type() {
@@ -46,9 +40,8 @@ class LocationBar extends Widget {
* @private
*/
_bindEvent() {
this._viewer.on(MouseEventType.MOUSE_MOVE, this._onMove, this)
this._viewer.on(SceneEventType.CAMERA_CHANGED, this._onCameraChanged, this)
this._viewer.on(SceneEventType.POST_UPDATE, this._onPostUpdate, this)
this._viewer.on(MouseEventType.MOUSE_MOVE, this._moveHandler, this)
this._viewer.on(SceneEventType.CAMERA_CHANGED, this._cameraHandler, this)
}

/**
@@ -56,9 +49,8 @@ class LocationBar extends Widget {
* @private
*/
_unbindEvent() {
this._viewer.off(MouseEventType.MOUSE_MOVE, this._onMove, this)
this._viewer.off(SceneEventType.CAMERA_CHANGED, this._onCameraChanged, this)
this._viewer.off(SceneEventType.POST_UPDATE, this._onPostUpdate, this)
this._viewer.off(MouseEventType.MOUSE_MOVE, this._moveHandler, this)
this._viewer.off(SceneEventType.CAMERA_CHANGED, this._cameraHandler, this)
}

/**
@@ -66,10 +58,8 @@ class LocationBar extends Widget {
* @private
*/
_mountContent() {
this._mouseEl = DomUtil.create('div', 'mouse-bar', this._wrapper)
this._cameraEl = DomUtil.create('div', 'camera-bar', this._wrapper)
this._msEl = DomUtil.create('div', 'ms-bar', this._wrapper)
this._fpsEl = DomUtil.create('div', 'fbs-bar', this._wrapper)
this._mouseEl = DomUtil.create('div', 'mouse-location', this._wrapper)
this._cameraEl = DomUtil.create('div', 'camera-location', this._wrapper)
this._ready = true
}

@@ -78,11 +68,12 @@ class LocationBar extends Widget {
* @param e
* @private
*/
_onMove(e) {
_moveHandler(e) {
let now = Cesium.getTimestamp()
if (now < this._lastMouseSampleTime + 300) {
if (now < this._lastMouseUpdate + 300) {
return
}
this._lastMouseUpdate = now
let ellipsoid = Cesium.Ellipsoid.WGS84
let cartographic = e.surfacePosition
? ellipsoid.cartesianToCartographic(e.surfacePosition)
@@ -96,52 +87,23 @@ class LocationBar extends Widget {
<span>经度:${lng.toFixed(8)}</span>
<span>纬度:${lat.toFixed(8)}</span>
<span>海拔:${alt.toFixed(2)} 米</span>`
this._lastMouseSampleTime = now
}

/**
*
* @private
*/
_onCameraChanged() {
_cameraHandler() {
let now = Cesium.getTimestamp()
if (now < this._lastCameraSampleTime + 300) {
if (now < this._lastCameraUpdate + 300) {
return
}
this._lastCameraUpdate = now
let cameraPosition = this._viewer.cameraPosition
this._cameraEl.innerHTML = `
<span>视角:${(+cameraPosition.pitch).toFixed(2)}</span>
<span>视高:${(+cameraPosition.alt).toFixed(2)} 米</span>
`
this._lastCameraSampleTime = now
}

/**
*
* @private
*/
_onPostUpdate() {
let now = Cesium.getTimestamp()

// ms
this._msFrameCount++
let msElapsedTime = now - this._lastMsSampleTime
if (msElapsedTime > 200) {
let ms = (msElapsedTime / this._msFrameCount).toFixed(2)
this._msEl.innerHTML = `<span>${ms} MS</span>`
this._lastMsSampleTime = now
this._msFrameCount = 0
}

// fps
this._fpsFrameCount++
let fpsElapsedTime = now - this._lastFpsSampleTime
if (fpsElapsedTime > 1000) {
let fps = ((this._fpsFrameCount * 1000) / fpsElapsedTime) | 0
this._fpsEl.innerHTML = `<span>${fps} FPS</span>`
this._lastFpsSampleTime = now
this._fpsFrameCount = 0
}
}
}


Loading…
Annulla
Salva