1
1
/** @prettier */
2
2
3
- import { html , css , LitElement } from 'lit' ;
4
- import { customElement , property , state } from 'lit/decorators.js' ;
5
-
6
- // code from https://cesium.com/learn/cesiumjs-learn/cesiumjs-quickstart/
7
- // see Import from CDN vs. Install with NPM
8
- // see also https://www.npmjs.com/package/vite-plugin-cesium
3
+ import { html , css , unsafeCSS , LitElement } from 'lit' ;
4
+ import { customElement , property } from 'lit/decorators.js' ;
9
5
10
6
import * as Cesium from 'cesium' ;
11
- import 'cesium/Build/Cesium/Widgets/widgets.css' ;
12
7
13
- // Your access token can be found at: https://cesium.com/ion/tokens.
14
- // This is the default access token from your ion account
8
+ // This works, tested in dev and in build+preview
9
+ import widgetStylesRaw from 'cesium/Build/Cesium/Widgets/widgets.css' ;
10
+ const widgetStyles = css `
11
+ ${ unsafeCSS ( widgetStylesRaw ) }
12
+ ` ;
15
13
14
+ // Your access token can be found at: https://cesium.com/ion/tokens.
15
+ // This is the default access token from the cesiumjs-quickstart demo
16
16
Cesium . Ion . defaultAccessToken =
17
17
'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJqdGkiOiIwMDY5YjNjNy05ZDZjLTQ5YjUtODBhOC03MGY4Njc3MzUyMDEiLCJpZCI6MTEyNTc3LCJpYXQiOjE2NjY4MTYyNjB9.fd9TA4pMsDaKBWE1lSEBvYB34xR-R1anLfSG-vSVI4c' ;
18
18
19
- // Initialize the Cesium Viewer in the HTML element with the `cesiumContainer` ID.
20
- const viewer = new Cesium . Viewer ( 'cesiumContainer' , {
21
- terrainProvider : Cesium . createWorldTerrain ( ) ,
22
- } ) ;
23
- // Add Cesium OSM Buildings, a global 3D buildings layer.
24
- const buildingTileset = viewer . scene . primitives . add (
25
- Cesium . createOsmBuildings ( )
26
- ) ;
27
-
28
- // Fly the camera to Geneva at the given longitude, latitude, and height.
29
- // viewer.camera.flyTo({
30
- // destination : Cesium.Cartesian3.fromDegrees(-122.4175, 37.655, 400),
31
- // orientation : {
32
- // heading : Cesium.Math.toRadians(0.0),
33
- // pitch : Cesium.Math.toRadians(-15.0),
34
- // }
35
- // });
36
-
37
19
/**
38
20
* Clamp the value to the range [min, max].
39
- * @param {* } value
40
- * @param {* } min
41
- * @param {* } max
21
+ * @param {* } value
22
+ * @param {* } min
23
+ * @param {* } max
42
24
* @returns -- clamped value
43
25
*/
44
26
const clamp = ( value , min , max ) => {
@@ -49,7 +31,6 @@ const clamp = (value, min, max) => {
49
31
50
32
/**
51
33
* Camera position and orientation to fly to.
52
- *
53
34
* @requires -- a `viewer` object.
54
35
*/
55
36
class CameraCoordinates {
@@ -66,7 +47,7 @@ class CameraCoordinates {
66
47
this . height = clamp ( height , 1000 , 40_000_000 ) ;
67
48
}
68
49
69
- flyTo ( ) {
50
+ flyTo ( viewer ) {
70
51
viewer . camera . flyTo ( {
71
52
destination : Cesium . Cartesian3 . fromDegrees (
72
53
this . lngDeg ,
@@ -83,46 +64,74 @@ class CameraCoordinates {
83
64
}
84
65
85
66
/**
86
- * A partial encapsulation of Cesium Viewer custom controls.
67
+ * Encapsulation of Cesium Viewer and custom controls.
87
68
*/
88
- @customElement ( 'cesium-zoomer ' )
89
- export class CesiumZoomer extends LitElement {
69
+ @customElement ( 'cesium-lit ' )
70
+ export class CesiumLit extends LitElement {
90
71
static get styles ( ) {
91
- return css `
72
+ return [
73
+ widgetStyles ,
74
+ css `
92
75
:host {
93
- display: block;
94
- border: solid 1px gray;
76
+ display: block; /* no effect */
95
77
padding: 10px;
96
78
max-width: 100vw;
79
+ max-height: 100vw; /*no effect*/
97
80
font-size: 16px;
98
81
font-family: Helvetica, Arial, sans-serif;
82
+ /* box-sizing: content-box; no effect */
99
83
}
100
84
button {
101
85
font-size: 14px;
102
86
}
103
- ` ;
87
+ #cesiumContainer {
88
+ /* width: 50%; */
89
+ /* width: 100%; */
90
+ /* height: 100%; */ /*does not prevent vertical growth*/
91
+ /* max-width: 100vw; */
92
+ /* max-height: 100vh; prevents vertical growth, vertically incluses all widgets */
93
+ /* width: auto; */
94
+ /* height: auto; */
95
+ /* height: 700px;*/ /*prevents vertical growth */
96
+ background: thistle;
97
+ /* overflow: hidden; not needed */
98
+ border: solid 1px blue;
99
+ }
100
+ .lit-widgets {
101
+ background: hsl(0, 0%, 90%);
102
+ border: solid 1px blue;
103
+ padding: 10px;
104
+ }
105
+ ` ,
106
+ ] ;
104
107
}
105
108
106
109
@property ( ) name = 'Cesium' ;
107
110
108
111
cameraCoordinates = new CameraCoordinates ( ) ;
109
112
110
113
flyTo ( ) {
111
- this . cameraCoordinates . flyTo ( ) ;
114
+ this . cameraCoordinates . flyTo ( this . viewer ) ;
112
115
}
113
116
114
117
firstUpdated ( ) {
118
+ const cesiumContainer = this . renderRoot . getElementById ( 'cesiumContainer' ) ;
119
+ console . log ( `firstUpdated cesiumContainer:` , cesiumContainer ) ;
120
+ this . viewer = new Cesium . Viewer ( cesiumContainer , {
121
+ terrainProvider : Cesium . createWorldTerrain ( ) ,
122
+ } ) ;
115
123
this . flyTo ( ) ;
116
124
}
117
125
118
126
render ( ) {
119
127
return html `
120
- < h3 > Hello, ${ this . name } ! </ h3 >
121
- < div >
128
+ < div class =" lit-widgets " >
129
+ < h3 > Hello, ${ this . name } ! </ h3 >
122
130
< button id ="-- " @click =${ this . _onClick } part ="button"> --</ button >
123
131
< button id ="++ " @click =${ this . _onClick } part ="button"> ++</ button >
124
- height: ${ this . cameraCoordinates . height }
132
+ height: ${ this . cameraCoordinates . height } m
125
133
</ div >
134
+ < div id ="cesiumContainer "> </ div >
126
135
` ;
127
136
}
128
137
0 commit comments