@znemz/cesium-navigation 3.0.5 → 6.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -1,101 +1,213 @@
1
- # cesium-navigation
1
+ # @znemz/cesium-navigation
2
2
 
3
- [![NPM version][npm-image]][npm-url] [![Downloads][downloads-image]][npm-url] [![Build Status][travis-image]][travis-url]
3
+ [![npm version](https://badge.fury.io/js/%40znemz%2Fcesium-navigation.svg)](https://www.npmjs.com/package/@znemz/cesium-navigation)
4
+ [![tests](https://github.com/brickhouse-tech/cesium-navigation/actions/workflows/tests.yml/badge.svg)](https://github.com/brickhouse-tech/cesium-navigation/actions/workflows/tests.yml)
4
5
 
5
- This is a Cesium plugin that adds to the Cesium map a user friendly compass, navigator (zoom in/out), and
6
- distance scale graphical user interface.
6
+ Cesium plugin that adds compass, navigator (zoom controls), and distance scale widgets to the map.
7
7
 
8
- This project was forked to provide a stable non-requirejs implementation to be more modern and be publishable to npm. There
9
- is no need to conform to Cesium's insanity of requirejs when tools like webpack and rollup exist.
8
+ **v5.0.0** Fully modernized with TypeScript, Vite, and zero legacy dependencies!
10
9
 
11
- ## How to get it
10
+ ## Features
12
11
 
13
- `yarn install @znemz/cesium-navigation`
12
+ - 🧭 **Compass** - Interactive compass for rotation and orientation
13
+ - 🔍 **Zoom Controls** - In/out zoom buttons
14
+ - 📏 **Distance Scale** - Dynamic distance legend
15
+ - 🎯 **Reset View** - One-click return to default view
16
+ - 📱 **Responsive** - Works on desktop and mobile
17
+ - 🎨 **Customizable** - Configure which controls to display
18
+ - 💪 **TypeScript** - Full type safety
19
+ - 🌲 **Tree-shakeable** - ES modules with zero runtime dependencies
14
20
 
15
- ## Why did you build it
21
+ ## Breaking Changes from v4.x
16
22
 
17
- First of all the Cesiumjs sdk does not include a compass, navigator (zoom in/out) nor distance scale. You can use the mouse to navigate on the map but this navigation plugin offers more navigation control and capabilities to the user.
18
- Some of the capabilities are:
19
- reset the compass to point to north, reset the orbit, and reset the view to a default bound.
23
+ - **Requires Node >= 20**
24
+ - **Requires Cesium >= 1.100**
25
+ - Removed all legacy dependencies (Knockout.js, HammerJS, markdown-it)
26
+ - Native ES modules only (no CommonJS)
27
+ - TypeScript-first API
28
+ - Removed `browser_` field from package.json
20
29
 
21
- ## How to build it
30
+ ## Installation
22
31
 
23
- - run `yarn install`
24
- - run `yarn start` or `yarn build`
32
+ ```bash
33
+ npm install @znemz/cesium-navigation cesium
34
+ ```
25
35
 
26
- ## How did you build it
36
+ ## Usage
27
37
 
28
- This plugin is based on the excellent compass, navigator (zoom in/out) and distance scale from the terriajs open source library (https://github.com/TerriaJS). The navigation UI from terriajs can not be used out of the box in Cesium because Cesium uses AMD modules with RequireJS, and the terriajs uses commonjs and Browserify, so you can't just copy the source files into Cesium and build. My work consisted on adapting the code to work within Cesium as a plugin as follows:
38
+ ### ES Modules (Vite, webpack 5+)
29
39
 
30
- - Extracted the minimum required modules from terriajs.
31
- - Converted all the modules from Browserify to requirejs.
32
- - Using nodejs and the requirejs optimizer as well as almond the whole plugin is built and bundled in a single file even the CSS style
33
- - This plugin can be used as a standalone script or via an AMD loader (tested with requirejs). Even in the special case where you use AMD but not for Cesium the plugin can be easily used.
40
+ ```typescript
41
+ import * as Cesium from 'cesium';
42
+ import { viewerCesiumNavigationMixin } from '@znemz/cesium-navigation';
43
+ import '@znemz/cesium-navigation/style.css';
34
44
 
35
- ## How to use it
45
+ const viewer = new Cesium.Viewer('cesiumContainer');
46
+ viewer.extend(viewerCesiumNavigationMixin, {
47
+ enableCompass: true,
48
+ enableZoomControls: true,
49
+ enableDistanceLegend: true,
50
+ units: 'kilometers' // or 'miles', 'meters', etc.
51
+ });
52
+ ```
36
53
 
37
- See: [Examples](./Examples/index.html)
54
+ ### Direct instantiation
38
55
 
39
- ## Available options of the plugin
56
+ ```typescript
57
+ import { CesiumNavigation } from '@znemz/cesium-navigation';
58
+ import '@znemz/cesium-navigation/style.css';
40
59
 
41
- **defaultResetView** - option used to set a default view when resetting the map view with the reset navigation
42
- control. Values accepted are of type Cesium's Cartographic and Rectangle.
60
+ const viewer = new Cesium.Viewer('cesiumContainer');
61
+ const navigation = new CesiumNavigation(viewer, {
62
+ enableCompass: true,
63
+ enableZoomControls: true,
64
+ enableDistanceLegend: true,
65
+ units: 'kilometers',
66
+ defaultResetView: Cesium.Rectangle.fromDegrees(-180, -90, 180, 90)
67
+ });
43
68
 
44
- **enableCompass** - option used to enable or disable the compass. Values accepted are true for enabling and false to disable. The default is true.
69
+ // Later, clean up
70
+ navigation.destroy();
71
+ ```
45
72
 
46
- **enableZoomControls** - option used to enable or disable the zoom controls. Values accepted are true for enabling and false to disable. The default is true.
73
+ ### TypeScript
47
74
 
48
- **enableDistanceLegend** - option used to enable or disable the distance legend. Values accepted are true for enabling and false to disable. The default is true.
75
+ Full TypeScript support with strict types:
49
76
 
50
- **units** - option used to set the type of units being displayed. Values accepted are turf helpers units ['kilometers', etc...](https://github.com/Turfjs/turf/blob/v5.1.6/packages/turf-helpers/index.d.ts#L20).
77
+ ```typescript
78
+ import type { ViewerWithCesiumNavigation } from '@znemz/cesium-navigation';
51
79
 
52
- **distanceLabelFormatter** - callback function which allows you to override default [distanceLabelFormater](./Source/Core/Utils.js#88). `(convertedDistance: Number, units : Units): string =>`
80
+ const viewer = new Cesium.Viewer('cesiumContainer') as ViewerWithCesiumNavigation;
81
+ viewer.extend(viewerCesiumNavigationMixin);
53
82
 
54
- More options will be set in future releases of the plugin.
83
+ // Type-safe access
84
+ viewer.cesiumNavigation.setNavigationLocked(true);
85
+ ```
55
86
 
56
- Example of using the options when loading Cesium without requirejs:
87
+ ## Configuration Options
88
+
89
+ ```typescript
90
+ interface CesiumNavigationOptions {
91
+ /** Enable or disable the compass control (default: true) */
92
+ enableCompass?: boolean;
93
+
94
+ /** Enable or disable the zoom controls (default: true) */
95
+ enableZoomControls?: boolean;
96
+
97
+ /** Enable or disable the distance legend (default: true) */
98
+ enableDistanceLegend?: boolean;
99
+
100
+ /** Units for distance legend (default: 'kilometers') */
101
+ units?: 'kilometers' | 'meters' | 'miles' | 'feet' | string;
102
+
103
+ /** Default reset view (Rectangle or Cartographic) */
104
+ defaultResetView?: Cesium.Rectangle | Cesium.Cartographic;
105
+
106
+ /** Custom distance label formatter */
107
+ distanceLabelFormatter?: (distance: number, units: string) => string;
108
+ }
109
+ ```
57
110
 
58
- ```JavaScript
59
- import { Rectangle, Viewer } from 'cesium';
111
+ ## Bundler Setup
112
+
113
+ ### Vite
114
+
115
+ ```javascript
116
+ // vite.config.js
117
+ import { defineConfig } from 'vite';
118
+ import cesium from 'vite-plugin-cesium';
119
+
120
+ export default defineConfig({
121
+ plugins: [cesium()]
122
+ });
123
+ ```
60
124
 
61
- const cesiumViewer = new Viewer();
62
- var options = {};
63
- options.defaultResetView = Rectangle.fromDegrees(71, 3, 90, 14);
64
- // Only the compass will show on the map
65
- options.enableCompass = true;
66
- options.enableZoomControls = false;
67
- options.enableDistanceLegend = false;
68
- options.units = 'kilometers' // default is kilometers;
69
- // turf helpers units https://github.com/Turfjs/turf/blob/v5.1.6/packages/turf-helpers/index.d.ts#L20
70
- options.distanceLabelFormatter = (convertedDistance, units : Units): string => { ... } // custom label formatter
71
- cesiumViewer.extend(window.viewerCesiumNavigationMixin, options);
125
+ ### Webpack 5
126
+
127
+ ```javascript
128
+ // webpack.config.js
129
+ const CopyWebpackPlugin = require('copy-webpack-plugin');
130
+ const webpack = require('webpack');
131
+ const path = require('path');
132
+
133
+ module.exports = {
134
+ plugins: [
135
+ new CopyWebpackPlugin({
136
+ patterns: [
137
+ {
138
+ from: 'node_modules/cesium/Build/Cesium/Workers',
139
+ to: 'cesium/Workers'
140
+ },
141
+ {
142
+ from: 'node_modules/cesium/Build/Cesium/ThirdParty',
143
+ to: 'cesium/ThirdParty'
144
+ },
145
+ {
146
+ from: 'node_modules/cesium/Build/Cesium/Assets',
147
+ to: 'cesium/Assets'
148
+ },
149
+ {
150
+ from: 'node_modules/cesium/Build/Cesium/Widgets',
151
+ to: 'cesium/Widgets'
152
+ }
153
+ ]
154
+ }),
155
+ new webpack.DefinePlugin({
156
+ CESIUM_BASE_URL: JSON.stringify('/cesium')
157
+ })
158
+ ]
159
+ };
72
160
  ```
73
161
 
74
- ## Others Stuff
162
+ ## Development
75
163
 
76
- - To destroy the navigation object and release the resources later on use the following
164
+ ```bash
165
+ # Install dependencies
166
+ npm install
77
167
 
78
- ```js
79
- viewer.cesiumNavigation.destroy();
168
+ # Run type checking
169
+ npm run type-check
170
+
171
+ # Build
172
+ npm run build
173
+
174
+ # Run tests
175
+ npm test
176
+
177
+ # Lint
178
+ npm run lint
179
+ npm run lint:fix
180
+ ```
181
+
182
+ ## Migration from v4.x
183
+
184
+ The API surface is largely the same, but with modernized internals:
185
+
186
+ **Before (v4.x):**
187
+ ```javascript
188
+ const viewer = new Cesium.Viewer('cesiumContainer');
189
+ viewer.extend(viewerCesiumNavigationMixin);
80
190
  ```
81
191
 
82
- - To lock the compass and navigation controls use the following. Use true to lock mode,
83
- false for unlocked mode. The default is false.
192
+ **After (v5.x):**
193
+ ```typescript
194
+ import { viewerCesiumNavigationMixin } from '@znemz/cesium-navigation';
195
+ import '@znemz/cesium-navigation/style.css';
84
196
 
85
- ```js
86
- viewer.cesiumNavigation.setNavigationLocked(true / false);
197
+ const viewer = new Cesium.Viewer('cesiumContainer');
198
+ viewer.extend(viewerCesiumNavigationMixin);
87
199
  ```
88
200
 
89
- - if there are still open questions please checkout the examples
201
+ ## License
202
+
203
+ Apache-2.0
90
204
 
91
- ## Why browser\_ in package.json
205
+ ## Credits
92
206
 
93
- Here is [why](https://github.com/webpack/webpack/issues/4674) and [here](https://github.com/nmccready/cesium-navigation/issues/2).
207
+ - Original author: Alberto Acevedo
208
+ - Maintainer: Nick McCready (@nmccready)
209
+ - Sponsor: [Brickhouse Technologies](https://github.com/brickhouse-tech)
94
210
 
95
- ## [License](./LICENSE)
211
+ ## Contributing
96
212
 
97
- [downloads-image]: http://img.shields.io/npm/dm/@znemz/cesium-navigation.svg
98
- [npm-image]: https://img.shields.io/npm/v/@znemz/cesium-navigation.svg
99
- [npm-url]: https://www.npmjs.com/package/@znemz/cesium-navigation
100
- [travis-image]: https://img.shields.io/travis/nmccready/cesium-navigation.svg?label=travis-ci
101
- [travis-url]: https://travis-ci.org/nmccready/cesium-navigation
213
+ Issues and pull requests welcome! Please use conventional commits for commit messages.
@@ -0,0 +1 @@
1
+ :root{--default-font: "Roboto", sans-serif;--highlight-color: #68adfe;--floating-background-color: rgba(47, 53, 60, .8);--floating-text-color: #ffffff;--floating-element-border: 1px solid #555555}.full-window{position:absolute;top:0;left:0;right:0;bottom:0;margin:0;overflow:hidden;padding:0;transition:left .25s ease-out}.transparent-to-input{pointer-events:none}.opaque-to-input{pointer-events:auto}.clickable{cursor:pointer}.cesium-widget-cesiumNavigationContainer{position:relative}.floating{pointer-events:auto;position:absolute;border-radius:15px;background-color:var(--floating-background-color)}.floating-horizontal{pointer-events:auto;position:absolute;border-radius:15px;background-color:var(--floating-background-color);padding-left:5px;padding-right:5px}.floating-vertical{pointer-events:auto;position:absolute;border-radius:15px;background-color:var(--floating-background-color);padding-top:5px;padding-bottom:5px}.navigation-controls{position:absolute;right:30px;top:210px;width:30px;border:1px solid rgba(255,255,255,.1);font-weight:300;-webkit-touch-callout:none;-webkit-user-select:none;-moz-user-select:none;-ms-user-select:none;user-select:none}.navigation-control{cursor:pointer;border-bottom:var(--floating-element-border)}.navigation-control:active{color:#fff}.navigation-control-last{cursor:pointer;border-bottom:0}.navigation-control-icon-zoom-in{position:relative;text-align:center;font-size:20px;color:var(--floating-text-color);padding-bottom:4px}.navigation-control-icon-zoom-out{position:relative;text-align:center;font-size:20px;color:var(--floating-text-color)}.navigation-control-icon-reset{position:relative;left:10px;width:10px;height:10px;fill:#fffc;padding-top:6px;padding-bottom:6px;box-sizing:content-box}.compass{pointer-events:auto;position:absolute;right:0;top:100px;width:95px;height:95px;overflow:hidden}.compass-outer-ring{position:absolute;top:0;width:95px;height:95px;fill:#ffffff80}.compass-outer-ring-background{position:absolute;top:14px;left:14px;width:44px;height:44px;border-radius:44px;border:12px solid var(--floating-background-color);box-sizing:content-box}.compass-gyro{pointer-events:none;position:absolute;top:0;width:95px;height:95px;fill:#ccc}.compass-gyro-active{fill:var(--highlight-color)}.compass-gyro-background{position:absolute;top:30px;left:30px;width:33px;height:33px;border-radius:33px;background-color:var(--floating-background-color);border:1px solid rgba(255,255,255,.2);box-sizing:content-box}.compass-gyro-background:hover+.compass-gyro{fill:var(--highlight-color)}.compass-rotation-marker{position:absolute;top:0;width:95px;height:95px;fill:var(--highlight-color)}.distance-legend{pointer-events:auto;position:absolute;border-radius:15px;background-color:var(--floating-background-color);padding-left:5px;padding-right:5px;right:25px;bottom:30px;height:30px;width:125px;border:1px solid rgba(255,255,255,.1);box-sizing:content-box}.distance-legend-label{display:inline-block;font-family:var(--default-font);font-size:14px;font-weight:lighter;line-height:30px;color:var(--floating-text-color);width:125px;text-align:center}.distance-legend-scale-bar{border-left:1px solid var(--floating-text-color);border-right:1px solid var(--floating-text-color);border-bottom:1px solid var(--floating-text-color);position:absolute;height:10px;top:15px}@media screen and (max-width:700px),screen and (max-height:420px){.navigation-controls,.compass,.distance-legend{display:none}}@media print{.navigation-controls,.compass,.distance-legend,.floating{display:none}.full-window{position:initial}}