@openglobus/og 0.13.5 → 0.13.6

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@openglobus/og",
3
- "version": "0.13.5",
3
+ "version": "0.13.6",
4
4
  "description": "[OpenGlobus](http://www.openglobus.org/) is a javascript library designed to display interactive 3d maps and planets with map tiles, imagery and vector data, markers and 3d objects. It uses the WebGL technology, open source and completely free.",
5
5
  "directories": {
6
6
  "example": "./sandbox"
package/src/og/Events.js CHANGED
@@ -1,188 +1,188 @@
1
- /**
2
- * @module og/Events
3
- */
4
-
5
- "use strict";
6
-
7
- import { stamp, binaryInsert } from "./utils/shared.js";
8
-
9
- /**
10
- * Base events class to handle custom events.
11
- * @class
12
- */
13
- class Events {
14
- /**
15
- *
16
- * @param {Array.<string>} [eventNames] - Event names that could be dispatched.
17
- * @param {*} [sender]
18
- */
19
- constructor(eventNames, sender) {
20
- /**
21
- * Registered event names.
22
- * @protected
23
- * @type {Array.<string>}
24
- */
25
- this._eventNames = [];
26
-
27
- eventNames && this.registerNames(eventNames);
28
-
29
- this._sender = sender || this;
30
-
31
- /**
32
- * Stop propagation flag
33
- * @protected
34
- * @type {boolean}
35
- */
36
- this._stopPropagation = false;
37
-
38
- this._stampCache = {};
39
-
40
- this.__id = Events._staticCounter++;
41
- }
42
-
43
- static get _staticCounter() {
44
- if (!this.__counter__ && this.__counter__ !== 0) {
45
- this.__counter__ = 0;
46
- }
47
- return this.__counter__;
48
- }
49
-
50
- static set _staticCounter(n) {
51
- this.__counter__ = n;
52
- }
53
-
54
- bindSender(sender) {
55
- this._sender = sender || this;
56
- }
57
-
58
- /**
59
- * Function that creates event object properties that would be dispatched.
60
- * @public
61
- * @param {Array.<string>} eventNames - Specified event names list.
62
- */
63
- registerNames(eventNames) {
64
- for (var i = 0; i < eventNames.length; i++) {
65
- this[eventNames[i]] = { active: true, handlers: [] };
66
- this._eventNames.push(eventNames[i]);
67
- }
68
- }
69
-
70
- _getStamp(name, id, ogid) {
71
- return `${name}_${id}_${ogid}`;
72
- }
73
-
74
- /**
75
- * Returns true if event callback has stamped.
76
- * @protected
77
- * @param {Object} name - Event identifier.
78
- * @param {Object} obj - Event callback.
79
- * @return {boolean} -
80
- */
81
- _stamp(name, obj) {
82
- var ogid = stamp(obj);
83
-
84
- var st = this._getStamp(name, this.__id, ogid);
85
-
86
- if (!this._stampCache[st]) {
87
- this._stampCache[st] = ogid;
88
- return true;
89
- }
90
-
91
- return false;
92
- }
93
-
94
- /**
95
- * Attach listener.
96
- * @public
97
- * @param {string} name - Event name to listen.
98
- * @param {eventCallback} callback - Event callback function.
99
- * @param {Object} sender - Event callback function owner.
100
- */
101
- on(name, callback, sender, priority = 0) {
102
- if (this._stamp(name, callback)) {
103
- if (this[name]) {
104
- let c = callback.bind(sender || this._sender);
105
- c._openglobus_id = callback._openglobus_id;
106
- c._openglobus_priority = priority;
107
- binaryInsert(this[name].handlers, c, (a, b) => {
108
- return b._openglobus_priority - a._openglobus_priority;
109
- });
110
- }
111
- }
112
- }
113
-
114
- /**
115
- * Stop listening event name with specified callback function.
116
- * @public
117
- * @param {string} name - Event name.
118
- * @param {eventCallback} callback - Attached event callback.
119
- */
120
- off(name, callback) {
121
- if (callback) {
122
- var st = this._getStamp(name, this.__id, callback._openglobus_id);
123
- if (callback._openglobus_id && this._stampCache[st]) {
124
- var h = this[name].handlers;
125
- var i = h.length;
126
- var indexToRemove = -1;
127
- while (i--) {
128
- var hi = h[i];
129
- if (hi._openglobus_id === callback._openglobus_id) {
130
- indexToRemove = i;
131
- break;
132
- }
133
- }
134
-
135
- if (indexToRemove !== -1) {
136
- h.splice(indexToRemove, 1);
137
- this._stampCache[st] = undefined;
138
- delete this._stampCache[st];
139
- }
140
- }
141
- }
142
- }
143
-
144
- /**
145
- * Dispatch event.
146
- * @public
147
- * @param {Object} event - Event instance property that created by event name.
148
- * @param {Object} [obj] - Event object.
149
- */
150
- dispatch(event, ...args) {
151
- let result = true;
152
- if (event && event.active && !this._stopPropagation) {
153
- let h = event.handlers,
154
- i = h.length;
155
- while (i--) {
156
- if (h[i](...args) === false) {
157
- result = false;
158
- }
159
- }
160
- }
161
- this._stopPropagation = false;
162
- return result;
163
- }
164
-
165
- /**
166
- * Brakes events propagation.
167
- * @public
168
- */
169
- stopPropagation() {
170
- this._stopPropagation = true;
171
- }
172
-
173
- /**
174
- * Removes all events.
175
- * @public
176
- */
177
- clear() {
178
- for (var i = 0; i < this._eventNames.length; i++) {
179
- var e = this[this._eventNames[i]];
180
- e.handlers.length = 0;
181
- e.handlers = [];
182
- }
183
- this._eventNames.length = 0;
184
- this._eventNames = [];
185
- }
186
- }
187
-
188
- export { Events };
1
+ /**
2
+ * @module og/Events
3
+ */
4
+
5
+ "use strict";
6
+
7
+ import { stamp, binaryInsert } from "./utils/shared.js";
8
+
9
+ /**
10
+ * Base events class to handle custom events.
11
+ * @class
12
+ */
13
+ class Events {
14
+ /**
15
+ *
16
+ * @param {Array.<string>} [eventNames] - Event names that could be dispatched.
17
+ * @param {*} [sender]
18
+ */
19
+ constructor(eventNames, sender) {
20
+ /**
21
+ * Registered event names.
22
+ * @protected
23
+ * @type {Array.<string>}
24
+ */
25
+ this._eventNames = [];
26
+
27
+ eventNames && this.registerNames(eventNames);
28
+
29
+ this._sender = sender || this;
30
+
31
+ /**
32
+ * Stop propagation flag
33
+ * @protected
34
+ * @type {boolean}
35
+ */
36
+ this._stopPropagation = false;
37
+
38
+ this._stampCache = {};
39
+
40
+ this.__id = Events._staticCounter++;
41
+ }
42
+
43
+ static get _staticCounter() {
44
+ if (!this.__counter__ && this.__counter__ !== 0) {
45
+ this.__counter__ = 0;
46
+ }
47
+ return this.__counter__;
48
+ }
49
+
50
+ static set _staticCounter(n) {
51
+ this.__counter__ = n;
52
+ }
53
+
54
+ bindSender(sender) {
55
+ this._sender = sender || this;
56
+ }
57
+
58
+ /**
59
+ * Function that creates event object properties that would be dispatched.
60
+ * @public
61
+ * @param {Array.<string>} eventNames - Specified event names list.
62
+ */
63
+ registerNames(eventNames) {
64
+ for (var i = 0; i < eventNames.length; i++) {
65
+ this[eventNames[i]] = { active: true, handlers: [] };
66
+ this._eventNames.push(eventNames[i]);
67
+ }
68
+ }
69
+
70
+ _getStamp(name, id, ogid) {
71
+ return `${name}_${id}_${ogid}`;
72
+ }
73
+
74
+ /**
75
+ * Returns true if event callback has stamped.
76
+ * @protected
77
+ * @param {Object} name - Event identifier.
78
+ * @param {Object} obj - Event callback.
79
+ * @return {boolean} -
80
+ */
81
+ _stamp(name, obj) {
82
+ var ogid = stamp(obj);
83
+
84
+ var st = this._getStamp(name, this.__id, ogid);
85
+
86
+ if (!this._stampCache[st]) {
87
+ this._stampCache[st] = ogid;
88
+ return true;
89
+ }
90
+
91
+ return false;
92
+ }
93
+
94
+ /**
95
+ * Attach listener.
96
+ * @public
97
+ * @param {string} name - Event name to listen.
98
+ * @param {eventCallback} callback - Event callback function.
99
+ * @param {Object} sender - Event callback function owner.
100
+ */
101
+ on(name, callback, sender, priority = 0) {
102
+ if (this._stamp(name, callback)) {
103
+ if (this[name]) {
104
+ let c = callback.bind(sender || this._sender);
105
+ c._openglobus_id = callback._openglobus_id;
106
+ c._openglobus_priority = priority;
107
+ binaryInsert(this[name].handlers, c, (a, b) => {
108
+ return b._openglobus_priority - a._openglobus_priority;
109
+ });
110
+ }
111
+ }
112
+ }
113
+
114
+ /**
115
+ * Stop listening event name with specified callback function.
116
+ * @public
117
+ * @param {string} name - Event name.
118
+ * @param {eventCallback} callback - Attached event callback.
119
+ */
120
+ off(name, callback) {
121
+ if (callback) {
122
+ var st = this._getStamp(name, this.__id, callback._openglobus_id);
123
+ if (callback._openglobus_id && this._stampCache[st]) {
124
+ var h = this[name].handlers;
125
+ var i = h.length;
126
+ var indexToRemove = -1;
127
+ while (i--) {
128
+ var hi = h[i];
129
+ if (hi._openglobus_id === callback._openglobus_id) {
130
+ indexToRemove = i;
131
+ break;
132
+ }
133
+ }
134
+
135
+ if (indexToRemove !== -1) {
136
+ h.splice(indexToRemove, 1);
137
+ this._stampCache[st] = undefined;
138
+ delete this._stampCache[st];
139
+ }
140
+ }
141
+ }
142
+ }
143
+
144
+ /**
145
+ * Dispatch event.
146
+ * @public
147
+ * @param {Object} event - Event instance property that created by event name.
148
+ * @param {Object} [obj] - Event object.
149
+ */
150
+ dispatch(event, ...args) {
151
+ let result = true;
152
+ if (event && event.active && !this._stopPropagation) {
153
+ let h = event.handlers.slice(0),
154
+ i = h.length;
155
+ while (i--) {
156
+ if (h[i](...args) === false) {
157
+ result = false;
158
+ }
159
+ }
160
+ }
161
+ this._stopPropagation = false;
162
+ return result;
163
+ }
164
+
165
+ /**
166
+ * Brakes events propagation.
167
+ * @public
168
+ */
169
+ stopPropagation() {
170
+ this._stopPropagation = true;
171
+ }
172
+
173
+ /**
174
+ * Removes all events.
175
+ * @public
176
+ */
177
+ clear() {
178
+ for (var i = 0; i < this._eventNames.length; i++) {
179
+ var e = this[this._eventNames[i]];
180
+ e.handlers.length = 0;
181
+ e.handlers = [];
182
+ }
183
+ this._eventNames.length = 0;
184
+ this._eventNames = [];
185
+ }
186
+ }
187
+
188
+ export { Events };
package/src/og/Globe.js CHANGED
@@ -8,6 +8,7 @@ import { CompassButton } from "./control/CompassButton.js";
8
8
  import { EarthCoordinates } from "./control/EarthCoordinates.js";
9
9
  import { EarthNavigation } from "./control/EarthNavigation.js";
10
10
  import { MouseNavigation } from "./control/MouseNavigation.js";
11
+ import { KeyboardNavigation } from "./control/KeyboardNavigation.js";
11
12
  import { ScaleControl } from "./control/ScaleControl.js";
12
13
  import { Sun } from "./control/Sun.js";
13
14
  import { TouchNavigation } from "./control/TouchNavigation.js";
@@ -24,16 +24,22 @@ class KeyboardNavigation extends Control {
24
24
  }
25
25
 
26
26
  oninit() {
27
+ this.renderer.events.on("keypress", input.KEY_PGUP, this.onCameraMoveForward, this);
28
+ this.renderer.events.on("keypress", input.KEY_PGDN, this.onCameraMoveBackward, this);
29
+ this.renderer.events.on("keypress", input.KEY_PLUS, this.onCameraMoveForward, this);
30
+ this.renderer.events.on("keypress", input.KEY_EQUALS, this.onCameraMoveForward, this);
31
+ this.renderer.events.on("keypress", input.KEY_MINUS, this.onCameraMoveBackward, this);
27
32
  this.renderer.events.on("keypress", input.KEY_W, this.onCameraMoveForward, this);
28
33
  this.renderer.events.on("keypress", input.KEY_S, this.onCameraMoveBackward, this);
29
34
  this.renderer.events.on("keypress", input.KEY_A, this.onCameraStrifeLeft, this);
30
35
  this.renderer.events.on("keypress", input.KEY_D, this.onCameraStrifeRight, this);
31
36
  this.renderer.events.on("keypress", input.KEY_UP, this.onCameraLookUp, this);
32
37
  this.renderer.events.on("keypress", input.KEY_DOWN, this.onCameraLookDown, this);
33
- this.renderer.events.on("keypress", input.KEY_LEFT, this.onCameraTurnLeft, this);
34
- this.renderer.events.on("keypress", input.KEY_RIGHT, this.onCameraTurnRight, this);
38
+ this.renderer.events.on("keypress", input.KEY_LEFT, this.onCameraLookLeft, this);
39
+ this.renderer.events.on("keypress", input.KEY_RIGHT, this.onCameraLookRight, this);
35
40
  this.renderer.events.on("keypress", input.KEY_Q, this.onCameraRollLeft, this);
36
41
  this.renderer.events.on("keypress", input.KEY_E, this.onCameraRollRight, this);
42
+ this.renderer.events.on("keypress", input.KEY_N, this.onCameraRollNorth, this);
37
43
  }
38
44
 
39
45
  onCameraMoveForward(event) {
@@ -84,6 +90,26 @@ class KeyboardNavigation extends Control {
84
90
  cam.update();
85
91
  }
86
92
 
93
+ onCameraLookLeft(event) {
94
+ var cam = this.renderer.activeCamera;
95
+ if (this.renderer.events.isKeyPressed(input.KEY_SHIFT)) {
96
+ cam.roll(15 / this.renderer.handler.deltaTime);
97
+ } else {
98
+ cam.rotateHorizontal((cam._lonLat.height / 3000000) * math.RADIANS, Vec3.ZERO);
99
+ }
100
+ cam.update();
101
+ }
102
+
103
+ onCameraLookRight(event) {
104
+ var cam = this.renderer.activeCamera;
105
+ if (this.renderer.events.isKeyPressed(input.KEY_SHIFT)) {
106
+ cam.roll(-15 / this.renderer.handler.deltaTime);
107
+ } else {
108
+ cam.rotateHorizontal((-cam._lonLat.height / 3000000) * math.RADIANS, Vec3.ZERO);
109
+ }
110
+ cam.update();
111
+ }
112
+
87
113
  onCameraTurnLeft(event) {
88
114
  var cam = this.renderer.activeCamera;
89
115
  if (this.renderer.events.isKeyPressed(input.KEY_SHIFT)) {
@@ -104,6 +130,26 @@ class KeyboardNavigation extends Control {
104
130
  cam.update();
105
131
  }
106
132
 
133
+ // from CompassButton._onClick()
134
+ onCameraRollNorth(event) {
135
+ let c = this.planet.getCartesianFromPixelTerrain(this.renderer.handler.getCenter());
136
+ if (c) {
137
+ this.planet.flyCartesian(
138
+ c.normal().scaleTo(c.length() + c.distance(this.planet.camera.eye)),
139
+ null,
140
+ null,
141
+ 0,
142
+ null,
143
+ null,
144
+ () => {
145
+ this.planet.camera.look(c);
146
+ }
147
+ );
148
+ } else {
149
+ this.planet.flyCartesian(this.planet.camera.eye);
150
+ }
151
+ }
152
+
107
153
  onCameraRollLeft(event) {
108
154
  this.renderer.activeCamera.roll(-15 / this.renderer.handler.deltaTime);
109
155
  this.renderer.activeCamera.update();
@@ -83,13 +83,13 @@ class TouchNavigation extends Control {
83
83
  t0.y = e.sys.touches.item(0).clientY - e.sys.offsetTop;
84
84
  t0.prev_x = e.sys.touches.item(0).clientX - e.sys.offsetLeft;
85
85
  t0.prev_y = e.sys.touches.item(0).clientY - e.sys.offsetTop;
86
- t0.grabbedPoint = this.planet.getCartesianFromPixelTerrain(t0, true);
86
+ t0.grabbedPoint = this.planet.getCartesianFromPixelTerrain(e, true);
87
87
 
88
88
  t1.x = e.sys.touches.item(1).clientX - e.sys.offsetLeft;
89
89
  t1.y = e.sys.touches.item(1).clientY - e.sys.offsetTop;
90
90
  t1.prev_x = e.sys.touches.item(1).clientX - e.sys.offsetLeft;
91
91
  t1.prev_y = e.sys.touches.item(1).clientY - e.sys.offsetTop;
92
- t1.grabbedPoint = this.planet.getCartesianFromPixelTerrain(t1, true);
92
+ t1.grabbedPoint = this.planet.getCartesianFromPixelTerrain(e, true);
93
93
 
94
94
  // this.planet._viewChanged = true;
95
95
  this.pointOnEarth = this.planet.getCartesianFromPixelTerrain(
@@ -119,7 +119,7 @@ class TouchNavigation extends Control {
119
119
  t.prev_x = e.sys.touches.item(0).clientX - e.sys.offsetLeft;
120
120
  t.prev_y = e.sys.touches.item(0).clientY - e.sys.offsetTop;
121
121
 
122
- t.grabbedPoint = this.planet.getCartesianFromPixelTerrain(t, true);
122
+ t.grabbedPoint = this.planet.getCartesianFromPixelTerrain(e, true);
123
123
  this._eye0.copy(this.renderer.activeCamera.eye);
124
124
 
125
125
  if (t.grabbedPoint) {
@@ -142,7 +142,8 @@ class TouchNavigation extends Control {
142
142
 
143
143
  this.planet.stopFlying();
144
144
  this.stopRotation();
145
- var p = this.planet.getCartesianFromPixelTerrain(this.touches[0], true);
145
+
146
+ var p = this.planet.getCartesianFromPixelTerrain(e);
146
147
  if (p) {
147
148
  var g = this.planet.ellipsoid.cartesianToLonLat(p);
148
149
  this.planet.flyLonLat(
@@ -199,11 +200,6 @@ class TouchNavigation extends Control {
199
200
  // distance < 0 --> zoomIn; distance > 0 --> zoomOut
200
201
  var t0t1Distance = Math.abs(t0.prev_x - t1.prev_x) + Math.abs(t0.prev_y - t1.prev_y) - (Math.abs(t0.x - t1.x) + Math.abs(t0.y - t1.y))
201
202
  var _move = 0
202
- var _targetPoint = this.renderer.getCenter()
203
- var d =
204
- cam.eye.distance(
205
- this.planet.getCartesianFromPixelTerrain(_targetPoint, true)
206
- ) * 0.075;
207
203
  if (t0t1Distance < 0) {
208
204
  _move = 1
209
205
  }
@@ -211,9 +207,13 @@ class TouchNavigation extends Control {
211
207
  _move = -1
212
208
  }
213
209
  if (_move !== 0) {
214
- cam.eye.addA(cam.getForward().scale(_move * d));
215
- cam.checkTerrainCollision();
216
- cam.update();
210
+ let pos = this.planet.getCartesianFromPixelTerrain(e);
211
+ if (pos) {
212
+ let d = cam.eye.distance(pos) * 0.075;
213
+ cam.eye.addA(cam.getForward().scale(_move * d));
214
+ cam.checkTerrainCollision();
215
+ cam.update();
216
+ }
217
217
  }
218
218
 
219
219
  if (
@@ -246,7 +246,7 @@ class TouchNavigation extends Control {
246
246
 
247
247
  this.planet.stopFlying();
248
248
 
249
- var direction = cam.unproject(t.x, t.y);
249
+ var direction = e.direction
250
250
  var targetPoint = new Ray(cam.eye, direction).hitSphere(t.grabbedSpheroid);
251
251
 
252
252
  if (targetPoint) {
@@ -114,7 +114,7 @@ class ZoomControl extends Control {
114
114
  var cam = this.renderer.activeCamera;
115
115
 
116
116
  if (this._move !== 0) {
117
- let pos = this.planet.getCartesianFromPixelTerrain(this._targetPoint);
117
+ let pos = this.planet.getCartesianFromPixelTerrain(e);
118
118
  if (pos) {
119
119
  let d = cam.eye.distance(pos) * 0.035;
120
120
  cam.eye.addA(cam.getForward().scale(this._move * d));
@@ -536,7 +536,7 @@ class Ellipsoid {
536
536
 
537
537
  let eps = Math.abs(qw2 - product);
538
538
 
539
- if (eps > math.EPSILON10 && qw2 < product) {
539
+ if (eps > math.EPSILON15 && qw2 < product) {
540
540
  // Imaginary roots (0 intersections).
541
541
  return null;
542
542
  } else if (qw2 > product) {
@@ -385,14 +385,14 @@ class LabelHandler extends BillboardHandler {
385
385
  if (isRTL) {
386
386
  _rtl_ = RTL;
387
387
  }
388
- let n = fa.get(text[c].charCodeAt());
388
+
389
389
  let offset = 0.0;
390
390
  let kern = fa.kernings;
391
391
 
392
392
  for (c = 0; c < len; c++) {
393
393
  let j = i + c * 24;
394
394
  let char = text[c];
395
- n = fa.get(char.charCodeAt()) || fa.get(" ".charCodeAt());
395
+ let n = fa.get(char.charCodeAt()) || fa.get(" ".charCodeAt());
396
396
  let tc = n.texCoords;
397
397
 
398
398
  let m = n.metrics;
@@ -9,11 +9,14 @@ export const input = {
9
9
  KEY_ALT: 18,
10
10
  KEY_SHIFT: 16,
11
11
  KEY_SPACE: 32,
12
+ KEY_PGUP: 33,
13
+ KEY_PGDN: 34,
12
14
  KEY_LEFT: 37,
13
15
  KEY_UP: 38,
14
16
  KEY_RIGHT: 39,
15
17
  KEY_DOWN: 40,
16
18
  KEY_PRINTSCREEN: 44,
19
+ KEY_EQUALS: 61,
17
20
  KEY_A: 65,
18
21
  KEY_C: 67,
19
22
  KEY_D: 68,
@@ -23,6 +26,7 @@ export const input = {
23
26
  KEY_I: 73,
24
27
  KEY_K: 75,
25
28
  KEY_L: 76,
29
+ KEY_N: 78,
26
30
  KEY_O: 79,
27
31
  KEY_P: 80,
28
32
  KEY_Q: 81,
@@ -32,9 +36,11 @@ export const input = {
32
36
  KEY_W: 87,
33
37
  KEY_X: 88,
34
38
  KEY_Z: 90,
39
+ KEY_PLUS: 107,
35
40
  KEY_F1: 112,
41
+ KEY_MINUS: 173,
36
42
  KEY_APOSTROPHE: 192,
37
43
  MB_LEFT: 0,
38
44
  MB_RIGHT: 2,
39
45
  MB_MIDDLE: 1
40
- };
46
+ };