globe.gl 2.25.3 → 2.26.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/README.md CHANGED
@@ -33,6 +33,7 @@ And check out the [React bindings](https://github.com/vasturiano/react-globe.gl)
33
33
  * [Hollow Globe](https://vasturiano.github.io/globe.gl/example/hollow-globe/) ([source](https://github.com/vasturiano/globe.gl/blob/master/example/hollow-globe/index.html))
34
34
  * [Path Lines](https://vasturiano.github.io/globe.gl/example/random-paths/) ([source](https://github.com/vasturiano/globe.gl/blob/master/example/random-paths/index.html))
35
35
  * [Map Labels](https://vasturiano.github.io/globe.gl/example/world-cities/) ([source](https://github.com/vasturiano/globe.gl/blob/master/example/world-cities/index.html))
36
+ * [HTML Markers](https://vasturiano.github.io/globe.gl/example/html-markers/) ([source](https://github.com/vasturiano/globe.gl/blob/master/example/html-markers/index.html))
36
37
  * [Hexed Country Polygons](https://vasturiano.github.io/globe.gl/example/hexed-polygons/) ([source](https://github.com/vasturiano/globe.gl/blob/master/example/hexed-polygons/index.html))
37
38
  * [Tiles](https://vasturiano.github.io/globe.gl/example/tiles/) ([source](https://github.com/vasturiano/globe.gl/blob/master/example/tiles/index.html))
38
39
  * [Ripple Rings](https://vasturiano.github.io/globe.gl/example/random-rings/) ([source](https://github.com/vasturiano/globe.gl/blob/master/example/random-rings/index.html))
@@ -73,6 +74,24 @@ myGlobe(myDOMElement)
73
74
 
74
75
  ## API reference
75
76
 
77
+ * [Initialisation](#initialisation)
78
+ * [Container Layout](#container-layout)
79
+ * [Globe Layer](#globe-layer)
80
+ * [Points Layer](#points-layer)
81
+ * [Arcs Layer](#arcs-layer)
82
+ * [Polygons Layer](#polygons-layer)
83
+ * [Paths Layer](#paths-layer)
84
+ * [Hex Bin Layer](#hex-bin-layer)
85
+ * [Hexed Polygons Layer](#hexed-polygons-layer)
86
+ * [Tiles Layer](#tiles-layer)
87
+ * [Rings Layer](#rings-layer)
88
+ * [Labels Layer](#labels-layer)
89
+ * [HTML Elements Layer](#html-elements-layer)
90
+ * [3D Objects Layer](#3d-objects-layer)
91
+ * [Custom Layer](#custom-layer)
92
+ * [Render Control](#render-control)
93
+ * [Utility](#utility)
94
+
76
95
  ### Initialisation
77
96
 
78
97
  ```js
@@ -85,7 +104,7 @@ Globe({ configOptions })(<domElement>)
85
104
  | <b>waitForGlobeReady</b>: <i>boolean</i> | Whether to wait until the globe wrapping or background image has been fully loaded before rendering the globe or any of the data layers. | `true` |
86
105
  | <b>animateIn</b>: <i>boolean</i> | Whether to animate the globe initialization, by scaling and rotating the globe into its inital position. | `true` |
87
106
 
88
- ### Container layout
107
+ ### Container Layout
89
108
 
90
109
  | Method | Description | Default |
91
110
  | --- | --- | :--: |
@@ -324,7 +343,22 @@ Globe({ configOptions })(<domElement>)
324
343
  | <b>onLabelRightClick</b>(<i>fn</i>) | Callback function for label right-clicks. The label object, the event object and the clicked coordinates are included as arguments: `onLabelRightClick(label, event, { lat, lng, altitude })`. | - |
325
344
  | <b>onLabelHover</b>(<i>fn</i>) | Callback function for label mouse over events. The label object (or `null` if there's no label under the mouse line of sight) is included as the first argument, and the previous label object (or `null`) as second argument: `onLabelHover(label, prevlabel)`. | - |
326
345
 
327
- ### Objects Layer
346
+ ### HTML Elements Layer
347
+
348
+ <p align="center">
349
+ <a href="//vasturiano.github.io/globe.gl/example/html-markers/"><img width="70%" src="https://vasturiano.github.io/globe.gl/example/html-markers/preview.png"></a>
350
+ </p>
351
+
352
+ | Method | Description | Default |
353
+ | --- | --- | :--: |
354
+ | <b>htmlElementsData</b>([<i>array</i>]) | Getter/setter for the list of objects to represent in the HTML elements map layer. Each HTML element is rendered using [ThreeJS CSS2DRenderer](https://threejs.org/docs/#examples/en/renderers/CSS2DRenderer). | `[]` |
355
+ | <b>htmlLat</b>([<i>num</i>, <i>str</i> or <i>fn</i>]) | HTML element accessor function, attribute or a numeric constant for the latitude coordinate of the element's central position. | `lat` |
356
+ | <b>htmlLng</b>([<i>num</i>, <i>str</i> or <i>fn</i>]) | HTML element accessor function, attribute or a numeric constant for the longitude coordinate of the element's central position. | `lng` |
357
+ | <b>htmlAltitude</b>([<i>num</i>, <i>str</i> or <i>fn</i>]) | HTML element accessor function, attribute or a numeric constant for the altitude coordinate of the element's position, in terms of globe radius units. | 0 |
358
+ | <b>htmlElement</b>([<i>str</i> or <i>fn</i>]) | Accessor function or attribute to retrieve the DOM element to use. Should return an instance of [HTMLElement](https://developer.mozilla.org/en-US/docs/Web/API/HTMLElement). | `null` |
359
+ | <b>htmlTransitionDuration</b>([<i>num</i>]) | Getter/setter for duration (ms) of the transition to animate HTML elements position changes. A value of `0` will move the elements immediately to their final position. | 1000 |
360
+
361
+ ### 3D Objects Layer
328
362
 
329
363
  <p align="center">
330
364
  <a href="//vasturiano.github.io/globe.gl/example/satellites/"><img width="70%" src="https://vasturiano.github.io/globe.gl/example/satellites/preview.png"></a>
@@ -358,7 +392,7 @@ Globe({ configOptions })(<domElement>)
358
392
  | <b>onCustomLayerRightClick</b>(<i>fn</i>) | Callback function for custom object right-clicks. The custom object, the event object and the clicked coordinates are included as arguments: `onCustomLayerRightClick(obj, event, { lat, lng, altitude })`. | - |
359
393
  | <b>onCustomLayerHover</b>(<i>fn</i>) | Callback function for custom object mouse over events. The custom object (or `null` if there's no object under the mouse line of sight) is included as the first argument, and the previous custom object (or `null`) as second argument: `onCustomLayerHover(obj, prevObj)`. | - |
360
394
 
361
- ### Render control
395
+ ### Render Control
362
396
 
363
397
  | Method | Description | Default |
364
398
  | --- | --- | :--: |
@@ -1,6 +1,7 @@
1
1
  'use strict';
2
2
 
3
- var three$1 = require('three');
3
+ var three = require('three');
4
+ var CSS2DRenderer_js = require('three/examples/jsm/renderers/CSS2DRenderer.js');
4
5
  var ThreeGlobe = require('three-globe');
5
6
  var ThreeRenderObjects = require('three-render-objects');
6
7
  var accessorFn = require('accessor-fn');
@@ -189,16 +190,19 @@ function linkKapsule (kapsulePropName, kapsuleType) {
189
190
  }
190
191
 
191
192
  var _excluded = ["rendererConfig", "waitForGlobeReady"];
192
- var three = window.THREE ? window.THREE // Prefer consumption from global THREE, if exists
193
+
194
+ var THREE = _objectSpread2(_objectSpread2({}, window.THREE ? window.THREE // Prefer consumption from global THREE, if exists
193
195
  : {
194
- AmbientLight: three$1.AmbientLight,
195
- DirectionalLight: three$1.DirectionalLight,
196
- Vector2: three$1.Vector2
197
- };
196
+ AmbientLight: three.AmbientLight,
197
+ DirectionalLight: three.DirectionalLight,
198
+ Vector2: three.Vector2
199
+ }), {}, {
200
+ CSS2DRenderer: CSS2DRenderer_js.CSS2DRenderer
201
+ });
198
202
  // Expose config from ThreeGlobe
199
203
 
200
204
  var bindGlobe = linkKapsule('globe', ThreeGlobe__default["default"]);
201
- var linkedGlobeProps = Object.assign.apply(Object, _toConsumableArray(['globeImageUrl', 'bumpImageUrl', 'showGlobe', 'showGraticules', 'showAtmosphere', 'atmosphereColor', 'atmosphereAltitude', 'globeMaterial', 'onGlobeReady', 'pointsData', 'pointLat', 'pointLng', 'pointColor', 'pointAltitude', 'pointRadius', 'pointResolution', 'pointsMerge', 'pointsTransitionDuration', 'arcsData', 'arcStartLat', 'arcStartLng', 'arcEndLat', 'arcEndLng', 'arcColor', 'arcAltitude', 'arcAltitudeAutoScale', 'arcStroke', 'arcCurveResolution', 'arcCircularResolution', 'arcDashLength', 'arcDashGap', 'arcDashInitialGap', 'arcDashAnimateTime', 'arcsTransitionDuration', 'polygonsData', 'polygonGeoJsonGeometry', 'polygonCapColor', 'polygonCapMaterial', 'polygonSideColor', 'polygonSideMaterial', 'polygonStrokeColor', 'polygonAltitude', 'polygonCapCurvatureResolution', 'polygonsTransitionDuration', 'pathsData', 'pathPoints', 'pathPointLat', 'pathPointLng', 'pathPointAlt', 'pathResolution', 'pathColor', 'pathStroke', 'pathDashLength', 'pathDashGap', 'pathDashInitialGap', 'pathDashAnimateTime', 'pathTransitionDuration', 'hexBinPointsData', 'hexBinPointLat', 'hexBinPointLng', 'hexBinPointWeight', 'hexBinResolution', 'hexMargin', 'hexTopCurvatureResolution', 'hexTopColor', 'hexSideColor', 'hexAltitude', 'hexBinMerge', 'hexTransitionDuration', 'hexPolygonsData', 'hexPolygonGeoJsonGeometry', 'hexPolygonColor', 'hexPolygonAltitude', 'hexPolygonResolution', 'hexPolygonMargin', 'hexPolygonCurvatureResolution', 'hexPolygonsTransitionDuration', 'tilesData', 'tileLat', 'tileLng', 'tileAltitude', 'tileWidth', 'tileHeight', 'tileUseGlobeProjection', 'tileMaterial', 'tileCurvatureResolution', 'tilesTransitionDuration', 'ringsData', 'ringLat', 'ringLng', 'ringAltitude', 'ringColor', 'ringResolution', 'ringMaxRadius', 'ringPropagationSpeed', 'ringRepeatPeriod', 'labelsData', 'labelLat', 'labelLng', 'labelAltitude', 'labelRotation', 'labelText', 'labelSize', 'labelTypeFace', 'labelColor', 'labelResolution', 'labelIncludeDot', 'labelDotRadius', 'labelDotOrientation', 'labelsTransitionDuration', 'objectsData', 'objectLat', 'objectLng', 'objectAltitude', 'objectThreeObject', 'customLayerData', 'customThreeObject', 'customThreeObjectUpdate'].map(function (p) {
205
+ var linkedGlobeProps = Object.assign.apply(Object, _toConsumableArray(['globeImageUrl', 'bumpImageUrl', 'showGlobe', 'showGraticules', 'showAtmosphere', 'atmosphereColor', 'atmosphereAltitude', 'globeMaterial', 'onGlobeReady', 'pointsData', 'pointLat', 'pointLng', 'pointColor', 'pointAltitude', 'pointRadius', 'pointResolution', 'pointsMerge', 'pointsTransitionDuration', 'arcsData', 'arcStartLat', 'arcStartLng', 'arcEndLat', 'arcEndLng', 'arcColor', 'arcAltitude', 'arcAltitudeAutoScale', 'arcStroke', 'arcCurveResolution', 'arcCircularResolution', 'arcDashLength', 'arcDashGap', 'arcDashInitialGap', 'arcDashAnimateTime', 'arcsTransitionDuration', 'polygonsData', 'polygonGeoJsonGeometry', 'polygonCapColor', 'polygonCapMaterial', 'polygonSideColor', 'polygonSideMaterial', 'polygonStrokeColor', 'polygonAltitude', 'polygonCapCurvatureResolution', 'polygonsTransitionDuration', 'pathsData', 'pathPoints', 'pathPointLat', 'pathPointLng', 'pathPointAlt', 'pathResolution', 'pathColor', 'pathStroke', 'pathDashLength', 'pathDashGap', 'pathDashInitialGap', 'pathDashAnimateTime', 'pathTransitionDuration', 'hexBinPointsData', 'hexBinPointLat', 'hexBinPointLng', 'hexBinPointWeight', 'hexBinResolution', 'hexMargin', 'hexTopCurvatureResolution', 'hexTopColor', 'hexSideColor', 'hexAltitude', 'hexBinMerge', 'hexTransitionDuration', 'hexPolygonsData', 'hexPolygonGeoJsonGeometry', 'hexPolygonColor', 'hexPolygonAltitude', 'hexPolygonResolution', 'hexPolygonMargin', 'hexPolygonCurvatureResolution', 'hexPolygonsTransitionDuration', 'tilesData', 'tileLat', 'tileLng', 'tileAltitude', 'tileWidth', 'tileHeight', 'tileUseGlobeProjection', 'tileMaterial', 'tileCurvatureResolution', 'tilesTransitionDuration', 'ringsData', 'ringLat', 'ringLng', 'ringAltitude', 'ringColor', 'ringResolution', 'ringMaxRadius', 'ringPropagationSpeed', 'ringRepeatPeriod', 'labelsData', 'labelLat', 'labelLng', 'labelAltitude', 'labelRotation', 'labelText', 'labelSize', 'labelTypeFace', 'labelColor', 'labelResolution', 'labelIncludeDot', 'labelDotRadius', 'labelDotOrientation', 'labelsTransitionDuration', 'htmlElementsData', 'htmlLat', 'htmlLng', 'htmlAltitude', 'htmlElement', 'htmlTransitionDuration', 'objectsData', 'objectLat', 'objectLng', 'objectAltitude', 'objectThreeObject', 'customLayerData', 'customThreeObject', 'customThreeObjectUpdate'].map(function (p) {
202
206
  return _defineProperty({}, p, bindGlobe.linkProp(p));
203
207
  })));
204
208
  var linkedGlobeMethods = Object.assign.apply(Object, _toConsumableArray(['getGlobeRadius', 'getCoords', 'toGeoCoords'].map(function (p) {
@@ -213,7 +217,6 @@ var linkedRenderObjsMethods = Object.assign.apply(Object, _toConsumableArray(['p
213
217
  return _defineProperty({}, p, bindRenderObjs.linkMethod(p));
214
218
  }))); //
215
219
 
216
- var GLOBE_RADIUS = 100;
217
220
  var globe = Kapsule__default["default"]({
218
221
  props: _objectSpread2(_objectSpread2({
219
222
  onZoom: {
@@ -489,6 +492,7 @@ var globe = Kapsule__default["default"]({
489
492
  this.hexPolygonsData([]);
490
493
  this.tilesData([]);
491
494
  this.labelsData([]);
495
+ this.htmlElementsData([]);
492
496
  this.objectsData([]);
493
497
  this.customLayerData([]);
494
498
  }
@@ -499,15 +503,18 @@ var globe = Kapsule__default["default"]({
499
503
  waitForGlobeReady = _ref6$waitForGlobeRea === void 0 ? true : _ref6$waitForGlobeRea,
500
504
  globeInitConfig = _objectWithoutProperties(_ref6, _excluded);
501
505
 
506
+ var globe = new ThreeGlobe__default["default"](_objectSpread2({
507
+ waitForGlobeReady: waitForGlobeReady
508
+ }, globeInitConfig));
502
509
  return {
503
- globe: new ThreeGlobe__default["default"](_objectSpread2({
504
- waitForGlobeReady: waitForGlobeReady
505
- }, globeInitConfig)),
510
+ globe: globe,
506
511
  renderObjs: ThreeRenderObjects__default["default"]({
507
512
  controlType: 'orbit',
508
513
  rendererConfig: rendererConfig,
509
- waitForLoadComplete: waitForGlobeReady
510
- }).skyRadius(GLOBE_RADIUS * 500).showNavInfo(false)
514
+ waitForLoadComplete: waitForGlobeReady,
515
+ extraRenderers: [new THREE.CSS2DRenderer()] // Used in HTML elements layer
516
+
517
+ }).skyRadius(globe.getGlobeRadius() * 500).showNavInfo(false)
511
518
  };
512
519
  },
513
520
  init: function init(domNode, state) {
@@ -523,18 +530,19 @@ var globe = Kapsule__default["default"]({
523
530
  state.container.appendChild(roDomNode);
524
531
  state.renderObjs(roDomNode); // inject renderer size on three-globe
525
532
 
526
- state.globe.rendererSize(state.renderObjs.renderer().getSize(new three.Vector2())); // set initial distance
533
+ state.globe.rendererSize(state.renderObjs.renderer().getSize(new THREE.Vector2())); // set initial distance
527
534
 
528
535
  this.pointOfView({
529
536
  altitude: 2.5
530
537
  }); // calibrate orbit controls
531
538
 
539
+ var globeR = state.globe.getGlobeRadius();
532
540
  var controls = state.renderObjs.controls();
533
- controls.minDistance = GLOBE_RADIUS * 1.01; // just above the surface
541
+ controls.minDistance = globeR * 1.01; // just above the surface
534
542
 
535
543
  setTimeout(function () {
536
- return controls.maxDistance = GLOBE_RADIUS * 100;
537
- }); // apply async after renderObjs sets maxDistance
544
+ return controls.maxDistance = globeR * 100;
545
+ }); // apply async after renderObjs sets maxDistance
538
546
 
539
547
  controls.enablePan = false;
540
548
  controls.enableDamping = true;
@@ -548,7 +556,9 @@ var globe = Kapsule__default["default"]({
548
556
  controls.rotateSpeed = pov.altitude * 0.2; // Math.pow(pov.altitude + 1, 2) * 0.025;
549
557
 
550
558
  controls.zoomSpeed = (pov.altitude + 1) * 0.1; // Math.sqrt(pov.altitude) * 0.2;
559
+ // Update three-globe pov when camera moves, for proper hiding of elements
551
560
 
561
+ state.globe.setPointOfView(state.renderObjs.camera().position);
552
562
  state.onZoom && state.onZoom(pov);
553
563
  }); // config renderObjs
554
564
 
@@ -595,7 +605,7 @@ var globe = Kapsule__default["default"]({
595
605
  }
596
606
  };
597
607
  state.renderObjs.objects([// Populate scene
598
- new three.AmbientLight(0xbbbbbb), new three.DirectionalLight(0xffffff, 0.6), state.globe]).hoverOrderComparator(function (a, b) {
608
+ new THREE.AmbientLight(0xbbbbbb), new THREE.DirectionalLight(0xffffff, 0.6), state.globe]).hoverOrderComparator(function (a, b) {
599
609
  var aObj = getGlobeObj(a);
600
610
  var bObj = getGlobeObj(b); // de-prioritize background / non-globe objects
601
611
 
@@ -1,4 +1,4 @@
1
- import { WebGLRendererParameters, Scene, Camera, WebGLRenderer, Object3D } from 'three';
1
+ import { WebGLRendererParameters, Scene, Camera, WebGLRenderer } from 'three';
2
2
  import { EffectComposer } from 'three/examples/jsm/postprocessing/EffectComposer.js';
3
3
  import { ConfigOptions as ConfigOptions$1, ThreeGlobeGeneric } from 'three-globe';
4
4
 
@@ -23,7 +23,11 @@ interface GeoCoords {
23
23
 
24
24
  type PointerEventsFilterFn = (object: Object3D, data?: object) => boolean;
25
25
 
26
- interface GlobeGenericInstance<ChainableInstance> extends ThreeGlobeGeneric<ChainableInstance> {
26
+ // don't surface these internal props from inner ThreeGlobe
27
+ type ExcludedInnerProps = 'setPointOfView';
28
+
29
+ interface GlobeGenericInstance<ChainableInstance>
30
+ extends Omit<ThreeGlobeGeneric<ChainableInstance>, ExcludedInnerProps> {
27
31
  (element: HTMLElement): ChainableInstance;
28
32
  resetProps(): ChainableInstance;
29
33
  _destructor(): void;