@znemz/cesium-navigation 4.0.0 → 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/dist/index.js DELETED
@@ -1,2610 +0,0 @@
1
- 'use strict';
2
-
3
- function _interopDefault (ex) { return (ex && (typeof ex === 'object') && 'default' in ex) ? ex['default'] : ex; }
4
-
5
- var MarkdownIt = _interopDefault(require('markdown-it'));
6
- var MarkdownItSanitizer = _interopDefault(require('markdown-it-sanitizer'));
7
- var Hammer = _interopDefault(require('hammerjs'));
8
- var Knockout = _interopDefault(require('knockout-es5'));
9
- var cesium = require('cesium');
10
-
11
- var htmlTagRegex = /<html(.|\s)*>(.|\s)*<\/html>/im;
12
-
13
- var md = new MarkdownIt({
14
- html: true,
15
- linkify: true });
16
-
17
-
18
- md.use(MarkdownItSanitizer, {
19
- imageClass: '',
20
- removeUnbalanced: false,
21
- removeUnknown: false });
22
-
23
-
24
- var KnockoutMarkdownBinding = {
25
- register: function register(_knockoutEle) {
26
- var knockoutEle = _knockoutEle;
27
- knockoutEle.bindingHandlers.markdown = {
28
- init: function init() {
29
- // Prevent binding on the dynamically-injected HTML
30
- // (as developers are unlikely to expect that, and it has security implications)
31
- return { controlsDescendantBindings: true };
32
- },
33
- update: function update(_element, valueAccessor) {
34
- var element = _element;
35
- // Remove existing children of this element.
36
- while (element.firstChild) {
37
- knockoutEle.removeNode(element.firstChild);
38
- }
39
-
40
- var rawText = knockoutEle.unwrap(valueAccessor());
41
-
42
- // If the text contains an <html> tag, don't try to interpret it as Markdown because
43
- // we'll probably break it in the process.
44
- var html = void 0;
45
- if (htmlTagRegex.test(rawText)) {
46
- html = rawText;
47
- } else {
48
- html = md.render(rawText);
49
- }
50
-
51
- var nodes = knockoutEle.utils.parseHtmlFragment(html, element);
52
- element.className = element.className + ' markdown';
53
-
54
- for (var i = 0; i < nodes.length; ++i) {
55
- var node = nodes[i];
56
- setAnchorTargets(node);
57
- element.appendChild(node);
58
- }
59
- } };
60
-
61
- } };
62
-
63
-
64
- function setAnchorTargets(_element) {
65
- var element = _element;
66
- if (element instanceof HTMLAnchorElement) {
67
- element.target = '_blank';
68
- }
69
-
70
- if (element.childNodes && element.childNodes.length > 0) {
71
- for (var i = 0; i < element.childNodes.length; ++i) {
72
- setAnchorTargets(element.childNodes[i]);
73
- }
74
- }
75
- }
76
-
77
- var KnockoutHammerBinding = {
78
- register: function register() {
79
- Knockout.bindingHandlers.swipeLeft = {
80
- init: function init(element, valueAccessor, allBindings, _viewModel, bindingContext) {
81
- var f = Knockout.unwrap(valueAccessor());
82
- new Hammer(element).on('swipeleft', function () {for (var _len = arguments.length, args = Array(_len), _key = 0; _key < _len; _key++) {args[_key] = arguments[_key];}
83
- var viewModel = bindingContext.$data;
84
- f.apply(viewModel, args);
85
- });
86
- } };
87
-
88
-
89
- Knockout.bindingHandlers.swipeRight = {
90
- init: function init(element, valueAccessor, allBindings, _viewModel, bindingContext) {
91
- var f = Knockout.unwrap(valueAccessor());
92
- new Hammer(element).on('swiperight', function () {for (var _len2 = arguments.length, args = Array(_len2), _key2 = 0; _key2 < _len2; _key2++) {args[_key2] = arguments[_key2];}
93
- var viewModel = bindingContext.$data;
94
- f.apply(viewModel, args);
95
- });
96
- } };
97
-
98
- } };
99
-
100
- function registerKnockoutBindings() {
101
- cesium.SvgPathBindingHandler.register(Knockout);
102
- KnockoutMarkdownBinding.register(Knockout);
103
- KnockoutHammerBinding.register(Knockout);
104
-
105
- Knockout.bindingHandlers.embeddedComponent = {
106
- init: function init(element, valueAccessor) {
107
- var component = Knockout.unwrap(valueAccessor());
108
- component.show(element);
109
- return { controlsDescendantBindings: true };
110
- },
111
- update: function update() {} };
112
-
113
- }
114
-
115
- function createFragmentFromTemplate(htmlString) {
116
- var holder = document.createElement('div');
117
- holder.innerHTML = htmlString;
118
-
119
- var fragment = document.createDocumentFragment();
120
- while (holder.firstChild) {
121
- fragment.appendChild(holder.firstChild);
122
- }
123
-
124
- return fragment;
125
- }
126
-
127
- function loadView(htmlString, _container, viewModel) {
128
- var container = cesium.getElement(_container);
129
-
130
- var fragment = createFragmentFromTemplate(htmlString);
131
-
132
- // Sadly, fragment.childNodes doesn't have a slice function.
133
- // This code could be replaced with Array.prototype.slice.call(fragment.childNodes)
134
- // but that seems slightly error prone.
135
- var nodes = [];
136
-
137
- for (var i = 0; i < fragment.childNodes.length; ++i) {
138
- nodes.push(fragment.childNodes[i]);
139
- }
140
-
141
- container.appendChild(fragment);
142
-
143
- for (var _i = 0; _i < nodes.length; ++_i) {
144
- var node = nodes[_i];
145
- if (node.nodeType === 1 || node.nodeType === 8) {
146
- Knockout.applyBindings(viewModel, node);
147
- }
148
- }
149
-
150
- return nodes;
151
- }
152
-
153
- function unwrapExports (x) {
154
- return x && x.__esModule && Object.prototype.hasOwnProperty.call(x, 'default') ? x.default : x;
155
- }
156
-
157
- function createCommonjsModule(fn, module) {
158
- return module = { exports: {} }, fn(module, module.exports), module.exports;
159
- }
160
-
161
- var helpers = createCommonjsModule(function (module, exports) {
162
- Object.defineProperty(exports, "__esModule", { value: true });
163
- /**
164
- * @module helpers
165
- */
166
- /**
167
- * Earth Radius used with the Harvesine formula and approximates using a spherical (non-ellipsoid) Earth.
168
- *
169
- * @memberof helpers
170
- * @type {number}
171
- */
172
- exports.earthRadius = 6371008.8;
173
- /**
174
- * Unit of measurement factors using a spherical (non-ellipsoid) earth radius.
175
- *
176
- * @memberof helpers
177
- * @type {Object}
178
- */
179
- exports.factors = {
180
- centimeters: exports.earthRadius * 100,
181
- centimetres: exports.earthRadius * 100,
182
- degrees: exports.earthRadius / 111325,
183
- feet: exports.earthRadius * 3.28084,
184
- inches: exports.earthRadius * 39.370,
185
- kilometers: exports.earthRadius / 1000,
186
- kilometres: exports.earthRadius / 1000,
187
- meters: exports.earthRadius,
188
- metres: exports.earthRadius,
189
- miles: exports.earthRadius / 1609.344,
190
- millimeters: exports.earthRadius * 1000,
191
- millimetres: exports.earthRadius * 1000,
192
- nauticalmiles: exports.earthRadius / 1852,
193
- radians: 1,
194
- yards: exports.earthRadius / 1.0936,
195
- };
196
- /**
197
- * Units of measurement factors based on 1 meter.
198
- *
199
- * @memberof helpers
200
- * @type {Object}
201
- */
202
- exports.unitsFactors = {
203
- centimeters: 100,
204
- centimetres: 100,
205
- degrees: 1 / 111325,
206
- feet: 3.28084,
207
- inches: 39.370,
208
- kilometers: 1 / 1000,
209
- kilometres: 1 / 1000,
210
- meters: 1,
211
- metres: 1,
212
- miles: 1 / 1609.344,
213
- millimeters: 1000,
214
- millimetres: 1000,
215
- nauticalmiles: 1 / 1852,
216
- radians: 1 / exports.earthRadius,
217
- yards: 1 / 1.0936,
218
- };
219
- /**
220
- * Area of measurement factors based on 1 square meter.
221
- *
222
- * @memberof helpers
223
- * @type {Object}
224
- */
225
- exports.areaFactors = {
226
- acres: 0.000247105,
227
- centimeters: 10000,
228
- centimetres: 10000,
229
- feet: 10.763910417,
230
- inches: 1550.003100006,
231
- kilometers: 0.000001,
232
- kilometres: 0.000001,
233
- meters: 1,
234
- metres: 1,
235
- miles: 3.86e-7,
236
- millimeters: 1000000,
237
- millimetres: 1000000,
238
- yards: 1.195990046,
239
- };
240
- /**
241
- * Wraps a GeoJSON {@link Geometry} in a GeoJSON {@link Feature}.
242
- *
243
- * @name feature
244
- * @param {Geometry} geometry input geometry
245
- * @param {Object} [properties={}] an Object of key-value pairs to add as properties
246
- * @param {Object} [options={}] Optional Parameters
247
- * @param {Array<number>} [options.bbox] Bounding Box Array [west, south, east, north] associated with the Feature
248
- * @param {string|number} [options.id] Identifier associated with the Feature
249
- * @returns {Feature} a GeoJSON Feature
250
- * @example
251
- * var geometry = {
252
- * "type": "Point",
253
- * "coordinates": [110, 50]
254
- * };
255
- *
256
- * var feature = turf.feature(geometry);
257
- *
258
- * //=feature
259
- */
260
- function feature(geom, properties, options) {
261
- if (options === void 0) { options = {}; }
262
- var feat = { type: "Feature" };
263
- if (options.id === 0 || options.id) {
264
- feat.id = options.id;
265
- }
266
- if (options.bbox) {
267
- feat.bbox = options.bbox;
268
- }
269
- feat.properties = properties || {};
270
- feat.geometry = geom;
271
- return feat;
272
- }
273
- exports.feature = feature;
274
- /**
275
- * Creates a GeoJSON {@link Geometry} from a Geometry string type & coordinates.
276
- * For GeometryCollection type use `helpers.geometryCollection`
277
- *
278
- * @name geometry
279
- * @param {string} type Geometry Type
280
- * @param {Array<any>} coordinates Coordinates
281
- * @param {Object} [options={}] Optional Parameters
282
- * @returns {Geometry} a GeoJSON Geometry
283
- * @example
284
- * var type = "Point";
285
- * var coordinates = [110, 50];
286
- * var geometry = turf.geometry(type, coordinates);
287
- * // => geometry
288
- */
289
- function geometry(type, coordinates, options) {
290
- if (options === void 0) { options = {}; }
291
- switch (type) {
292
- case "Point": return point(coordinates).geometry;
293
- case "LineString": return lineString(coordinates).geometry;
294
- case "Polygon": return polygon(coordinates).geometry;
295
- case "MultiPoint": return multiPoint(coordinates).geometry;
296
- case "MultiLineString": return multiLineString(coordinates).geometry;
297
- case "MultiPolygon": return multiPolygon(coordinates).geometry;
298
- default: throw new Error(type + " is invalid");
299
- }
300
- }
301
- exports.geometry = geometry;
302
- /**
303
- * Creates a {@link Point} {@link Feature} from a Position.
304
- *
305
- * @name point
306
- * @param {Array<number>} coordinates longitude, latitude position (each in decimal degrees)
307
- * @param {Object} [properties={}] an Object of key-value pairs to add as properties
308
- * @param {Object} [options={}] Optional Parameters
309
- * @param {Array<number>} [options.bbox] Bounding Box Array [west, south, east, north] associated with the Feature
310
- * @param {string|number} [options.id] Identifier associated with the Feature
311
- * @returns {Feature<Point>} a Point feature
312
- * @example
313
- * var point = turf.point([-75.343, 39.984]);
314
- *
315
- * //=point
316
- */
317
- function point(coordinates, properties, options) {
318
- if (options === void 0) { options = {}; }
319
- var geom = {
320
- type: "Point",
321
- coordinates: coordinates,
322
- };
323
- return feature(geom, properties, options);
324
- }
325
- exports.point = point;
326
- /**
327
- * Creates a {@link Point} {@link FeatureCollection} from an Array of Point coordinates.
328
- *
329
- * @name points
330
- * @param {Array<Array<number>>} coordinates an array of Points
331
- * @param {Object} [properties={}] Translate these properties to each Feature
332
- * @param {Object} [options={}] Optional Parameters
333
- * @param {Array<number>} [options.bbox] Bounding Box Array [west, south, east, north]
334
- * associated with the FeatureCollection
335
- * @param {string|number} [options.id] Identifier associated with the FeatureCollection
336
- * @returns {FeatureCollection<Point>} Point Feature
337
- * @example
338
- * var points = turf.points([
339
- * [-75, 39],
340
- * [-80, 45],
341
- * [-78, 50]
342
- * ]);
343
- *
344
- * //=points
345
- */
346
- function points(coordinates, properties, options) {
347
- if (options === void 0) { options = {}; }
348
- return featureCollection(coordinates.map(function (coords) {
349
- return point(coords, properties);
350
- }), options);
351
- }
352
- exports.points = points;
353
- /**
354
- * Creates a {@link Polygon} {@link Feature} from an Array of LinearRings.
355
- *
356
- * @name polygon
357
- * @param {Array<Array<Array<number>>>} coordinates an array of LinearRings
358
- * @param {Object} [properties={}] an Object of key-value pairs to add as properties
359
- * @param {Object} [options={}] Optional Parameters
360
- * @param {Array<number>} [options.bbox] Bounding Box Array [west, south, east, north] associated with the Feature
361
- * @param {string|number} [options.id] Identifier associated with the Feature
362
- * @returns {Feature<Polygon>} Polygon Feature
363
- * @example
364
- * var polygon = turf.polygon([[[-5, 52], [-4, 56], [-2, 51], [-7, 54], [-5, 52]]], { name: 'poly1' });
365
- *
366
- * //=polygon
367
- */
368
- function polygon(coordinates, properties, options) {
369
- if (options === void 0) { options = {}; }
370
- for (var _i = 0, coordinates_1 = coordinates; _i < coordinates_1.length; _i++) {
371
- var ring = coordinates_1[_i];
372
- if (ring.length < 4) {
373
- throw new Error("Each LinearRing of a Polygon must have 4 or more Positions.");
374
- }
375
- for (var j = 0; j < ring[ring.length - 1].length; j++) {
376
- // Check if first point of Polygon contains two numbers
377
- if (ring[ring.length - 1][j] !== ring[0][j]) {
378
- throw new Error("First and last Position are not equivalent.");
379
- }
380
- }
381
- }
382
- var geom = {
383
- type: "Polygon",
384
- coordinates: coordinates,
385
- };
386
- return feature(geom, properties, options);
387
- }
388
- exports.polygon = polygon;
389
- /**
390
- * Creates a {@link Polygon} {@link FeatureCollection} from an Array of Polygon coordinates.
391
- *
392
- * @name polygons
393
- * @param {Array<Array<Array<Array<number>>>>} coordinates an array of Polygon coordinates
394
- * @param {Object} [properties={}] an Object of key-value pairs to add as properties
395
- * @param {Object} [options={}] Optional Parameters
396
- * @param {Array<number>} [options.bbox] Bounding Box Array [west, south, east, north] associated with the Feature
397
- * @param {string|number} [options.id] Identifier associated with the FeatureCollection
398
- * @returns {FeatureCollection<Polygon>} Polygon FeatureCollection
399
- * @example
400
- * var polygons = turf.polygons([
401
- * [[[-5, 52], [-4, 56], [-2, 51], [-7, 54], [-5, 52]]],
402
- * [[[-15, 42], [-14, 46], [-12, 41], [-17, 44], [-15, 42]]],
403
- * ]);
404
- *
405
- * //=polygons
406
- */
407
- function polygons(coordinates, properties, options) {
408
- if (options === void 0) { options = {}; }
409
- return featureCollection(coordinates.map(function (coords) {
410
- return polygon(coords, properties);
411
- }), options);
412
- }
413
- exports.polygons = polygons;
414
- /**
415
- * Creates a {@link LineString} {@link Feature} from an Array of Positions.
416
- *
417
- * @name lineString
418
- * @param {Array<Array<number>>} coordinates an array of Positions
419
- * @param {Object} [properties={}] an Object of key-value pairs to add as properties
420
- * @param {Object} [options={}] Optional Parameters
421
- * @param {Array<number>} [options.bbox] Bounding Box Array [west, south, east, north] associated with the Feature
422
- * @param {string|number} [options.id] Identifier associated with the Feature
423
- * @returns {Feature<LineString>} LineString Feature
424
- * @example
425
- * var linestring1 = turf.lineString([[-24, 63], [-23, 60], [-25, 65], [-20, 69]], {name: 'line 1'});
426
- * var linestring2 = turf.lineString([[-14, 43], [-13, 40], [-15, 45], [-10, 49]], {name: 'line 2'});
427
- *
428
- * //=linestring1
429
- * //=linestring2
430
- */
431
- function lineString(coordinates, properties, options) {
432
- if (options === void 0) { options = {}; }
433
- if (coordinates.length < 2) {
434
- throw new Error("coordinates must be an array of two or more positions");
435
- }
436
- var geom = {
437
- type: "LineString",
438
- coordinates: coordinates,
439
- };
440
- return feature(geom, properties, options);
441
- }
442
- exports.lineString = lineString;
443
- /**
444
- * Creates a {@link LineString} {@link FeatureCollection} from an Array of LineString coordinates.
445
- *
446
- * @name lineStrings
447
- * @param {Array<Array<Array<number>>>} coordinates an array of LinearRings
448
- * @param {Object} [properties={}] an Object of key-value pairs to add as properties
449
- * @param {Object} [options={}] Optional Parameters
450
- * @param {Array<number>} [options.bbox] Bounding Box Array [west, south, east, north]
451
- * associated with the FeatureCollection
452
- * @param {string|number} [options.id] Identifier associated with the FeatureCollection
453
- * @returns {FeatureCollection<LineString>} LineString FeatureCollection
454
- * @example
455
- * var linestrings = turf.lineStrings([
456
- * [[-24, 63], [-23, 60], [-25, 65], [-20, 69]],
457
- * [[-14, 43], [-13, 40], [-15, 45], [-10, 49]]
458
- * ]);
459
- *
460
- * //=linestrings
461
- */
462
- function lineStrings(coordinates, properties, options) {
463
- if (options === void 0) { options = {}; }
464
- return featureCollection(coordinates.map(function (coords) {
465
- return lineString(coords, properties);
466
- }), options);
467
- }
468
- exports.lineStrings = lineStrings;
469
- /**
470
- * Takes one or more {@link Feature|Features} and creates a {@link FeatureCollection}.
471
- *
472
- * @name featureCollection
473
- * @param {Feature[]} features input features
474
- * @param {Object} [options={}] Optional Parameters
475
- * @param {Array<number>} [options.bbox] Bounding Box Array [west, south, east, north] associated with the Feature
476
- * @param {string|number} [options.id] Identifier associated with the Feature
477
- * @returns {FeatureCollection} FeatureCollection of Features
478
- * @example
479
- * var locationA = turf.point([-75.343, 39.984], {name: 'Location A'});
480
- * var locationB = turf.point([-75.833, 39.284], {name: 'Location B'});
481
- * var locationC = turf.point([-75.534, 39.123], {name: 'Location C'});
482
- *
483
- * var collection = turf.featureCollection([
484
- * locationA,
485
- * locationB,
486
- * locationC
487
- * ]);
488
- *
489
- * //=collection
490
- */
491
- function featureCollection(features, options) {
492
- if (options === void 0) { options = {}; }
493
- var fc = { type: "FeatureCollection" };
494
- if (options.id) {
495
- fc.id = options.id;
496
- }
497
- if (options.bbox) {
498
- fc.bbox = options.bbox;
499
- }
500
- fc.features = features;
501
- return fc;
502
- }
503
- exports.featureCollection = featureCollection;
504
- /**
505
- * Creates a {@link Feature<MultiLineString>} based on a
506
- * coordinate array. Properties can be added optionally.
507
- *
508
- * @name multiLineString
509
- * @param {Array<Array<Array<number>>>} coordinates an array of LineStrings
510
- * @param {Object} [properties={}] an Object of key-value pairs to add as properties
511
- * @param {Object} [options={}] Optional Parameters
512
- * @param {Array<number>} [options.bbox] Bounding Box Array [west, south, east, north] associated with the Feature
513
- * @param {string|number} [options.id] Identifier associated with the Feature
514
- * @returns {Feature<MultiLineString>} a MultiLineString feature
515
- * @throws {Error} if no coordinates are passed
516
- * @example
517
- * var multiLine = turf.multiLineString([[[0,0],[10,10]]]);
518
- *
519
- * //=multiLine
520
- */
521
- function multiLineString(coordinates, properties, options) {
522
- if (options === void 0) { options = {}; }
523
- var geom = {
524
- type: "MultiLineString",
525
- coordinates: coordinates,
526
- };
527
- return feature(geom, properties, options);
528
- }
529
- exports.multiLineString = multiLineString;
530
- /**
531
- * Creates a {@link Feature<MultiPoint>} based on a
532
- * coordinate array. Properties can be added optionally.
533
- *
534
- * @name multiPoint
535
- * @param {Array<Array<number>>} coordinates an array of Positions
536
- * @param {Object} [properties={}] an Object of key-value pairs to add as properties
537
- * @param {Object} [options={}] Optional Parameters
538
- * @param {Array<number>} [options.bbox] Bounding Box Array [west, south, east, north] associated with the Feature
539
- * @param {string|number} [options.id] Identifier associated with the Feature
540
- * @returns {Feature<MultiPoint>} a MultiPoint feature
541
- * @throws {Error} if no coordinates are passed
542
- * @example
543
- * var multiPt = turf.multiPoint([[0,0],[10,10]]);
544
- *
545
- * //=multiPt
546
- */
547
- function multiPoint(coordinates, properties, options) {
548
- if (options === void 0) { options = {}; }
549
- var geom = {
550
- type: "MultiPoint",
551
- coordinates: coordinates,
552
- };
553
- return feature(geom, properties, options);
554
- }
555
- exports.multiPoint = multiPoint;
556
- /**
557
- * Creates a {@link Feature<MultiPolygon>} based on a
558
- * coordinate array. Properties can be added optionally.
559
- *
560
- * @name multiPolygon
561
- * @param {Array<Array<Array<Array<number>>>>} coordinates an array of Polygons
562
- * @param {Object} [properties={}] an Object of key-value pairs to add as properties
563
- * @param {Object} [options={}] Optional Parameters
564
- * @param {Array<number>} [options.bbox] Bounding Box Array [west, south, east, north] associated with the Feature
565
- * @param {string|number} [options.id] Identifier associated with the Feature
566
- * @returns {Feature<MultiPolygon>} a multipolygon feature
567
- * @throws {Error} if no coordinates are passed
568
- * @example
569
- * var multiPoly = turf.multiPolygon([[[[0,0],[0,10],[10,10],[10,0],[0,0]]]]);
570
- *
571
- * //=multiPoly
572
- *
573
- */
574
- function multiPolygon(coordinates, properties, options) {
575
- if (options === void 0) { options = {}; }
576
- var geom = {
577
- type: "MultiPolygon",
578
- coordinates: coordinates,
579
- };
580
- return feature(geom, properties, options);
581
- }
582
- exports.multiPolygon = multiPolygon;
583
- /**
584
- * Creates a {@link Feature<GeometryCollection>} based on a
585
- * coordinate array. Properties can be added optionally.
586
- *
587
- * @name geometryCollection
588
- * @param {Array<Geometry>} geometries an array of GeoJSON Geometries
589
- * @param {Object} [properties={}] an Object of key-value pairs to add as properties
590
- * @param {Object} [options={}] Optional Parameters
591
- * @param {Array<number>} [options.bbox] Bounding Box Array [west, south, east, north] associated with the Feature
592
- * @param {string|number} [options.id] Identifier associated with the Feature
593
- * @returns {Feature<GeometryCollection>} a GeoJSON GeometryCollection Feature
594
- * @example
595
- * var pt = turf.geometry("Point", [100, 0]);
596
- * var line = turf.geometry("LineString", [[101, 0], [102, 1]]);
597
- * var collection = turf.geometryCollection([pt, line]);
598
- *
599
- * // => collection
600
- */
601
- function geometryCollection(geometries, properties, options) {
602
- if (options === void 0) { options = {}; }
603
- var geom = {
604
- type: "GeometryCollection",
605
- geometries: geometries,
606
- };
607
- return feature(geom, properties, options);
608
- }
609
- exports.geometryCollection = geometryCollection;
610
- /**
611
- * Round number to precision
612
- *
613
- * @param {number} num Number
614
- * @param {number} [precision=0] Precision
615
- * @returns {number} rounded number
616
- * @example
617
- * turf.round(120.4321)
618
- * //=120
619
- *
620
- * turf.round(120.4321, 2)
621
- * //=120.43
622
- */
623
- function round(num, precision) {
624
- if (precision === void 0) { precision = 0; }
625
- if (precision && !(precision >= 0)) {
626
- throw new Error("precision must be a positive number");
627
- }
628
- var multiplier = Math.pow(10, precision || 0);
629
- return Math.round(num * multiplier) / multiplier;
630
- }
631
- exports.round = round;
632
- /**
633
- * Convert a distance measurement (assuming a spherical Earth) from radians to a more friendly unit.
634
- * Valid units: miles, nauticalmiles, inches, yards, meters, metres, kilometers, centimeters, feet
635
- *
636
- * @name radiansToLength
637
- * @param {number} radians in radians across the sphere
638
- * @param {string} [units="kilometers"] can be degrees, radians, miles, or kilometers inches, yards, metres,
639
- * meters, kilometres, kilometers.
640
- * @returns {number} distance
641
- */
642
- function radiansToLength(radians, units) {
643
- if (units === void 0) { units = "kilometers"; }
644
- var factor = exports.factors[units];
645
- if (!factor) {
646
- throw new Error(units + " units is invalid");
647
- }
648
- return radians * factor;
649
- }
650
- exports.radiansToLength = radiansToLength;
651
- /**
652
- * Convert a distance measurement (assuming a spherical Earth) from a real-world unit into radians
653
- * Valid units: miles, nauticalmiles, inches, yards, meters, metres, kilometers, centimeters, feet
654
- *
655
- * @name lengthToRadians
656
- * @param {number} distance in real units
657
- * @param {string} [units="kilometers"] can be degrees, radians, miles, or kilometers inches, yards, metres,
658
- * meters, kilometres, kilometers.
659
- * @returns {number} radians
660
- */
661
- function lengthToRadians(distance, units) {
662
- if (units === void 0) { units = "kilometers"; }
663
- var factor = exports.factors[units];
664
- if (!factor) {
665
- throw new Error(units + " units is invalid");
666
- }
667
- return distance / factor;
668
- }
669
- exports.lengthToRadians = lengthToRadians;
670
- /**
671
- * Convert a distance measurement (assuming a spherical Earth) from a real-world unit into degrees
672
- * Valid units: miles, nauticalmiles, inches, yards, meters, metres, centimeters, kilometres, feet
673
- *
674
- * @name lengthToDegrees
675
- * @param {number} distance in real units
676
- * @param {string} [units="kilometers"] can be degrees, radians, miles, or kilometers inches, yards, metres,
677
- * meters, kilometres, kilometers.
678
- * @returns {number} degrees
679
- */
680
- function lengthToDegrees(distance, units) {
681
- return radiansToDegrees(lengthToRadians(distance, units));
682
- }
683
- exports.lengthToDegrees = lengthToDegrees;
684
- /**
685
- * Converts any bearing angle from the north line direction (positive clockwise)
686
- * and returns an angle between 0-360 degrees (positive clockwise), 0 being the north line
687
- *
688
- * @name bearingToAzimuth
689
- * @param {number} bearing angle, between -180 and +180 degrees
690
- * @returns {number} angle between 0 and 360 degrees
691
- */
692
- function bearingToAzimuth(bearing) {
693
- var angle = bearing % 360;
694
- if (angle < 0) {
695
- angle += 360;
696
- }
697
- return angle;
698
- }
699
- exports.bearingToAzimuth = bearingToAzimuth;
700
- /**
701
- * Converts an angle in radians to degrees
702
- *
703
- * @name radiansToDegrees
704
- * @param {number} radians angle in radians
705
- * @returns {number} degrees between 0 and 360 degrees
706
- */
707
- function radiansToDegrees(radians) {
708
- var degrees = radians % (2 * Math.PI);
709
- return degrees * 180 / Math.PI;
710
- }
711
- exports.radiansToDegrees = radiansToDegrees;
712
- /**
713
- * Converts an angle in degrees to radians
714
- *
715
- * @name degreesToRadians
716
- * @param {number} degrees angle between 0 and 360 degrees
717
- * @returns {number} angle in radians
718
- */
719
- function degreesToRadians(degrees) {
720
- var radians = degrees % 360;
721
- return radians * Math.PI / 180;
722
- }
723
- exports.degreesToRadians = degreesToRadians;
724
- /**
725
- * Converts a length to the requested unit.
726
- * Valid units: miles, nauticalmiles, inches, yards, meters, metres, kilometers, centimeters, feet
727
- *
728
- * @param {number} length to be converted
729
- * @param {Units} [originalUnit="kilometers"] of the length
730
- * @param {Units} [finalUnit="kilometers"] returned unit
731
- * @returns {number} the converted length
732
- */
733
- function convertLength(length, originalUnit, finalUnit) {
734
- if (originalUnit === void 0) { originalUnit = "kilometers"; }
735
- if (finalUnit === void 0) { finalUnit = "kilometers"; }
736
- if (!(length >= 0)) {
737
- throw new Error("length must be a positive number");
738
- }
739
- return radiansToLength(lengthToRadians(length, originalUnit), finalUnit);
740
- }
741
- exports.convertLength = convertLength;
742
- /**
743
- * Converts a area to the requested unit.
744
- * Valid units: kilometers, kilometres, meters, metres, centimetres, millimeters, acres, miles, yards, feet, inches
745
- * @param {number} area to be converted
746
- * @param {Units} [originalUnit="meters"] of the distance
747
- * @param {Units} [finalUnit="kilometers"] returned unit
748
- * @returns {number} the converted distance
749
- */
750
- function convertArea(area, originalUnit, finalUnit) {
751
- if (originalUnit === void 0) { originalUnit = "meters"; }
752
- if (finalUnit === void 0) { finalUnit = "kilometers"; }
753
- if (!(area >= 0)) {
754
- throw new Error("area must be a positive number");
755
- }
756
- var startFactor = exports.areaFactors[originalUnit];
757
- if (!startFactor) {
758
- throw new Error("invalid original units");
759
- }
760
- var finalFactor = exports.areaFactors[finalUnit];
761
- if (!finalFactor) {
762
- throw new Error("invalid final units");
763
- }
764
- return (area / startFactor) * finalFactor;
765
- }
766
- exports.convertArea = convertArea;
767
- /**
768
- * isNumber
769
- *
770
- * @param {*} num Number to validate
771
- * @returns {boolean} true/false
772
- * @example
773
- * turf.isNumber(123)
774
- * //=true
775
- * turf.isNumber('foo')
776
- * //=false
777
- */
778
- function isNumber(num) {
779
- return !isNaN(num) && num !== null && !Array.isArray(num) && !/^\s*$/.test(num);
780
- }
781
- exports.isNumber = isNumber;
782
- /**
783
- * isObject
784
- *
785
- * @param {*} input variable to validate
786
- * @returns {boolean} true/false
787
- * @example
788
- * turf.isObject({elevation: 10})
789
- * //=true
790
- * turf.isObject('foo')
791
- * //=false
792
- */
793
- function isObject(input) {
794
- return (!!input) && (input.constructor === Object);
795
- }
796
- exports.isObject = isObject;
797
- /**
798
- * Validate BBox
799
- *
800
- * @private
801
- * @param {Array<number>} bbox BBox to validate
802
- * @returns {void}
803
- * @throws Error if BBox is not valid
804
- * @example
805
- * validateBBox([-180, -40, 110, 50])
806
- * //=OK
807
- * validateBBox([-180, -40])
808
- * //=Error
809
- * validateBBox('Foo')
810
- * //=Error
811
- * validateBBox(5)
812
- * //=Error
813
- * validateBBox(null)
814
- * //=Error
815
- * validateBBox(undefined)
816
- * //=Error
817
- */
818
- function validateBBox(bbox) {
819
- if (!bbox) {
820
- throw new Error("bbox is required");
821
- }
822
- if (!Array.isArray(bbox)) {
823
- throw new Error("bbox must be an Array");
824
- }
825
- if (bbox.length !== 4 && bbox.length !== 6) {
826
- throw new Error("bbox must be an Array of 4 or 6 numbers");
827
- }
828
- bbox.forEach(function (num) {
829
- if (!isNumber(num)) {
830
- throw new Error("bbox must only contain numbers");
831
- }
832
- });
833
- }
834
- exports.validateBBox = validateBBox;
835
- /**
836
- * Validate Id
837
- *
838
- * @private
839
- * @param {string|number} id Id to validate
840
- * @returns {void}
841
- * @throws Error if Id is not valid
842
- * @example
843
- * validateId([-180, -40, 110, 50])
844
- * //=Error
845
- * validateId([-180, -40])
846
- * //=Error
847
- * validateId('Foo')
848
- * //=OK
849
- * validateId(5)
850
- * //=OK
851
- * validateId(null)
852
- * //=Error
853
- * validateId(undefined)
854
- * //=Error
855
- */
856
- function validateId(id) {
857
- if (!id) {
858
- throw new Error("id is required");
859
- }
860
- if (["string", "number"].indexOf(typeof id) === -1) {
861
- throw new Error("id must be a number or a string");
862
- }
863
- }
864
- exports.validateId = validateId;
865
- // Deprecated methods
866
- function radians2degrees() {
867
- throw new Error("method has been renamed to `radiansToDegrees`");
868
- }
869
- exports.radians2degrees = radians2degrees;
870
- function degrees2radians() {
871
- throw new Error("method has been renamed to `degreesToRadians`");
872
- }
873
- exports.degrees2radians = degrees2radians;
874
- function distanceToDegrees() {
875
- throw new Error("method has been renamed to `lengthToDegrees`");
876
- }
877
- exports.distanceToDegrees = distanceToDegrees;
878
- function distanceToRadians() {
879
- throw new Error("method has been renamed to `lengthToRadians`");
880
- }
881
- exports.distanceToRadians = distanceToRadians;
882
- function radiansToDistance() {
883
- throw new Error("method has been renamed to `radiansToLength`");
884
- }
885
- exports.radiansToDistance = radiansToDistance;
886
- function bearingToAngle() {
887
- throw new Error("method has been renamed to `bearingToAzimuth`");
888
- }
889
- exports.bearingToAngle = bearingToAngle;
890
- function convertDistance() {
891
- throw new Error("method has been renamed to `convertLength`");
892
- }
893
- exports.convertDistance = convertDistance;
894
- });
895
-
896
- unwrapExports(helpers);
897
- var helpers_1 = helpers.earthRadius;
898
- var helpers_2 = helpers.factors;
899
- var helpers_3 = helpers.unitsFactors;
900
- var helpers_4 = helpers.areaFactors;
901
- var helpers_5 = helpers.feature;
902
- var helpers_6 = helpers.geometry;
903
- var helpers_7 = helpers.point;
904
- var helpers_8 = helpers.points;
905
- var helpers_9 = helpers.polygon;
906
- var helpers_10 = helpers.polygons;
907
- var helpers_11 = helpers.lineString;
908
- var helpers_12 = helpers.lineStrings;
909
- var helpers_13 = helpers.featureCollection;
910
- var helpers_14 = helpers.multiLineString;
911
- var helpers_15 = helpers.multiPoint;
912
- var helpers_16 = helpers.multiPolygon;
913
- var helpers_17 = helpers.geometryCollection;
914
- var helpers_18 = helpers.round;
915
- var helpers_19 = helpers.radiansToLength;
916
- var helpers_20 = helpers.lengthToRadians;
917
- var helpers_21 = helpers.lengthToDegrees;
918
- var helpers_22 = helpers.bearingToAzimuth;
919
- var helpers_23 = helpers.radiansToDegrees;
920
- var helpers_24 = helpers.degreesToRadians;
921
- var helpers_25 = helpers.convertLength;
922
- var helpers_26 = helpers.convertArea;
923
- var helpers_27 = helpers.isNumber;
924
- var helpers_28 = helpers.isObject;
925
- var helpers_29 = helpers.validateBBox;
926
- var helpers_30 = helpers.validateId;
927
- var helpers_31 = helpers.radians2degrees;
928
- var helpers_32 = helpers.degrees2radians;
929
- var helpers_33 = helpers.distanceToDegrees;
930
- var helpers_34 = helpers.distanceToRadians;
931
- var helpers_35 = helpers.radiansToDistance;
932
- var helpers_36 = helpers.bearingToAngle;
933
- var helpers_37 = helpers.convertDistance;
934
-
935
- var unprojectedScratch = new cesium.Cartographic();
936
- var rayScratch = new cesium.Ray();
937
-
938
- /**
939
- * gets the focus point of the camera
940
- * @param {Viewer|Widget} terria The terria
941
- * @param {boolean} inWorldCoordinates true to get the focus in world coordinates,
942
- * otherwise get it in projection-specific map coordinates, in meters.
943
- * @param {Cartesian3} [result] The object in which the result will be stored.
944
- * @return {Cartesian3} The modified result parameter, a new instance if none
945
- * was provided or undefined if there is no focus point.
946
- */
947
- function getCameraFocus(terria, inWorldCoordinates, _result) {
948
- var result = _result;var
949
- scene = terria.scene;var
950
- camera = scene.camera;
951
-
952
- if (scene.mode === cesium.SceneMode.MORPHING) {
953
- return undefined;
954
- }
955
-
956
- if (!cesium.defined(result)) {
957
- result = new cesium.Cartesian3();
958
- }
959
-
960
- // TODO bug when tracking: if entity moves the current position
961
- // should be used and not only the one when starting orbiting/rotating
962
- // TODO bug when tracking: reset should reset to default view of tracked entity
963
-
964
- if (cesium.defined(terria.trackedEntity)) {
965
- result = terria.trackedEntity.position.getValue(
966
- terria.clock.currentTime,
967
- result);
968
-
969
- } else {
970
- rayScratch.origin = camera.positionWC;
971
- rayScratch.direction = camera.directionWC;
972
- result = scene.globe.pick(rayScratch, scene, result);
973
- }
974
-
975
- if (!cesium.defined(result)) {
976
- return undefined;
977
- }
978
-
979
- if (
980
- scene.mode === cesium.SceneMode.SCENE2D ||
981
- scene.mode === cesium.SceneMode.COLUMBUS_VIEW)
982
- {
983
- result = camera.worldToCameraCoordinatesPoint(result, result);
984
-
985
- if (inWorldCoordinates) {
986
- result = scene.globe.ellipsoid.cartographicToCartesian(
987
- scene.mapProjection.unproject(result, unprojectedScratch),
988
- result);
989
-
990
- }
991
- } else {
992
- if (!inWorldCoordinates) {
993
- result = camera.worldToCameraCoordinatesPoint(result, result);
994
- }
995
- }
996
-
997
- return result;
998
- }
999
-
1000
- var UNITS_TO_ABBREVIATION = {
1001
- meters: 'm',
1002
- millimeters: 'mm',
1003
- centimeters: 'cm',
1004
- kilometers: 'km',
1005
- acres: 'ac',
1006
- miles: 'mi',
1007
- nauticalmiles: 'nm',
1008
- inches: 'inch',
1009
- yards: 'yd',
1010
- feet: 'ft',
1011
- radians: 'rad',
1012
- degrees: 'deg' };
1013
-
1014
-
1015
- /**
1016
- * @param {Number} length
1017
- * @param {TufHelper.Units} units
1018
- */
1019
- function distanceLabelFormatter(length, units) {
1020
- var fixed = 1;
1021
- if (length < 1) {
1022
- fixed = 2;
1023
- if (units === 'kilometers') {
1024
- /* eslint-disable no-param-reassign */
1025
- units = 'meters';
1026
- length = helpers_25(length, 'kilometers', units);
1027
- /* eslint-enable no-param-reassign */
1028
- }
1029
- }
1030
-
1031
- return length.toFixed(fixed) + ' ' + UNITS_TO_ABBREVIATION[units];
1032
- }
1033
-
1034
- /* eslint-disable no-bitwise */
1035
-
1036
- function DistanceLegendViewModel(options) {
1037
- if (!cesium.defined(options) || !cesium.defined(options.terria)) {
1038
- throw new cesium.DeveloperError('options.terria is required.');
1039
- }
1040
-
1041
- this.terria = options.terria;
1042
- this._removeSubscription = undefined;
1043
- this._lastLegendUpdate = undefined;
1044
- this.eventHelper = new cesium.EventHelper();
1045
-
1046
- this.distanceLabel = undefined;
1047
- this.barWidth = undefined;
1048
-
1049
- this.enableDistanceLegend = cesium.defined(options.enableDistanceLegend) ?
1050
- options.enableDistanceLegend :
1051
- true;
1052
-
1053
- Knockout.track(this, ['distanceLabel', 'barWidth']);
1054
-
1055
- this.eventHelper.add(
1056
- this.terria.afterWidgetChanged,
1057
- function () {
1058
- if (cesium.defined(this._removeSubscription)) {
1059
- this._removeSubscription();
1060
- this._removeSubscription = undefined;
1061
- }
1062
- },
1063
- this);
1064
-
1065
- // this.terria.beforeWidgetChanged.addEventListener(function () {
1066
- // if (defined(this._removeSubscription)) {
1067
- // this._removeSubscription();
1068
- // this._removeSubscription = undefined;
1069
- // }
1070
- // }, this);
1071
-
1072
- var that = this;
1073
-
1074
- function addUpdateSubscription() {
1075
- if (cesium.defined(that.terria)) {var
1076
- scene = that.terria.scene;
1077
- that._removeSubscription = scene.postRender.addEventListener(function () {
1078
- updateDistanceLegendCesium(this, scene, options);
1079
- }, that);
1080
- }
1081
- }
1082
-
1083
- addUpdateSubscription();
1084
- this.eventHelper.add(
1085
- this.terria.afterWidgetChanged,
1086
- function () {
1087
- addUpdateSubscription();
1088
- },
1089
- this);
1090
-
1091
- // this.terria.afterWidgetChanged.addEventListener(function() {
1092
- // addUpdateSubscription();
1093
- // }, this);
1094
- }
1095
-
1096
- DistanceLegendViewModel.prototype.destroy = function () {
1097
- this.eventHelper.removeAll();
1098
- };
1099
-
1100
- DistanceLegendViewModel.prototype.show = function (container) {
1101
- var testing = void 0;
1102
- if (this.enableDistanceLegend) {
1103
- testing =
1104
- '<div class="distance-legend" data-bind="visible: distanceLabel && barWidth">' +
1105
- '<div class="distance-legend-label" data-bind="text: distanceLabel"></div>' +
1106
- '<div class="distance-legend-scale-bar" data-bind="style: { width: barWidth + \'px\', left: (5 + (125 - barWidth) / 2) + \'px\' }"></div>' +
1107
- '</div>';
1108
- } else {
1109
- testing =
1110
- '<div class="distance-legend" style="display: none;" data-bind="visible: distanceLabel && barWidth">' +
1111
- '<div class="distance-legend-label" data-bind="text: distanceLabel"></div>' +
1112
- '<div class="distance-legend-scale-bar" data-bind="style: { width: barWidth + \'px\', left: (5 + (125 - barWidth) / 2) + \'px\' }"></div>' +
1113
- '</div>';
1114
- }
1115
- loadView(testing, container, this);
1116
- // loadView(distanceLegendTemplate, container, this);
1117
- // loadView(require('fs').readFileSync(
1118
- // __dirname + '/../Views/DistanceLegend.html', 'utf8'), container, this);
1119
- };
1120
-
1121
- DistanceLegendViewModel.create = function (options) {
1122
- var result = new DistanceLegendViewModel(options);
1123
- result.show(options.container);
1124
- return result;
1125
- };
1126
-
1127
- var geodesic = new cesium.EllipsoidGeodesic();
1128
-
1129
- var distances = [
1130
- 1,
1131
- 2,
1132
- 3,
1133
- 5,
1134
- 10,
1135
- 20,
1136
- 30,
1137
- 50,
1138
- 100,
1139
- 200,
1140
- 300,
1141
- 500,
1142
- 1000,
1143
- 2000,
1144
- 3000,
1145
- 5000,
1146
- 10000,
1147
- 20000,
1148
- 30000,
1149
- 50000,
1150
- 100000,
1151
- 200000,
1152
- 300000,
1153
- 500000,
1154
- 1000000,
1155
- 2000000,
1156
- 3000000,
1157
- 5000000,
1158
- 10000000,
1159
- 20000000,
1160
- 30000000,
1161
- 50000000];
1162
-
1163
-
1164
- /**
1165
- * @param {KnockoutViewModel} _viewModel
1166
- * @param {HtmlElement} scene
1167
- * @param {Object} options
1168
- * @param {TufHelper.Units} options.units
1169
- * @param {(_:Number, _: Units): string => {}} options.distanceLabelFormatter
1170
- */
1171
- function updateDistanceLegendCesium(
1172
- _viewModel,
1173
- scene)
1174
-
1175
-
1176
-
1177
-
1178
- {var _ref = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {},_ref$units = _ref.units,units = _ref$units === undefined ? 'kilometers' : _ref$units,_ref$distanceLabelFor = _ref.distanceLabelFormatter,distanceLabelFormatter$$1 = _ref$distanceLabelFor === undefined ? distanceLabelFormatter : _ref$distanceLabelFor;
1179
- var viewModel = _viewModel;
1180
- if (!viewModel.enableDistanceLegend) {
1181
- viewModel.barWidth = undefined;
1182
- viewModel.distanceLabel = undefined;
1183
- return;
1184
- }
1185
- var now = cesium.getTimestamp();
1186
- if (now < viewModel._lastLegendUpdate + 250) {
1187
- return;
1188
- }
1189
-
1190
- viewModel._lastLegendUpdate = now;
1191
-
1192
- // Find the distance between two pixels at the bottom center of the screen.
1193
- var width = scene.canvas.clientWidth;
1194
- var height = scene.canvas.clientHeight;
1195
-
1196
- var left = scene.camera.getPickRay(
1197
- new cesium.Cartesian2(width / 2 | 0, height - 1));
1198
-
1199
- var right = scene.camera.getPickRay(
1200
- new cesium.Cartesian2(1 + width / 2 | 0, height - 1));var
1201
-
1202
-
1203
- globe = scene.globe;
1204
- var leftPosition = globe.pick(left, scene);
1205
- var rightPosition = globe.pick(right, scene);
1206
-
1207
- if (!cesium.defined(leftPosition) || !cesium.defined(rightPosition)) {
1208
- viewModel.barWidth = undefined;
1209
- viewModel.distanceLabel = undefined;
1210
- return;
1211
- }
1212
-
1213
- var leftCartographic = globe.ellipsoid.cartesianToCartographic(
1214
- leftPosition);
1215
-
1216
- var rightCartographic = globe.ellipsoid.cartesianToCartographic(
1217
- rightPosition);
1218
-
1219
-
1220
- geodesic.setEndPoints(leftCartographic, rightCartographic);
1221
- var pixelDistance = geodesic.surfaceDistance;
1222
-
1223
- // Find the first distance that makes the scale bar less than 100 pixels.
1224
- var maxBarWidth = 100;
1225
- var distance = void 0;
1226
- for (var i = distances.length - 1; !cesium.defined(distance) && i >= 0; --i) {
1227
- if (distances[i] / pixelDistance < maxBarWidth) {
1228
- distance = distances[i];
1229
- }
1230
- }
1231
-
1232
- if (cesium.defined(distance)) {
1233
- var convertedDistance = helpers_25(distance, 'meters', units);
1234
- var label = distanceLabelFormatter$$1(convertedDistance, units);
1235
-
1236
- viewModel.barWidth = distance / pixelDistance | 0;
1237
- viewModel.distanceLabel = label;
1238
- } else {
1239
- viewModel.barWidth = undefined;
1240
- viewModel.distanceLabel = undefined;
1241
- }
1242
- }
1243
-
1244
- /**
1245
- * The view-model for a control in the user interface
1246
- *
1247
- * @alias UserInterfaceControl
1248
- * @constructor
1249
- * @abstract
1250
- *
1251
- * @param {Terria} terria The Terria instance.
1252
- */
1253
- function UserInterfaceControl(terria) {
1254
- if (!cesium.defined(terria)) {
1255
- throw new cesium.DeveloperError('terria is required');
1256
- }
1257
-
1258
- this._terria = terria;
1259
-
1260
- /**
1261
- * Gets or sets the name of the control which is set as the controls title.
1262
- * This property is observable.
1263
- * @type {String}
1264
- */
1265
- this.name = 'Unnamed Control';
1266
-
1267
- /**
1268
- * Gets or sets the text to be displayed in the UI control.
1269
- * This property is observable.
1270
- * @type {String}
1271
- */
1272
- this.text = undefined;
1273
-
1274
- /**
1275
- * Gets or sets the svg icon of the control. This property is observable.
1276
- * @type {Object}
1277
- */
1278
- this.svgIcon = undefined;
1279
-
1280
- /**
1281
- * Gets or sets the height of the svg icon. This property is observable.
1282
- * @type {Integer}
1283
- */
1284
- this.svgHeight = undefined;
1285
-
1286
- /**
1287
- * Gets or sets the width of the svg icon. This property is observable.
1288
- * @type {Integer}
1289
- */
1290
- this.svgWidth = undefined;
1291
-
1292
- /**
1293
- * Gets or sets the CSS class of the control. This property is observable.
1294
- * @type {String}
1295
- */
1296
- this.cssClass = undefined;
1297
-
1298
- /**
1299
- * Gets or sets the property describing whether or not the control is in the active state.
1300
- * This property is observable.
1301
- * @type {Boolean}
1302
- */
1303
- this.isActive = false;
1304
-
1305
- Knockout.track(this, [
1306
- 'name',
1307
- 'svgIcon',
1308
- 'svgHeight',
1309
- 'svgWidth',
1310
- 'cssClass',
1311
- 'isActive']);
1312
-
1313
- }
1314
-
1315
- Object.defineProperties(UserInterfaceControl.prototype, {
1316
- /**
1317
- * Gets the Terria instance.
1318
- * @memberOf UserInterfaceControl.prototype
1319
- * @type {Terria}
1320
- */
1321
- terria: {
1322
- get: function get() {
1323
- return this._terria;
1324
- } },
1325
-
1326
- /**
1327
- * Gets a value indicating whether this button has text associated with it.
1328
- * @type {Object}
1329
- */
1330
- hasText: {
1331
- get: function get() {
1332
- return cesium.defined(this.text) && typeof this.text === 'string';
1333
- } } });
1334
-
1335
-
1336
-
1337
- /**
1338
- * When implemented in a derived class, performs an action when the user clicks
1339
- * on this control.
1340
- * @abstract
1341
- * @protected
1342
- */
1343
- UserInterfaceControl.prototype.activate = function () {
1344
- throw new cesium.DeveloperError(
1345
- 'activate must be implemented in the derived class.');
1346
-
1347
- };
1348
-
1349
- function _classCallCheck(instance, Constructor) {if (!(instance instanceof Constructor)) {throw new TypeError("Cannot call a class as a function");}}function _possibleConstructorReturn(self, call) {if (!self) {throw new ReferenceError("this hasn't been initialised - super() hasn't been called");}return call && (typeof call === "object" || typeof call === "function") ? call : self;}function _inherits(subClass, superClass) {if (typeof superClass !== "function" && superClass !== null) {throw new TypeError("Super expression must either be null or a function, not " + typeof superClass);}subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } });if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass;}var
1350
-
1351
- NavigationControl = function (_UserInterfaceControl) {_inherits(NavigationControl, _UserInterfaceControl);function NavigationControl() {_classCallCheck(this, NavigationControl);return _possibleConstructorReturn(this, (NavigationControl.__proto__ || Object.getPrototypeOf(NavigationControl)).apply(this, arguments));}return NavigationControl;}(UserInterfaceControl);
1352
-
1353
- var svgReset = 'M 7.5,0 C 3.375,0 0,3.375 0,7.5 0,11.625 3.375,15 7.5,15 c 3.46875,0 6.375,-2.4375 7.21875,-5.625 l -1.96875,0 C 12,11.53125 9.9375,13.125 7.5,13.125 4.40625,13.125 1.875,10.59375 1.875,7.5 1.875,4.40625 4.40625,1.875 7.5,1.875 c 1.59375,0 2.90625,0.65625 3.9375,1.6875 l -3,3 6.5625,0 L 15,0 12.75,2.25 C 11.4375,0.84375 9.5625,0 7.5,0 z';
1354
-
1355
- /**
1356
- * The model for a zoom in control in the navigation control tool bar
1357
- *
1358
- * @alias ResetViewNavigationControl
1359
- * @constructor
1360
- * @abstract
1361
- *
1362
- * @param {Terria} terria The Terria instance.
1363
- */
1364
- function ResetViewNavigationControl() {for (var _len = arguments.length, args = Array(_len), _key = 0; _key < _len; _key++) {args[_key] = arguments[_key];}
1365
- NavigationControl.apply(this, args);
1366
-
1367
- /**
1368
- * Gets or sets the name of the control which is set as the control's title.
1369
- * This property is observable.
1370
- * @type {String}
1371
- */
1372
- this.name = 'Reset View';
1373
- this.navigationLocked = false;
1374
-
1375
- /**
1376
- * Gets or sets the svg icon of the control. This property is observable.
1377
- * @type {Object}
1378
- */
1379
- this.svgIcon = svgReset;
1380
-
1381
- /**
1382
- * Gets or sets the height of the svg icon. This property is observable.
1383
- * @type {Integer}
1384
- */
1385
- this.svgHeight = 15;
1386
-
1387
- /**
1388
- * Gets or sets the width of the svg icon. This property is observable.
1389
- * @type {Integer}
1390
- */
1391
- this.svgWidth = 15;
1392
-
1393
- /**
1394
- * Gets or sets the CSS class of the control. This property is observable.
1395
- * @type {String}
1396
- */
1397
- this.cssClass = 'navigation-control-icon-reset';
1398
- }
1399
-
1400
- ResetViewNavigationControl.prototype = Object.create(
1401
- NavigationControl.prototype);
1402
-
1403
-
1404
- ResetViewNavigationControl.prototype.setNavigationLocked = function (locked) {
1405
- this.navigationLocked = locked;
1406
- };
1407
-
1408
- ResetViewNavigationControl.prototype.resetView = function () {
1409
- // this.terria.analytics.logEvent('navigation', 'click', 'reset');
1410
- if (this.navigationLocked) {
1411
- return;
1412
- }var
1413
- scene = this.terria.scene;
1414
-
1415
- var sscc = scene.screenSpaceCameraController;
1416
- if (!sscc.enableInputs) {
1417
- return;
1418
- }
1419
-
1420
- this.isActive = true;var
1421
-
1422
- camera = scene.camera;
1423
-
1424
- if (cesium.defined(this.terria.trackedEntity)) {
1425
- // when tracking do not reset to default view but to default view of tracked entity
1426
- var trackedEntity = this.terria.trackedEntity;
1427
- this.terria.trackedEntity = undefined;
1428
- this.terria.trackedEntity = trackedEntity;
1429
- } else {
1430
- // reset to a default position or view defined in the options
1431
- if (this.terria.options.defaultResetView) {
1432
- if (
1433
- this.terria.options.defaultResetView &&
1434
- this.terria.options.defaultResetView instanceof cesium.Cartographic)
1435
- {
1436
- camera.flyTo({
1437
- destination: scene.globe.ellipsoid.cartographicToCartesian(
1438
- this.terria.options.defaultResetView) });
1439
-
1440
-
1441
- } else if (
1442
- this.terria.options.defaultResetView &&
1443
- this.terria.options.defaultResetView instanceof cesium.Rectangle)
1444
- {
1445
- try {
1446
- cesium.Rectangle.validate(this.terria.options.defaultResetView);
1447
- camera.flyTo({
1448
- destination: this.terria.options.defaultResetView });
1449
-
1450
- } catch (e) {
1451
- console.warn(
1452
- 'Cesium-navigation/ResetViewNavigationControl: options.defaultResetView Cesium rectangle is invalid!');
1453
-
1454
- }
1455
- }
1456
- } else if (typeof camera.flyHome === 'function') {
1457
- camera.flyHome(1);
1458
- } else {
1459
- camera.flyTo({
1460
- destination: cesium.Camera.DEFAULT_VIEW_RECTANGLE,
1461
- duration: 1 });
1462
-
1463
- }
1464
- }
1465
- this.isActive = false;
1466
- };
1467
-
1468
- /**
1469
- * When implemented in a derived class, performs an action when the user clicks
1470
- * on this control
1471
- * @abstract
1472
- * @protected
1473
- */
1474
- ResetViewNavigationControl.prototype.activate = function () {
1475
- this.resetView();
1476
- };
1477
-
1478
- /**
1479
- * The model for a zoom in control in the navigation control tool bar
1480
- *
1481
- * @alias ZoomOutNavigationControl
1482
- * @constructor
1483
- * @abstract
1484
- *
1485
- * @param {Terria} terria The Terria instance.
1486
- * @param {boolean} zoomIn is used for zooming in (true) or out (false)
1487
- */
1488
- function ZoomNavigationControl() {for (var _len = arguments.length, args = Array(_len), _key = 0; _key < _len; _key++) {args[_key] = arguments[_key];}
1489
- var zoomIn = args[1];
1490
- NavigationControl.apply(this, args);
1491
-
1492
- /**
1493
- * Gets or sets the name of the control which is set as the control's title.
1494
- * This property is observable.
1495
- * @type {String}
1496
- */
1497
- this.name = 'Zoom ' + (zoomIn ? 'In' : 'Out');
1498
-
1499
- /**
1500
- * Gets or sets the text to be displayed in the nav control. Controls that
1501
- * have text do not display the svgIcon.
1502
- * This property is observable.
1503
- * @type {String}
1504
- */
1505
- this.text = zoomIn ? '+' : '-';
1506
-
1507
- /**
1508
- * Gets or sets the CSS class of the control. This property is observable.
1509
- * @type {String}
1510
- */
1511
- this.cssClass = 'navigation-control-icon-zoom-' + (zoomIn ? 'in' : 'out');
1512
-
1513
- this.relativeAmount = 2;
1514
-
1515
- if (zoomIn) {
1516
- // this ensures that zooming in is the inverse of zooming out and vice versa
1517
- // e.g. the camera position remains when zooming in and out
1518
- this.relativeAmount = 1 / this.relativeAmount;
1519
- }
1520
- }
1521
-
1522
- ZoomNavigationControl.prototype.relativeAmount = 1;
1523
-
1524
- ZoomNavigationControl.prototype = Object.create(NavigationControl.prototype);
1525
-
1526
- /**
1527
- * When implemented in a derived class, performs an action when the user clicks
1528
- * on this control
1529
- * @abstract
1530
- * @protected
1531
- */
1532
- ZoomNavigationControl.prototype.activate = function () {
1533
- this.zoom(this.relativeAmount);
1534
- };
1535
-
1536
- var cartesian3Scratch = new cesium.Cartesian3();
1537
-
1538
- ZoomNavigationControl.prototype.zoom = function (relativeAmount) {
1539
- // this.terria.analytics.logEvent('navigation', 'click', 'zoomIn');
1540
-
1541
- this.isActive = true;
1542
-
1543
- if (cesium.defined(this.terria)) {var
1544
- scene = this.terria.scene;
1545
-
1546
- var sscc = scene.screenSpaceCameraController;
1547
- // do not zoom if it is disabled
1548
- if (!sscc.enableInputs || !sscc.enableZoom) {
1549
- return;
1550
- }
1551
- // TODO
1552
- // if(scene.mode == SceneMode.COLUMBUS_VIEW && !sscc.enableTranslate) {
1553
- // return;
1554
- // }
1555
- var
1556
- camera = scene.camera;
1557
- var orientation = void 0;
1558
-
1559
- switch (scene.mode) {
1560
- case cesium.SceneMode.MORPHING:
1561
- break;
1562
- case cesium.SceneMode.SCENE2D:
1563
- camera.zoomIn(
1564
- camera.positionCartographic.height * (1 - this.relativeAmount));
1565
-
1566
- break;
1567
- default:{
1568
- var focus = void 0;
1569
-
1570
- if (cesium.defined(this.terria.trackedEntity)) {
1571
- focus = new cesium.Cartesian3();
1572
- } else {
1573
- focus = getCameraFocus(this.terria, false);
1574
- }
1575
-
1576
- if (!cesium.defined(focus)) {
1577
- // Camera direction is not pointing at the globe, so use the ellipsoid horizon point as
1578
- // the focal point.
1579
- var ray = new cesium.Ray(
1580
- camera.worldToCameraCoordinatesPoint(
1581
- scene.globe.ellipsoid.cartographicToCartesian(
1582
- camera.positionCartographic)),
1583
-
1584
-
1585
- camera.directionWC);
1586
-
1587
- focus = cesium.IntersectionTests.grazingAltitudeLocation(
1588
- ray,
1589
- scene.globe.ellipsoid);
1590
-
1591
-
1592
- orientation = {
1593
- heading: camera.heading,
1594
- pitch: camera.pitch,
1595
- roll: camera.roll };
1596
-
1597
- } else {
1598
- orientation = {
1599
- direction: camera.direction,
1600
- up: camera.up };
1601
-
1602
- }
1603
-
1604
- var direction = cesium.Cartesian3.subtract(
1605
- camera.position,
1606
- focus,
1607
- cartesian3Scratch);
1608
-
1609
- var movementVector = cesium.Cartesian3.multiplyByScalar(
1610
- direction,
1611
- relativeAmount,
1612
- direction);
1613
-
1614
- var endPosition = cesium.Cartesian3.add(focus, movementVector, focus);
1615
-
1616
- if (
1617
- cesium.defined(this.terria.trackedEntity) ||
1618
- scene.mode === cesium.SceneMode.COLUMBUS_VIEW)
1619
- {
1620
- // sometimes flyTo does not work (jumps to wrong position)
1621
- // so just set the position without any animation
1622
- // do not use flyTo when tracking an entity because
1623
- // during animation the position of the entity may change
1624
- camera.position = endPosition;
1625
- } else {
1626
- camera.flyTo({
1627
- destination: endPosition,
1628
- orientation: orientation,
1629
- duration: 0.5,
1630
- convert: false });
1631
-
1632
- }
1633
- }}
1634
-
1635
- }
1636
-
1637
- // this.terria.notifyRepaintRequired();
1638
- this.isActive = false;
1639
- };
1640
-
1641
- var svgCompassOuterRing = 'm 66.5625,0 0,15.15625 3.71875,0 0,-10.40625 5.5,10.40625 4.375,0 0,-15.15625 -3.71875,0 0,10.40625 L 70.9375,0 66.5625,0 z M 72.5,20.21875 c -28.867432,0 -52.28125,23.407738 -52.28125,52.28125 0,28.87351 23.413818,52.3125 52.28125,52.3125 28.86743,0 52.28125,-23.43899 52.28125,-52.3125 0,-28.873512 -23.41382,-52.28125 -52.28125,-52.28125 z m 0,1.75 c 13.842515,0 26.368948,5.558092 35.5,14.5625 l -11.03125,11 0.625,0.625 11.03125,-11 c 8.9199,9.108762 14.4375,21.579143 14.4375,35.34375 0,13.764606 -5.5176,26.22729 -14.4375,35.34375 l -11.03125,-11 -0.625,0.625 11.03125,11 c -9.130866,9.01087 -21.658601,14.59375 -35.5,14.59375 -13.801622,0 -26.321058,-5.53481 -35.4375,-14.5 l 11.125,-11.09375 c 6.277989,6.12179 14.857796,9.90625 24.3125,9.90625 19.241896,0 34.875,-15.629154 34.875,-34.875 0,-19.245847 -15.633104,-34.84375 -34.875,-34.84375 -9.454704,0 -18.034511,3.760884 -24.3125,9.875 L 37.0625,36.4375 C 46.179178,27.478444 58.696991,21.96875 72.5,21.96875 z m -0.875,0.84375 0,13.9375 1.75,0 0,-13.9375 -1.75,0 z M 36.46875,37.0625 47.5625,48.15625 C 41.429794,54.436565 37.65625,63.027539 37.65625,72.5 c 0,9.472461 3.773544,18.055746 9.90625,24.34375 L 36.46875,107.9375 c -8.96721,-9.1247 -14.5,-21.624886 -14.5,-35.4375 0,-13.812615 5.53279,-26.320526 14.5,-35.4375 z M 72.5,39.40625 c 18.297686,0 33.125,14.791695 33.125,33.09375 0,18.302054 -14.827314,33.125 -33.125,33.125 -18.297687,0 -33.09375,-14.822946 -33.09375,-33.125 0,-18.302056 14.796063,-33.09375 33.09375,-33.09375 z M 22.84375,71.625 l 0,1.75 13.96875,0 0,-1.75 -13.96875,0 z m 85.5625,0 0,1.75 14,0 0,-1.75 -14,0 z M 71.75,108.25 l 0,13.9375 1.71875,0 0,-13.9375 -1.71875,0 z';
1642
-
1643
- var svgCompassGyro = 'm 72.71875,54.375 c -0.476702,0 -0.908208,0.245402 -1.21875,0.5625 -0.310542,0.317098 -0.551189,0.701933 -0.78125,1.1875 -0.172018,0.363062 -0.319101,0.791709 -0.46875,1.25 -6.91615,1.075544 -12.313231,6.656514 -13,13.625 -0.327516,0.117495 -0.661877,0.244642 -0.9375,0.375 -0.485434,0.22959 -0.901634,0.471239 -1.21875,0.78125 -0.317116,0.310011 -0.5625,0.742111 -0.5625,1.21875 l 0.03125,0 c 0,0.476639 0.245384,0.877489 0.5625,1.1875 0.317116,0.310011 0.702066,0.58291 1.1875,0.8125 0.35554,0.168155 0.771616,0.32165 1.21875,0.46875 1.370803,6.10004 6.420817,10.834127 12.71875,11.8125 0.146999,0.447079 0.30025,0.863113 0.46875,1.21875 0.230061,0.485567 0.470708,0.870402 0.78125,1.1875 0.310542,0.317098 0.742048,0.5625 1.21875,0.5625 0.476702,0 0.876958,-0.245402 1.1875,-0.5625 0.310542,-0.317098 0.582439,-0.701933 0.8125,-1.1875 0.172018,-0.363062 0.319101,-0.791709 0.46875,-1.25 6.249045,-1.017063 11.256351,-5.7184 12.625,-11.78125 0.447134,-0.1471 0.86321,-0.300595 1.21875,-0.46875 0.485434,-0.22959 0.901633,-0.502489 1.21875,-0.8125 0.317117,-0.310011 0.5625,-0.710861 0.5625,-1.1875 l -0.03125,0 c 0,-0.476639 -0.245383,-0.908739 -0.5625,-1.21875 C 89.901633,71.846239 89.516684,71.60459 89.03125,71.375 88.755626,71.244642 88.456123,71.117495 88.125,71 87.439949,64.078341 82.072807,58.503735 75.21875,57.375 c -0.15044,-0.461669 -0.326927,-0.884711 -0.5,-1.25 -0.230061,-0.485567 -0.501958,-0.870402 -0.8125,-1.1875 -0.310542,-0.317098 -0.710798,-0.5625 -1.1875,-0.5625 z m -0.0625,1.40625 c 0.03595,-0.01283 0.05968,0 0.0625,0 0.0056,0 0.04321,-0.02233 0.1875,0.125 0.144288,0.147334 0.34336,0.447188 0.53125,0.84375 0.06385,0.134761 0.123901,0.309578 0.1875,0.46875 -0.320353,-0.01957 -0.643524,-0.0625 -0.96875,-0.0625 -0.289073,0 -0.558569,0.04702 -0.84375,0.0625 C 71.8761,57.059578 71.936151,56.884761 72,56.75 c 0.18789,-0.396562 0.355712,-0.696416 0.5,-0.84375 0.07214,-0.07367 0.120304,-0.112167 0.15625,-0.125 z m 0,2.40625 c 0.448007,0 0.906196,0.05436 1.34375,0.09375 0.177011,0.592256 0.347655,1.271044 0.5,2.03125 0.475097,2.370753 0.807525,5.463852 0.9375,8.9375 -0.906869,-0.02852 -1.834463,-0.0625 -2.78125,-0.0625 -0.92298,0 -1.802327,0.03537 -2.6875,0.0625 0.138529,-3.473648 0.493653,-6.566747 0.96875,-8.9375 0.154684,-0.771878 0.320019,-1.463985 0.5,-2.0625 0.405568,-0.03377 0.804291,-0.0625 1.21875,-0.0625 z m -2.71875,0.28125 c -0.129732,0.498888 -0.259782,0.987558 -0.375,1.5625 -0.498513,2.487595 -0.838088,5.693299 -0.96875,9.25 -3.21363,0.15162 -6.119596,0.480068 -8.40625,0.9375 -0.682394,0.136509 -1.275579,0.279657 -1.84375,0.4375 0.799068,-6.135482 5.504716,-11.036454 11.59375,-12.1875 z M 75.5,58.5 c 6.043169,1.18408 10.705093,6.052712 11.5,12.15625 -0.569435,-0.155806 -1.200273,-0.302525 -1.875,-0.4375 -2.262525,-0.452605 -5.108535,-0.783809 -8.28125,-0.9375 -0.130662,-3.556701 -0.470237,-6.762405 -0.96875,-9.25 C 75.761959,59.467174 75.626981,58.990925 75.5,58.5 z m -2.84375,12.09375 c 0.959338,0 1.895843,0.03282 2.8125,0.0625 C 75.48165,71.267751 75.5,71.871028 75.5,72.5 c 0,1.228616 -0.01449,2.438313 -0.0625,3.59375 -0.897358,0.0284 -1.811972,0.0625 -2.75,0.0625 -0.927373,0 -1.831062,-0.03473 -2.71875,-0.0625 -0.05109,-1.155437 -0.0625,-2.365134 -0.0625,-3.59375 0,-0.628972 0.01741,-1.232249 0.03125,-1.84375 0.895269,-0.02827 1.783025,-0.0625 2.71875,-0.0625 z M 68.5625,70.6875 c -0.01243,0.60601 -0.03125,1.189946 -0.03125,1.8125 0,1.22431 0.01541,2.407837 0.0625,3.5625 -3.125243,-0.150329 -5.92077,-0.471558 -8.09375,-0.90625 -0.784983,-0.157031 -1.511491,-0.316471 -2.125,-0.5 -0.107878,-0.704096 -0.1875,-1.422089 -0.1875,-2.15625 0,-0.115714 0.02849,-0.228688 0.03125,-0.34375 0.643106,-0.20284 1.389577,-0.390377 2.25,-0.5625 2.166953,-0.433487 4.97905,-0.75541 8.09375,-0.90625 z m 8.3125,0.03125 c 3.075121,0.15271 5.824455,0.446046 7.96875,0.875 0.857478,0.171534 1.630962,0.360416 2.28125,0.5625 0.0027,0.114659 0,0.228443 0,0.34375 0,0.735827 -0.07914,1.450633 -0.1875,2.15625 -0.598568,0.180148 -1.29077,0.34562 -2.0625,0.5 -2.158064,0.431708 -4.932088,0.754666 -8.03125,0.90625 0.04709,-1.154663 0.0625,-2.33819 0.0625,-3.5625 0,-0.611824 -0.01924,-1.185379 -0.03125,-1.78125 z M 57.15625,72.5625 c 0.0023,0.572772 0.06082,1.131112 0.125,1.6875 -0.125327,-0.05123 -0.266577,-0.10497 -0.375,-0.15625 -0.396499,-0.187528 -0.665288,-0.387337 -0.8125,-0.53125 -0.147212,-0.143913 -0.15625,-0.182756 -0.15625,-0.1875 0,-0.0047 -0.02221,-0.07484 0.125,-0.21875 0.147212,-0.143913 0.447251,-0.312472 0.84375,-0.5 0.07123,-0.03369 0.171867,-0.06006 0.25,-0.09375 z m 31.03125,0 c 0.08201,0.03503 0.175941,0.05872 0.25,0.09375 0.396499,0.187528 0.665288,0.356087 0.8125,0.5 0.14725,0.14391 0.15625,0.21405 0.15625,0.21875 0,0.0047 -0.009,0.04359 -0.15625,0.1875 -0.147212,0.143913 -0.416001,0.343722 -0.8125,0.53125 -0.09755,0.04613 -0.233314,0.07889 -0.34375,0.125 0.06214,-0.546289 0.09144,-1.094215 0.09375,-1.65625 z m -29.5,3.625 c 0.479308,0.123125 0.983064,0.234089 1.53125,0.34375 2.301781,0.460458 5.229421,0.787224 8.46875,0.9375 0.167006,2.84339 0.46081,5.433176 0.875,7.5 0.115218,0.574942 0.245268,1.063612 0.375,1.5625 -5.463677,-1.028179 -9.833074,-5.091831 -11.25,-10.34375 z m 27.96875,0 C 85.247546,81.408945 80.919274,85.442932 75.5,86.5 c 0.126981,-0.490925 0.261959,-0.967174 0.375,-1.53125 0.41419,-2.066824 0.707994,-4.65661 0.875,-7.5 3.204493,-0.15162 6.088346,-0.480068 8.375,-0.9375 0.548186,-0.109661 1.051942,-0.220625 1.53125,-0.34375 z M 70.0625,77.53125 c 0.865391,0.02589 1.723666,0.03125 2.625,0.03125 0.912062,0 1.782843,-0.0048 2.65625,-0.03125 -0.165173,2.736408 -0.453252,5.207651 -0.84375,7.15625 -0.152345,0.760206 -0.322989,1.438994 -0.5,2.03125 -0.437447,0.03919 -0.895856,0.0625 -1.34375,0.0625 -0.414943,0 -0.812719,-0.02881 -1.21875,-0.0625 -0.177011,-0.592256 -0.347655,-1.271044 -0.5,-2.03125 -0.390498,-1.948599 -0.700644,-4.419842 -0.875,-7.15625 z m 1.75,10.28125 c 0.284911,0.01545 0.554954,0.03125 0.84375,0.03125 0.325029,0 0.648588,-0.01171 0.96875,-0.03125 -0.05999,0.148763 -0.127309,0.31046 -0.1875,0.4375 -0.18789,0.396562 -0.386962,0.696416 -0.53125,0.84375 -0.144288,0.147334 -0.181857,0.125 -0.1875,0.125 -0.0056,0 -0.07446,0.02233 -0.21875,-0.125 C 72.355712,88.946416 72.18789,88.646562 72,88.25 71.939809,88.12296 71.872486,87.961263 71.8125,87.8125 z';
1644
-
1645
- var svgCompassRotationMarker = 'M 72.46875,22.03125 C 59.505873,22.050338 46.521615,27.004287 36.6875,36.875 L 47.84375,47.96875 C 61.521556,34.240041 83.442603,34.227389 97.125,47.90625 l 11.125,-11.125 C 98.401629,26.935424 85.431627,22.012162 72.46875,22.03125 z';
1646
-
1647
- function NavigationViewModel(options) {
1648
- this.terria = options.terria;
1649
- this.eventHelper = new cesium.EventHelper();
1650
- this.enableZoomControls = cesium.defined(options.enableZoomControls) ?
1651
- options.enableZoomControls :
1652
- true;
1653
- this.enableCompass = cesium.defined(options.enableCompass) ?
1654
- options.enableCompass :
1655
- true;
1656
- this.navigationLocked = false;
1657
-
1658
- // if (this.showZoomControls)
1659
- // {
1660
- this.controls = options.controls;
1661
- if (!cesium.defined(this.controls)) {
1662
- this.controls = [
1663
- new ZoomNavigationControl(this.terria, true),
1664
- new ResetViewNavigationControl(this.terria),
1665
- new ZoomNavigationControl(this.terria, false)];
1666
-
1667
- }
1668
- // }
1669
-
1670
- this.svgCompassOuterRing = svgCompassOuterRing;
1671
- this.svgCompassGyro = svgCompassGyro;
1672
- this.svgCompassRotationMarker = svgCompassRotationMarker;
1673
-
1674
- this.showCompass = cesium.defined(this.terria) && this.enableCompass;
1675
- this.heading = this.showCompass ? this.terria.scene.camera.heading : 0.0;
1676
-
1677
- this.isOrbiting = false;
1678
- this.orbitCursorAngle = 0;
1679
- this.orbitCursorOpacity = 0.0;
1680
- this.orbitLastTimestamp = 0;
1681
- this.orbitFrame = undefined;
1682
- this.orbitIsLook = false;
1683
- this.orbitMouseMoveFunction = undefined;
1684
- this.orbitMouseUpFunction = undefined;
1685
-
1686
- this.isRotating = false;
1687
- this.rotateInitialCursorAngle = undefined;
1688
- this.rotateFrame = undefined;
1689
- this.rotateIsLook = false;
1690
- this.rotateMouseMoveFunction = undefined;
1691
- this.rotateMouseUpFunction = undefined;
1692
-
1693
- this._unsubcribeFromPostRender = undefined;
1694
-
1695
- Knockout.track(this, [
1696
- 'controls',
1697
- 'showCompass',
1698
- 'heading',
1699
- 'isOrbiting',
1700
- 'orbitCursorAngle',
1701
- 'isRotating']);
1702
-
1703
-
1704
- var that = this;
1705
-
1706
- NavigationViewModel.prototype.setNavigationLocked = function (locked) {
1707
- this.navigationLocked = locked;
1708
- if (this.controls && this.controls.length > 1) {
1709
- this.controls[1].setNavigationLocked(this.navigationLocked);
1710
- }
1711
- };
1712
-
1713
- function widgetChange() {
1714
- if (cesium.defined(that.terria)) {
1715
- if (that._unsubcribeFromPostRender) {
1716
- that._unsubcribeFromPostRender();
1717
- that._unsubcribeFromPostRender = undefined;
1718
- }
1719
-
1720
- that.showCompass = that.enableCompass;
1721
-
1722
- that._unsubcribeFromPostRender = that.terria.scene.postRender.addEventListener(
1723
- function () {
1724
- that.heading = that.terria.scene.camera.heading;
1725
- });
1726
-
1727
- } else {
1728
- if (that._unsubcribeFromPostRender) {
1729
- that._unsubcribeFromPostRender();
1730
- that._unsubcribeFromPostRender = undefined;
1731
- }
1732
- that.showCompass = false;
1733
- }
1734
- }
1735
-
1736
- this.eventHelper.add(this.terria.afterWidgetChanged, widgetChange, this);
1737
- // this.terria.afterWidgetChanged.addEventListener(widgetChange);
1738
-
1739
- widgetChange();
1740
- }
1741
-
1742
- NavigationViewModel.prototype.destroy = function () {
1743
- this.eventHelper.removeAll();
1744
-
1745
- // loadView(require('fs').readFileSync(baseURLEmpCesium
1746
- // + 'js-lib/terrajs/lib/Views/Navigation.html', 'utf8'), container, this);
1747
- };
1748
-
1749
- NavigationViewModel.prototype.show = function (container) {
1750
- var testing = void 0;
1751
- if (this.enableZoomControls && this.enableCompass) {
1752
- testing =
1753
- '<div class="compass" title="Drag outer ring: rotate view. ' +
1754
- 'Drag inner gyroscope: free orbit.' +
1755
- 'Double-click: reset view.' +
1756
- 'TIP: You can also free orbit by holding the CTRL key and dragging the map." data-bind="visible: showCompass, event: { mousedown: handleMouseDown, dblclick: handleDoubleClick }">' +
1757
- '<div class="compass-outer-ring-background"></div>' +
1758
- " <div class=\"compass-rotation-marker\" data-bind=\"visible: isOrbiting, style: { transform: 'rotate(-' + orbitCursorAngle + 'rad)', '-webkit-transform': 'rotate(-' + orbitCursorAngle + 'rad)', opacity: orbitCursorOpacity }, cesiumSvgPath: { path: svgCompassRotationMarker, width: 145, height: 145 }\"></div>" +
1759
- " <div class=\"compass-outer-ring\" title=\"Click and drag to rotate the camera\" data-bind=\"style: { transform: 'rotate(-' + heading + 'rad)', '-webkit-transform': 'rotate(-' + heading + 'rad)' }, cesiumSvgPath: { path: svgCompassOuterRing, width: 145, height: 145 }\"></div>" +
1760
- ' <div class="compass-gyro-background"></div>' +
1761
- ' <div class="compass-gyro" data-bind="cesiumSvgPath: { path: svgCompassGyro, width: 145, height: 145 }, css: { \'compass-gyro-active\': isOrbiting }"></div>' +
1762
- '</div>' +
1763
- '<div class="navigation-controls">' +
1764
- '<!-- ko foreach: controls -->' +
1765
- "<div data-bind=\"click: activate, attr: { title: $data.name }, css: $root.isLastControl($data) ? 'navigation-control-last' : 'navigation-control' \">" +
1766
- ' <!-- ko if: $data.hasText -->' +
1767
- ' <div data-bind="text: $data.text, css: $data.isActive ? \'navigation-control-icon-active \' + $data.cssClass : $data.cssClass"></div>' +
1768
- ' <!-- /ko -->' +
1769
- ' <!-- ko ifnot: $data.hasText -->' +
1770
- ' <div data-bind="cesiumSvgPath: { path: $data.svgIcon, width: $data.svgWidth, height: $data.svgHeight }, css: $data.isActive ? \'navigation-control-icon-active \' + $data.cssClass : $data.cssClass"></div>' +
1771
- ' <!-- /ko -->' +
1772
- ' </div>' +
1773
- ' <!-- /ko -->' +
1774
- '</div>';
1775
- } else if (!this.enableZoomControls && this.enableCompass) {
1776
- testing =
1777
- '<div class="compass" title="Drag outer ring: rotate view. ' +
1778
- 'Drag inner gyroscope: free orbit.' +
1779
- 'Double-click: reset view.' +
1780
- 'TIP: You can also free orbit by holding the CTRL key and dragging the map." data-bind="visible: showCompass, event: { mousedown: handleMouseDown, dblclick: handleDoubleClick }">' +
1781
- '<div class="compass-outer-ring-background"></div>' +
1782
- " <div class=\"compass-rotation-marker\" data-bind=\"visible: isOrbiting, style: { transform: 'rotate(-' + orbitCursorAngle + 'rad)', '-webkit-transform': 'rotate(-' + orbitCursorAngle + 'rad)', opacity: orbitCursorOpacity }, cesiumSvgPath: { path: svgCompassRotationMarker, width: 145, height: 145 }\"></div>" +
1783
- " <div class=\"compass-outer-ring\" title=\"Click and drag to rotate the camera\" data-bind=\"style: { transform: 'rotate(-' + heading + 'rad)', '-webkit-transform': 'rotate(-' + heading + 'rad)' }, cesiumSvgPath: { path: svgCompassOuterRing, width: 145, height: 145 }\"></div>" +
1784
- ' <div class="compass-gyro-background"></div>' +
1785
- ' <div class="compass-gyro" data-bind="cesiumSvgPath: { path: svgCompassGyro, width: 145, height: 145 }, css: { \'compass-gyro-active\': isOrbiting }"></div>' +
1786
- '</div>' +
1787
- '<div class="navigation-controls" style="display: none;" >' +
1788
- '<!-- ko foreach: controls -->' +
1789
- "<div data-bind=\"click: activate, attr: { title: $data.name }, css: $root.isLastControl($data) ? 'navigation-control-last' : 'navigation-control' \">" +
1790
- ' <!-- ko if: $data.hasText -->' +
1791
- ' <div data-bind="text: $data.text, css: $data.isActive ? \'navigation-control-icon-active \' + $data.cssClass : $data.cssClass"></div>' +
1792
- ' <!-- /ko -->' +
1793
- ' <!-- ko ifnot: $data.hasText -->' +
1794
- ' <div data-bind="cesiumSvgPath: { path: $data.svgIcon, width: $data.svgWidth, height: $data.svgHeight }, css: $data.isActive ? \'navigation-control-icon-active \' + $data.cssClass : $data.cssClass"></div>' +
1795
- ' <!-- /ko -->' +
1796
- ' </div>' +
1797
- ' <!-- /ko -->' +
1798
- '</div>';
1799
- } else if (this.enableZoomControls && !this.enableCompass) {
1800
- testing =
1801
- '<div class="compass" style="display: none;" title="Drag outer ring: rotate view. ' +
1802
- 'Drag inner gyroscope: free orbit.' +
1803
- 'Double-click: reset view.' +
1804
- 'TIP: You can also free orbit by holding the CTRL key and dragging the map." data-bind="visible: showCompass, event: { mousedown: handleMouseDown, dblclick: handleDoubleClick }">' +
1805
- '<div class="compass-outer-ring-background"></div>' +
1806
- " <div class=\"compass-rotation-marker\" data-bind=\"visible: isOrbiting, style: { transform: 'rotate(-' + orbitCursorAngle + 'rad)', '-webkit-transform': 'rotate(-' + orbitCursorAngle + 'rad)', opacity: orbitCursorOpacity }, cesiumSvgPath: { path: svgCompassRotationMarker, width: 145, height: 145 }\"></div>" +
1807
- " <div class=\"compass-outer-ring\" title=\"Click and drag to rotate the camera\" data-bind=\"style: { transform: 'rotate(-' + heading + 'rad)', '-webkit-transform': 'rotate(-' + heading + 'rad)' }, cesiumSvgPath: { path: svgCompassOuterRing, width: 145, height: 145 }\"></div>" +
1808
- ' <div class="compass-gyro-background"></div>' +
1809
- ' <div class="compass-gyro" data-bind="cesiumSvgPath: { path: svgCompassGyro, width: 145, height: 145 }, css: { \'compass-gyro-active\': isOrbiting }"></div>' +
1810
- '</div>' +
1811
- '<div class="navigation-controls" >' +
1812
- '<!-- ko foreach: controls -->' +
1813
- "<div data-bind=\"click: activate, attr: { title: $data.name }, css: $root.isLastControl($data) ? 'navigation-control-last' : 'navigation-control' \">" +
1814
- ' <!-- ko if: $data.hasText -->' +
1815
- ' <div data-bind="text: $data.text, css: $data.isActive ? \'navigation-control-icon-active \' + $data.cssClass : $data.cssClass"></div>' +
1816
- ' <!-- /ko -->' +
1817
- ' <!-- ko ifnot: $data.hasText -->' +
1818
- ' <div data-bind="cesiumSvgPath: { path: $data.svgIcon, width: $data.svgWidth, height: $data.svgHeight }, css: $data.isActive ? \'navigation-control-icon-active \' + $data.cssClass : $data.cssClass"></div>' +
1819
- ' <!-- /ko -->' +
1820
- ' </div>' +
1821
- ' <!-- /ko -->' +
1822
- '</div>';
1823
- } else if (!this.enableZoomControls && !this.enableCompass) {
1824
- testing =
1825
- '<div class="compass" style="display: none;" title="Drag outer ring: rotate view. ' +
1826
- 'Drag inner gyroscope: free orbit.' +
1827
- 'Double-click: reset view.' +
1828
- 'TIP: You can also free orbit by holding the CTRL key and dragging the map." data-bind="visible: showCompass, event: { mousedown: handleMouseDown, dblclick: handleDoubleClick }">' +
1829
- '<div class="compass-outer-ring-background"></div>' +
1830
- " <div class=\"compass-rotation-marker\" data-bind=\"visible: isOrbiting, style: { transform: 'rotate(-' + orbitCursorAngle + 'rad)', '-webkit-transform': 'rotate(-' + orbitCursorAngle + 'rad)', opacity: orbitCursorOpacity }, cesiumSvgPath: { path: svgCompassRotationMarker, width: 145, height: 145 }\"></div>" +
1831
- " <div class=\"compass-outer-ring\" title=\"Click and drag to rotate the camera\" data-bind=\"style: { transform: 'rotate(-' + heading + 'rad)', '-webkit-transform': 'rotate(-' + heading + 'rad)' }, cesiumSvgPath: { path: svgCompassOuterRing, width: 145, height: 145 }\"></div>" +
1832
- ' <div class="compass-gyro-background"></div>' +
1833
- ' <div class="compass-gyro" data-bind="cesiumSvgPath: { path: svgCompassGyro, width: 145, height: 145 }, css: { \'compass-gyro-active\': isOrbiting }"></div>' +
1834
- '</div>' +
1835
- '<div class="navigation-controls" style="display: none;" >' +
1836
- '<!-- ko foreach: controls -->' +
1837
- "<div data-bind=\"click: activate, attr: { title: $data.name }, css: $root.isLastControl($data) ? 'navigation-control-last' : 'navigation-control' \">" +
1838
- ' <!-- ko if: $data.hasText -->' +
1839
- ' <div data-bind="text: $data.text, css: $data.isActive ? \'navigation-control-icon-active \' + $data.cssClass : $data.cssClass"></div>' +
1840
- ' <!-- /ko -->' +
1841
- ' <!-- ko ifnot: $data.hasText -->' +
1842
- ' <div data-bind="cesiumSvgPath: { path: $data.svgIcon, width: $data.svgWidth, height: $data.svgHeight }, css: $data.isActive ? \'navigation-control-icon-active \' + $data.cssClass : $data.cssClass"></div>' +
1843
- ' <!-- /ko -->' +
1844
- ' </div>' +
1845
- ' <!-- /ko -->' +
1846
- '</div>';
1847
- }
1848
- loadView(testing, container, this);
1849
- // loadView(navigatorTemplate, container, this);
1850
- // loadView(require('fs')
1851
- // .readFileSync(baseURLEmpCesium +
1852
- // 'js-lib/terrajs/lib/Views/Navigation.html', 'utf8'), container, this);
1853
- };
1854
-
1855
- /**
1856
- * Adds a control to this toolbar.
1857
- * @param {NavControl} control The control to add.
1858
- */
1859
- NavigationViewModel.prototype.add = function (control) {
1860
- this.controls.push(control);
1861
- };
1862
-
1863
- /**
1864
- * Removes a control from this toolbar.
1865
- * @param {NavControl} control The control to remove.
1866
- */
1867
- NavigationViewModel.prototype.remove = function (control) {
1868
- this.controls.remove(control);
1869
- };
1870
-
1871
- /**
1872
- * Checks if the control given is the last control in the control array.
1873
- * @param {NavControl} control The control to remove.
1874
- */
1875
- NavigationViewModel.prototype.isLastControl = function (control) {
1876
- return control === this.controls[this.controls.length - 1];
1877
- };
1878
-
1879
- var vectorScratch = new cesium.Cartesian2();
1880
-
1881
- NavigationViewModel.prototype.handleMouseDown = function (viewModel, e) {var
1882
- scene = this.terria.scene;
1883
- if (scene.mode === cesium.SceneMode.MORPHING) {
1884
- return true;
1885
- }
1886
- if (viewModel.navigationLocked) {
1887
- return true;
1888
- }
1889
-
1890
- var compassElement = e.currentTarget;
1891
- var compassRectangle = e.currentTarget.getBoundingClientRect();
1892
- var maxDistance = compassRectangle.width / 2.0;
1893
- var center = new cesium.Cartesian2(
1894
- (compassRectangle.right - compassRectangle.left) / 2.0,
1895
- (compassRectangle.bottom - compassRectangle.top) / 2.0);
1896
-
1897
- var clickLocation = new cesium.Cartesian2(
1898
- e.clientX - compassRectangle.left,
1899
- e.clientY - compassRectangle.top);
1900
-
1901
- var vector = cesium.Cartesian2.subtract(clickLocation, center, vectorScratch);
1902
- var distanceFromCenter = cesium.Cartesian2.magnitude(vector);
1903
-
1904
- var distanceFraction = distanceFromCenter / maxDistance;
1905
-
1906
- var nominalTotalRadius = 145;
1907
- var norminalGyroRadius = 50;
1908
-
1909
- if (distanceFraction < norminalGyroRadius / nominalTotalRadius) {
1910
- orbit(this, compassElement, vector);
1911
- // return false;
1912
- } else if (distanceFraction < 1.0) {
1913
- rotate(this, compassElement, vector);
1914
- // return false;
1915
- } else {
1916
- return true;
1917
- }
1918
- };
1919
-
1920
- var oldTransformScratch = new cesium.Matrix4();
1921
- var newTransformScratch = new cesium.Matrix4();
1922
- var centerScratch = new cesium.Cartesian3();
1923
-
1924
- NavigationViewModel.prototype.handleDoubleClick = function (viewModel) {var
1925
- scene = viewModel.terria.scene;var
1926
- camera = scene.camera;
1927
-
1928
- var sscc = scene.screenSpaceCameraController;
1929
-
1930
- if (scene.mode === cesium.SceneMode.MORPHING || !sscc.enableInputs) {
1931
- return true;
1932
- }
1933
- if (viewModel.navigationLocked) {
1934
- return true;
1935
- }
1936
- if (scene.mode === cesium.SceneMode.COLUMBUS_VIEW && !sscc.enableTranslate) {
1937
- return;
1938
- }
1939
- if (
1940
- scene.mode === cesium.SceneMode.SCENE3D ||
1941
- scene.mode === cesium.SceneMode.COLUMBUS_VIEW)
1942
- {
1943
- if (!sscc.enableLook) {
1944
- return;
1945
- }
1946
-
1947
- if (scene.mode === cesium.SceneMode.SCENE3D) {
1948
- if (!sscc.enableRotate) {
1949
- return;
1950
- }
1951
- }
1952
- }
1953
-
1954
- var center = getCameraFocus(viewModel.terria, true, centerScratch);
1955
-
1956
- if (!cesium.defined(center)) {
1957
- // Globe is barely visible, so reset to home view.
1958
-
1959
- this.controls[1].resetView();
1960
- return;
1961
- }
1962
-
1963
- var cameraPosition = scene.globe.ellipsoid.cartographicToCartesian(
1964
- camera.positionCartographic,
1965
- new cesium.Cartesian3());
1966
-
1967
-
1968
- var surfaceNormal = scene.globe.ellipsoid.geodeticSurfaceNormal(center);
1969
-
1970
- var focusBoundingSphere = new cesium.BoundingSphere(center, 0);
1971
-
1972
- camera.flyToBoundingSphere(focusBoundingSphere, {
1973
- offset: new cesium.HeadingPitchRange(
1974
- 0,
1975
- // do not use camera.pitch since the pitch at the center/target is required
1976
- cesium.Math.PI_OVER_TWO -
1977
- cesium.Cartesian3.angleBetween(surfaceNormal, camera.directionWC),
1978
- // distanceToBoundingSphere returns wrong values when in 2D or Columbus view so do not use
1979
- // camera.distanceToBoundingSphere(focusBoundingSphere)
1980
- // instead calculate distance manually
1981
- cesium.Cartesian3.distance(cameraPosition, center)),
1982
-
1983
- duration: 1.5 });
1984
-
1985
- };
1986
-
1987
- NavigationViewModel.create = function (options) {
1988
- // options.enableZoomControls = this.enableZoomControls;
1989
- // options.enableCompass = this.enableCompass;
1990
- var result = new NavigationViewModel(options);
1991
- result.show(options.container);
1992
- return result;
1993
- };
1994
-
1995
- function orbit(_viewModel, compassElement, cursorVector) {
1996
- var viewModel = _viewModel;var
1997
- scene = viewModel.terria.scene;
1998
-
1999
- var sscc = scene.screenSpaceCameraController;
2000
-
2001
- // do not orbit if it is disabled
2002
- if (scene.mode === cesium.SceneMode.MORPHING || !sscc.enableInputs) {
2003
- return;
2004
- }
2005
- if (viewModel.navigationLocked) {
2006
- return true;
2007
- }
2008
-
2009
- switch (scene.mode) {
2010
- case cesium.SceneMode.COLUMBUS_VIEW:
2011
- if (sscc.enableLook) {
2012
- break;
2013
- }
2014
-
2015
- if (!sscc.enableTranslate || !sscc.enableTilt) {
2016
- return;
2017
- }
2018
- break;
2019
- case cesium.SceneMode.SCENE3D:
2020
- if (sscc.enableLook) {
2021
- break;
2022
- }
2023
-
2024
- if (!sscc.enableTilt || !sscc.enableRotate) {
2025
- return;
2026
- }
2027
- break;
2028
- case cesium.SceneMode.SCENE2D:
2029
- if (!sscc.enableTranslate) {
2030
- return;
2031
- }
2032
- break;
2033
- default:
2034
- console.warn('scene.mode:' + scene.mode + ' bad case');}
2035
-
2036
-
2037
- // Remove existing event handlers, if any.
2038
- document.removeEventListener(
2039
- 'mousemove',
2040
- viewModel.orbitMouseMoveFunction,
2041
- false);
2042
-
2043
- document.removeEventListener(
2044
- 'mouseup',
2045
- viewModel.orbitMouseUpFunction,
2046
- false);
2047
-
2048
-
2049
- if (cesium.defined(viewModel.orbitTickFunction)) {
2050
- viewModel.terria.clock.onTick.removeEventListener(
2051
- viewModel.orbitTickFunction);
2052
-
2053
- }
2054
-
2055
- viewModel.orbitMouseMoveFunction = undefined;
2056
- viewModel.orbitMouseUpFunction = undefined;
2057
- viewModel.orbitTickFunction = undefined;
2058
-
2059
- viewModel.isOrbiting = true;
2060
- viewModel.orbitLastTimestamp = cesium.getTimestamp();var
2061
-
2062
- camera = scene.camera;
2063
-
2064
- if (cesium.defined(viewModel.terria.trackedEntity)) {
2065
- // when tracking an entity simply use that reference frame
2066
- viewModel.orbitFrame = undefined;
2067
- viewModel.orbitIsLook = false;
2068
- } else {
2069
- var center = getCameraFocus(viewModel.terria, true, centerScratch);
2070
-
2071
- if (!cesium.defined(center)) {
2072
- viewModel.orbitFrame = cesium.Transforms.eastNorthUpToFixedFrame(
2073
- camera.positionWC,
2074
- scene.globe.ellipsoid,
2075
- newTransformScratch);
2076
-
2077
- viewModel.orbitIsLook = true;
2078
- } else {
2079
- viewModel.orbitFrame = cesium.Transforms.eastNorthUpToFixedFrame(
2080
- center,
2081
- scene.globe.ellipsoid,
2082
- newTransformScratch);
2083
-
2084
- viewModel.orbitIsLook = false;
2085
- }
2086
- }
2087
-
2088
- // eslint-disable-next-line no-unused-vars
2089
- viewModel.orbitTickFunction = function (e) {
2090
- var timestamp = cesium.getTimestamp();
2091
- var deltaT = timestamp - viewModel.orbitLastTimestamp;
2092
- var rate = (viewModel.orbitCursorOpacity - 0.5) * 2.5 / 1000;
2093
- var distance = deltaT * rate;
2094
-
2095
- var angle = viewModel.orbitCursorAngle + cesium.Math.PI_OVER_TWO;
2096
- var x = Math.cos(angle) * distance;
2097
- var y = Math.sin(angle) * distance;
2098
-
2099
- var oldTransform = void 0;
2100
-
2101
- if (viewModel.navigationLocked) {
2102
- return true;
2103
- }
2104
-
2105
- if (cesium.defined(viewModel.orbitFrame)) {
2106
- oldTransform = cesium.Matrix4.clone(camera.transform, oldTransformScratch);
2107
-
2108
- camera.lookAtTransform(viewModel.orbitFrame);
2109
- }
2110
-
2111
- // do not look up/down or rotate in 2D mode
2112
- if (scene.mode === cesium.SceneMode.SCENE2D) {
2113
- camera.move(
2114
- new cesium.Cartesian3(x, y, 0),
2115
- Math.max(scene.canvas.clientWidth, scene.canvas.clientHeight) / 100 *
2116
- camera.positionCartographic.height *
2117
- distance);
2118
-
2119
- } else {
2120
- if (viewModel.orbitIsLook) {
2121
- camera.look(cesium.Cartesian3.UNIT_Z, -x);
2122
- camera.look(camera.right, -y);
2123
- } else {
2124
- camera.rotateLeft(x);
2125
- camera.rotateUp(y);
2126
- }
2127
- }
2128
-
2129
- if (cesium.defined(viewModel.orbitFrame)) {
2130
- camera.lookAtTransform(oldTransform);
2131
- }
2132
-
2133
- // viewModel.terria.cesium.notifyRepaintRequired();
2134
-
2135
- viewModel.orbitLastTimestamp = timestamp;
2136
- };
2137
-
2138
- function updateAngleAndOpacity(vector, compassWidth) {
2139
- var angle = Math.atan2(-vector.y, vector.x);
2140
- viewModel.orbitCursorAngle = cesium.Math.zeroToTwoPi(
2141
- angle - cesium.Math.PI_OVER_TWO);
2142
-
2143
-
2144
- var distance = cesium.Cartesian2.magnitude(vector);
2145
- var maxDistance = compassWidth / 2.0;
2146
- var distanceFraction = Math.min(distance / maxDistance, 1.0);
2147
- var easedOpacity = 0.5 * distanceFraction * distanceFraction + 0.5;
2148
- viewModel.orbitCursorOpacity = easedOpacity;
2149
-
2150
- // viewModel.terria.cesium.notifyRepaintRequired();
2151
- }
2152
-
2153
- viewModel.orbitMouseMoveFunction = function (e) {
2154
- var compassRectangle = compassElement.getBoundingClientRect();
2155
- var center = new cesium.Cartesian2(
2156
- (compassRectangle.right - compassRectangle.left) / 2.0,
2157
- (compassRectangle.bottom - compassRectangle.top) / 2.0);
2158
-
2159
- var clickLocation = new cesium.Cartesian2(
2160
- e.clientX - compassRectangle.left,
2161
- e.clientY - compassRectangle.top);
2162
-
2163
- var vector = cesium.Cartesian2.subtract(clickLocation, center, vectorScratch);
2164
- updateAngleAndOpacity(vector, compassRectangle.width);
2165
- };
2166
-
2167
- // eslint-disable-next-line no-unused-vars
2168
- viewModel.orbitMouseUpFunction = function (e) {
2169
- // TODO: if mouse didn't move, reset view to looking down, north is up?
2170
-
2171
- viewModel.isOrbiting = false;
2172
- document.removeEventListener(
2173
- 'mousemove',
2174
- viewModel.orbitMouseMoveFunction,
2175
- false);
2176
-
2177
- document.removeEventListener(
2178
- 'mouseup',
2179
- viewModel.orbitMouseUpFunction,
2180
- false);
2181
-
2182
-
2183
- if (cesium.defined(viewModel.orbitTickFunction)) {
2184
- viewModel.terria.clock.onTick.removeEventListener(
2185
- viewModel.orbitTickFunction);
2186
-
2187
- }
2188
-
2189
- viewModel.orbitMouseMoveFunction = undefined;
2190
- viewModel.orbitMouseUpFunction = undefined;
2191
- viewModel.orbitTickFunction = undefined;
2192
- };
2193
-
2194
- document.addEventListener(
2195
- 'mousemove',
2196
- viewModel.orbitMouseMoveFunction,
2197
- false);
2198
-
2199
- document.addEventListener('mouseup', viewModel.orbitMouseUpFunction, false);
2200
- viewModel.terria.clock.onTick.addEventListener(viewModel.orbitTickFunction);
2201
-
2202
- updateAngleAndOpacity(
2203
- cursorVector,
2204
- compassElement.getBoundingClientRect().width);
2205
-
2206
- }
2207
-
2208
- function rotate(_viewModel, compassElement, cursorVector) {
2209
- var viewModel = _viewModel;var
2210
- scene = viewModel.terria.scene;var
2211
- camera = scene.camera;
2212
-
2213
- var sscc = scene.screenSpaceCameraController;
2214
- // do not rotate in 2D mode or if rotating is disabled
2215
- if (
2216
- scene.mode === cesium.SceneMode.MORPHING ||
2217
- scene.mode === cesium.SceneMode.SCENE2D ||
2218
- !sscc.enableInputs)
2219
- {
2220
- return;
2221
- }
2222
- if (viewModel.navigationLocked) {
2223
- return true;
2224
- }
2225
-
2226
- if (
2227
- !sscc.enableLook && (
2228
- scene.mode === cesium.SceneMode.COLUMBUS_VIEW ||
2229
- scene.mode === cesium.SceneMode.SCENE3D && !sscc.enableRotate))
2230
- {
2231
- return;
2232
- }
2233
-
2234
- // Remove existing event handlers, if any.
2235
- document.removeEventListener(
2236
- 'mousemove',
2237
- viewModel.rotateMouseMoveFunction,
2238
- false);
2239
-
2240
- document.removeEventListener(
2241
- 'mouseup',
2242
- viewModel.rotateMouseUpFunction,
2243
- false);
2244
-
2245
-
2246
- viewModel.rotateMouseMoveFunction = undefined;
2247
- viewModel.rotateMouseUpFunction = undefined;
2248
-
2249
- viewModel.isRotating = true;
2250
- viewModel.rotateInitialCursorAngle = Math.atan2(
2251
- -cursorVector.y,
2252
- cursorVector.x);
2253
-
2254
-
2255
- if (cesium.defined(viewModel.terria.trackedEntity)) {
2256
- // when tracking an entity simply use that reference frame
2257
- viewModel.rotateFrame = undefined;
2258
- viewModel.rotateIsLook = false;
2259
- } else {
2260
- var viewCenter = getCameraFocus(
2261
- viewModel.terria,
2262
- true,
2263
- centerScratch);
2264
-
2265
-
2266
- if (
2267
- !cesium.defined(viewCenter) ||
2268
- scene.mode === cesium.SceneMode.COLUMBUS_VIEW &&
2269
- !sscc.enableLook &&
2270
- !sscc.enableTranslate)
2271
- {
2272
- viewModel.rotateFrame = cesium.Transforms.eastNorthUpToFixedFrame(
2273
- camera.positionWC,
2274
- scene.globe.ellipsoid,
2275
- newTransformScratch);
2276
-
2277
- viewModel.rotateIsLook = true;
2278
- } else {
2279
- viewModel.rotateFrame = cesium.Transforms.eastNorthUpToFixedFrame(
2280
- viewCenter,
2281
- scene.globe.ellipsoid,
2282
- newTransformScratch);
2283
-
2284
- viewModel.rotateIsLook = false;
2285
- }
2286
- }
2287
-
2288
- var oldTransform = void 0;
2289
- if (cesium.defined(viewModel.rotateFrame)) {
2290
- oldTransform = cesium.Matrix4.clone(camera.transform, oldTransformScratch);
2291
- camera.lookAtTransform(viewModel.rotateFrame);
2292
- }
2293
-
2294
- viewModel.rotateInitialCameraAngle = -camera.heading;
2295
-
2296
- if (cesium.defined(viewModel.rotateFrame)) {
2297
- camera.lookAtTransform(oldTransform);
2298
- }
2299
-
2300
- viewModel.rotateMouseMoveFunction = function (e) {
2301
- var compassRectangle = compassElement.getBoundingClientRect();
2302
- var center = new cesium.Cartesian2(
2303
- (compassRectangle.right - compassRectangle.left) / 2.0,
2304
- (compassRectangle.bottom - compassRectangle.top) / 2.0);
2305
-
2306
- var clickLocation = new cesium.Cartesian2(
2307
- e.clientX - compassRectangle.left,
2308
- e.clientY - compassRectangle.top);
2309
-
2310
- var vector = cesium.Cartesian2.subtract(clickLocation, center, vectorScratch);
2311
- var angle = Math.atan2(-vector.y, vector.x);
2312
-
2313
- var angleDifference = angle - viewModel.rotateInitialCursorAngle;
2314
- var newCameraAngle = cesium.Math.zeroToTwoPi(
2315
- viewModel.rotateInitialCameraAngle - angleDifference);
2316
-
2317
-
2318
- // eslint-disable-next-line
2319
- camera = viewModel.terria.scene.camera;
2320
-
2321
- if (cesium.defined(viewModel.rotateFrame)) {
2322
- oldTransform = cesium.Matrix4.clone(camera.transform, oldTransformScratch);
2323
- camera.lookAtTransform(viewModel.rotateFrame);
2324
- }
2325
-
2326
- var currentCameraAngle = -camera.heading;
2327
- camera.rotateRight(newCameraAngle - currentCameraAngle);
2328
-
2329
- if (cesium.defined(viewModel.rotateFrame)) {
2330
- camera.lookAtTransform(oldTransform);
2331
- }
2332
-
2333
- // viewModel.terria.cesium.notifyRepaintRequired();
2334
- };
2335
-
2336
- // eslint-disable-next-line no-unused-vars
2337
- viewModel.rotateMouseUpFunction = function (e) {
2338
- viewModel.isRotating = false;
2339
- document.removeEventListener(
2340
- 'mousemove',
2341
- viewModel.rotateMouseMoveFunction,
2342
- false);
2343
-
2344
- document.removeEventListener(
2345
- 'mouseup',
2346
- viewModel.rotateMouseUpFunction,
2347
- false);
2348
-
2349
-
2350
- viewModel.rotateMouseMoveFunction = undefined;
2351
- viewModel.rotateMouseUpFunction = undefined;
2352
- };
2353
-
2354
- document.addEventListener(
2355
- 'mousemove',
2356
- viewModel.rotateMouseMoveFunction,
2357
- false);
2358
-
2359
- document.addEventListener('mouseup', viewModel.rotateMouseUpFunction, false);
2360
- }
2361
-
2362
- var _extends = Object.assign || function (target) {for (var i = 1; i < arguments.length; i++) {var source = arguments[i];for (var key in source) {if (Object.prototype.hasOwnProperty.call(source, key)) {target[key] = source[key];}}}return target;};
2363
- /**
2364
- * @alias CesiumNavigation
2365
- * @constructor
2366
- *
2367
- * @param {Viewer|CesiumWidget} viewerCesiumWidget The Viewer or CesiumWidget instance
2368
- */
2369
- function CesiumNavigation() {for (var _len = arguments.length, args = Array(_len), _key = 0; _key < _len; _key++) {args[_key] = arguments[_key];}
2370
- initialize.apply(this, args);
2371
-
2372
- this._onDestroyListeners = [];
2373
- }
2374
-
2375
- CesiumNavigation.prototype.distanceLegendViewModel = undefined;
2376
- CesiumNavigation.prototype.navigationViewModel = undefined;
2377
- CesiumNavigation.prototype.navigationDiv = undefined;
2378
- CesiumNavigation.prototype.distanceLegendDiv = undefined;
2379
- CesiumNavigation.prototype.terria = undefined;
2380
- CesiumNavigation.prototype.container = undefined;
2381
- CesiumNavigation.prototype._onDestroyListeners = undefined;
2382
- CesiumNavigation.prototype._navigationLocked = false;
2383
-
2384
- CesiumNavigation.prototype.setNavigationLocked = function (locked) {
2385
- this._navigationLocked = locked;
2386
- this.navigationViewModel.setNavigationLocked(this._navigationLocked);
2387
- };
2388
-
2389
- CesiumNavigation.prototype.getNavigationLocked = function () {
2390
- return this._navigationLocked;
2391
- };
2392
-
2393
- CesiumNavigation.prototype.destroy = function () {
2394
- if (cesium.defined(this.navigationViewModel)) {
2395
- this.navigationViewModel.destroy();
2396
- }
2397
- if (cesium.defined(this.distanceLegendViewModel)) {
2398
- this.distanceLegendViewModel.destroy();
2399
- }
2400
-
2401
- if (cesium.defined(this.navigationDiv)) {
2402
- this.navigationDiv.parentNode.removeChild(this.navigationDiv);
2403
- }
2404
- delete this.navigationDiv;
2405
-
2406
- if (cesium.defined(this.distanceLegendDiv)) {
2407
- this.distanceLegendDiv.parentNode.removeChild(this.distanceLegendDiv);
2408
- }
2409
- delete this.distanceLegendDiv;
2410
-
2411
- if (cesium.defined(this.container)) {
2412
- this.container.parentNode.removeChild(this.container);
2413
- }
2414
- delete this.container;
2415
-
2416
- for (var i = 0; i < this._onDestroyListeners.length; i++) {
2417
- this._onDestroyListeners[i]();
2418
- }
2419
- };
2420
-
2421
- CesiumNavigation.prototype.addOnDestroyListener = function (callback) {
2422
- if (typeof callback === 'function') {
2423
- this._onDestroyListeners.push(callback);
2424
- }
2425
- };
2426
-
2427
- /**
2428
- * @param {Viewer|CesiumWidget} viewerCesiumWidget The Viewer or CesiumWidget instance
2429
- * @param options
2430
- */
2431
- function initialize(viewerCesiumWidget) {var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : { units: 'kilometers' };
2432
- if (!cesium.defined(viewerCesiumWidget)) {
2433
- throw new cesium.DeveloperError('CesiumWidget or Viewer is required.');
2434
- }
2435
-
2436
- // options = defaultValue(options, defaultValue.EMPTY_OBJECT);
2437
-
2438
- var cesiumWidget = cesium.defined(viewerCesiumWidget.cesiumWidget) ?
2439
- viewerCesiumWidget.cesiumWidget :
2440
- viewerCesiumWidget;
2441
-
2442
- var container = document.createElement('div');
2443
- container.className = 'cesium-widget-cesiumNavigationContainer';
2444
- cesiumWidget.container.appendChild(container);
2445
-
2446
- this.terria = viewerCesiumWidget;
2447
- this.terria.options = cesium.defined(options) ? options : {};
2448
- this.terria.afterWidgetChanged = new cesium.Event();
2449
- this.terria.beforeWidgetChanged = new cesium.Event();
2450
- this.container = container;
2451
-
2452
- // this.navigationDiv.setAttribute("id", "navigationDiv");
2453
-
2454
- // Register custom Knockout.js bindings.
2455
- // If you're not using the TerriaJS user interface, you can remove this.
2456
- registerKnockoutBindings();
2457
-
2458
- if (
2459
- !cesium.defined(this.terria.options.enableDistanceLegend) ||
2460
- this.terria.options.enableDistanceLegend)
2461
- {
2462
- this.distanceLegendDiv = document.createElement('div');
2463
- container.appendChild(this.distanceLegendDiv);
2464
- this.distanceLegendDiv.setAttribute('id', 'distanceLegendDiv');
2465
- this.distanceLegendViewModel = DistanceLegendViewModel.create(_extends({},
2466
- options, {
2467
- container: this.distanceLegendDiv,
2468
- terria: this.terria,
2469
- mapElement: container,
2470
- enableDistanceLegend: true }));
2471
-
2472
- }
2473
-
2474
- if (
2475
- (!cesium.defined(this.terria.options.enableZoomControls) ||
2476
- this.terria.options.enableZoomControls) && (
2477
- !cesium.defined(this.terria.options.enableCompass) ||
2478
- this.terria.options.enableCompass))
2479
- {
2480
- this.navigationDiv = document.createElement('div');
2481
- this.navigationDiv.setAttribute('id', 'navigationDiv');
2482
- container.appendChild(this.navigationDiv);
2483
- // Create the navigation controls.
2484
- this.navigationViewModel = NavigationViewModel.create({
2485
- container: this.navigationDiv,
2486
- terria: this.terria,
2487
- enableZoomControls: true,
2488
- enableCompass: true });
2489
-
2490
- } else if (
2491
- cesium.defined(this.terria.options.enableZoomControls) &&
2492
- !this.terria.options.enableZoomControls && (
2493
- !cesium.defined(this.terria.options.enableCompass) ||
2494
- this.terria.options.enableCompass))
2495
- {
2496
- this.navigationDiv = document.createElement('div');
2497
- this.navigationDiv.setAttribute('id', 'navigationDiv');
2498
- container.appendChild(this.navigationDiv);
2499
- // Create the navigation controls.
2500
- this.navigationViewModel = NavigationViewModel.create({
2501
- container: this.navigationDiv,
2502
- terria: this.terria,
2503
- enableZoomControls: false,
2504
- enableCompass: true });
2505
-
2506
- } else if (
2507
- (!cesium.defined(this.terria.options.enableZoomControls) ||
2508
- this.terria.options.enableZoomControls) &&
2509
- cesium.defined(this.terria.options.enableCompass) &&
2510
- !this.terria.options.enableCompass)
2511
- {
2512
- this.navigationDiv = document.createElement('div');
2513
- this.navigationDiv.setAttribute('id', 'navigationDiv');
2514
- container.appendChild(this.navigationDiv);
2515
- // Create the navigation controls.
2516
- this.navigationViewModel = NavigationViewModel.create({
2517
- container: this.navigationDiv,
2518
- terria: this.terria,
2519
- enableZoomControls: true,
2520
- enableCompass: false });
2521
-
2522
- } else if (
2523
- cesium.defined(this.terria.options.enableZoomControls) &&
2524
- !this.terria.options.enableZoomControls &&
2525
- cesium.defined(this.terria.options.enableCompass) &&
2526
- !this.terria.options.enableCompass)
2527
- ;
2528
- }
2529
-
2530
- /**
2531
- * Created by Larcius on 18.02.16.
2532
- */
2533
-
2534
- /**
2535
- * A mixin which adds the Compass/Navigation widget to the Viewer widget.
2536
- * Rather than being called directly, this function is normally passed as
2537
- * a parameter to {@link Viewer#extend}, as shown in the example below.
2538
- * @exports viewerCesiumNavigationMixin
2539
- *
2540
- * @param {Viewer} viewer The viewer instance.
2541
- * @param {{}} options The options.
2542
- *
2543
- * @exception {DeveloperError} viewer is required.
2544
- *
2545
- * @demo {@link http://localhost:8080/index.html|run local server with examples}
2546
- *
2547
- * @example
2548
- * const viewer = new Cesium.Viewer('cesiumContainer');
2549
- * viewer.extend(viewerCesiumNavigationMixin);
2550
- */
2551
- function viewerCesiumNavigationMixin(viewer, options) {
2552
- if (!cesium.defined(viewer)) {
2553
- throw new cesium.DeveloperError('viewer is required.');
2554
- }
2555
-
2556
- var cesiumNavigation = init(viewer, options);
2557
-
2558
- cesiumNavigation.addOnDestroyListener(
2559
- function (_viewer) {return function () {
2560
- var v = _viewer;
2561
- delete v.cesiumNavigation;
2562
- };}(viewer));
2563
-
2564
-
2565
- Object.defineProperties(viewer, {
2566
- cesiumNavigation: {
2567
- configurable: true,
2568
- get: function get() {return viewer.cesiumWidget.cesiumNavigation;} } });
2569
-
2570
-
2571
- }
2572
-
2573
- /**
2574
- *
2575
- * @param {CesiumWidget} cesiumWidget The cesium widget instance.
2576
- * @param {{}} options The options.
2577
- */
2578
- viewerCesiumNavigationMixin.mixinWidget = function () {return init.apply(undefined, arguments);};
2579
-
2580
- /**
2581
- * @param {Viewer|CesiumWidget} viewerCesiumWidget The Viewer or CesiumWidget instance
2582
- * @param {{}} options the options
2583
- */
2584
- var init = function init(viewerCesiumWidget, options) {
2585
- var cesiumNavigation = new CesiumNavigation(viewerCesiumWidget, options);
2586
-
2587
- var cesiumWidget = cesium.defined(viewerCesiumWidget.cesiumWidget) ?
2588
- viewerCesiumWidget.cesiumWidget :
2589
- viewerCesiumWidget;
2590
-
2591
- Object.defineProperties(cesiumWidget, {
2592
- cesiumNavigation: {
2593
- configurable: true,
2594
- get: function get() {return cesiumNavigation;} } });
2595
-
2596
-
2597
-
2598
- cesiumNavigation.addOnDestroyListener(
2599
- function (_cW) {
2600
- var _cesiumWidget = _cW;
2601
- return function () {
2602
- delete _cesiumWidget.cesiumNavigation;
2603
- };
2604
- }(cesiumWidget));
2605
-
2606
-
2607
- return cesiumNavigation;
2608
- };
2609
-
2610
- module.exports = viewerCesiumNavigationMixin;