Browse Source

完善比例尺功能

tags/1.13.1
Caven Chen 4 years ago
parent
commit
1bb31f6705
3 changed files with 16 additions and 20 deletions
  1. 3
    3
      src/core/event/SceneEvent.js
  2. 5
    1
      src/core/viewer/Viewer.js
  3. 8
    16
      src/core/widget/DistanceLegend.js

+ 3
- 3
src/core/event/SceneEvent.js View File

@@ -9,9 +9,9 @@ import Event from './Event'
class SceneEvent extends Event {
constructor(viewer) {
super()
this._camera = viewer.delegate.camera
this._scene = viewer.delegate.scene
this._clock = viewer.delegate.clock
this._camera = viewer.camera
this._scene = viewer.scene
this._clock = viewer.clock
}

/**

+ 5
- 1
src/core/viewer/Viewer.js View File

@@ -105,6 +105,10 @@ class Viewer {
return this._delegate.imageryLayers
}

get terrainProvider() {
return this._delegate.terrainProvider
}

get entities() {
return this._delegate.entities
}
@@ -271,7 +275,7 @@ class Viewer {
if (!this._baseLayerPicker.selectedImagery) {
this._baseLayerPicker.selectedImagery = this._baseLayerPicker.imageryProviderViewModels[0]
}
this.mapSwitch.addMap(options)
this.mapSwitch && this.mapSwitch.addMap(options)
return this
}


+ 8
- 16
src/core/widget/DistanceLegend.js View File

@@ -29,7 +29,7 @@ class DistanceLegend extends Widget {
super()
this._wrapper = DomUtil.create('div', 'dc-distance-legend')
this._labelEl = undefined
this._scaleBar = undefined
this._scaleBarEl = undefined
this._lastUpdate = Cesium.getTimestamp()
this.type = Widget.getWidgetType('distance_legend')
this._state = State.INITIALIZED
@@ -51,11 +51,7 @@ class DistanceLegend extends Widget {
* @private
*/
_bindEvent() {
this._viewer.on(
SceneEventType.POST_RENDER,
this._updateDistanceLegend,
this
)
this._viewer.on(SceneEventType.POST_RENDER, this._updateContent, this)
}

/**
@@ -63,11 +59,7 @@ class DistanceLegend extends Widget {
* @private
*/
_unbindEvent() {
this._viewer.off(
SceneEventType.POST_RENDER,
this._updateDistanceLegend,
this
)
this._viewer.off(SceneEventType.POST_RENDER, this._updateContent, this)
}

/**
@@ -77,12 +69,12 @@ class DistanceLegend extends Widget {
* @returns
* @private
*/
_updateDistanceLegend(scene, time) {
_updateContent(scene, time) {
let now = Cesium.getTimestamp()
if (now < this._lastUpdate + 250) {
return
}
if (!this._labelEl || !this._scaleBar) {
if (!this._labelEl || !this._scaleBarEl) {
return
}
this._lastUpdate = now
@@ -116,12 +108,12 @@ class DistanceLegend extends Widget {
this._labelEl.innerHTML =
distance >= 1000 ? `${distance / 1000} km` : `${distance} m`
let barWidth = (distance / pixelDistance) | 0
this._scaleBar.style.cssText = `width: ${barWidth}px; left: ${(125 -
this._scaleBarEl.style.cssText = `width: ${barWidth}px; left: ${(125 -
barWidth) /
2}px;`
} else {
this._labelEl.style.cssText = 'display:none'
this._scaleBar.style.cssText = 'display:none'
this._scaleBarEl.style.cssText = 'display:none'
}
}

@@ -131,7 +123,7 @@ class DistanceLegend extends Widget {
*/
_mountContent() {
this._labelEl = DomUtil.create('div', 'label', this._wrapper)
this._scaleBar = DomUtil.create('div', 'scale-bar', this._wrapper)
this._scaleBarEl = DomUtil.create('div', 'scale-bar', this._wrapper)
this._ready = true
}
}

Loading…
Cancel
Save