forked from richard1015/cesium-navigation-es6
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathviewerCesiumNavigationMixin.js
82 lines (70 loc) · 2.24 KB
/
viewerCesiumNavigationMixin.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
import { defined, DeveloperError } from 'cesium/Source/Cesium.js'
import CesiumNavigation from './CesiumNavigation'
import './styles/cesium-navigation.css'
/**
* A mixin which adds the Compass/Navigation widget to the Viewer widget.
* Rather than being called directly, this function is normally passed as
* a parameter to {@link Viewer#extend}, as shown in the example below.
* @exports viewerCesiumNavigationMixin
*
* @param {Viewer} viewer The viewer instance.
* @param {{}} options The options.
*
* @exception {DeveloperError} viewer is required.
*
* @demo {@link http://localhost:8080/index.html|run local server with examples}
*
* @example
* var viewer = new Cesium.Viewer('cesiumContainer');
* viewer.extend(viewerCesiumNavigationMixin);
*/
function viewerCesiumNavigationMixin(viewer, options) {
if (!defined(viewer)) {
throw new DeveloperError('viewer is required.')
}
var cesiumNavigation = init(viewer, options)
cesiumNavigation.addOnDestroyListener((function (viewer) {
return function () {
delete viewer.cesiumNavigation
}
})(viewer))
Object.defineProperties(viewer, {
cesiumNavigation: {
configurable: true,
get: function () {
return viewer.cesiumWidget.cesiumNavigation
}
}
})
}
/**
*
* @param {CesiumWidget} cesiumWidget The cesium widget instance.
* @param {{}} options The options.
*/
viewerCesiumNavigationMixin.mixinWidget = function (cesiumWidget, options) {
return init.apply(undefined, arguments)
}
/**
* @param {Viewer|CesiumWidget} viewerCesiumWidget The Viewer or CesiumWidget instance
* @param {{}} options the options
*/
var init = function (viewerCesiumWidget, options) {
var cesiumNavigation = new CesiumNavigation(viewerCesiumWidget, options)
var cesiumWidget = defined(viewerCesiumWidget.cesiumWidget) ? viewerCesiumWidget.cesiumWidget : viewerCesiumWidget
Object.defineProperties(cesiumWidget, {
cesiumNavigation: {
configurable: true,
get: function () {
return cesiumNavigation
}
}
})
cesiumNavigation.addOnDestroyListener((function (cesiumWidget) {
return function () {
delete cesiumWidget.cesiumNavigation
}
})(cesiumWidget))
return cesiumNavigation
}
export default viewerCesiumNavigationMixin