@znemz/cesium-navigation 4.0.0 → 6.0.2

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