private updateBarsAndHeatMapByZoom()

in src/globemap.ts [1464:1558]


        private updateBarsAndHeatMapByZoom(delta: number = 0): void {
            if (!this.data) {
                return;
            }
            // delta > 0 ? Zoom increased
            // delta < 0 ? Zoom decreased
            let heatSizeScale: number = delta > 0 ? this.GlobeSettings.heatmapScaleOnZoom : (1 / this.GlobeSettings.heatmapScaleOnZoom);
            let barHeightScale: number = delta > 0 ? this.GlobeSettings.barHeightScaleOnZoom : (1 / this.GlobeSettings.barHeightScaleOnZoom);
            let barWidthtScale: number = delta > 0 ? this.GlobeSettings.barWidthScaleOnZoom : (1 / this.GlobeSettings.barWidthScaleOnZoom);

            if (delta === 0) {
                heatSizeScale = 1;
                barHeightScale = 1;
                barWidthtScale = 1;
            }

            // Calculate new bar and heat sizes by zool level
            this.GlobeSettings.heatPointSize = this.calculateNewSizeOfShape(this.GlobeSettings.heatPointSize, heatSizeScale, this.GlobeSettings.minHeatPointSize, this.GlobeSettings.maxHeatPointSize);
            this.GlobeSettings.heatIntensity = this.calculateNewSizeOfShape(this.GlobeSettings.heatIntensity, heatSizeScale, this.GlobeSettings.minHeatIntensity, this.GlobeSettings.maxHeatIntensity);
            this.GlobeSettings.barHeight = this.calculateNewSizeOfShape(this.GlobeSettings.barHeight, barHeightScale, this.GlobeSettings.minBarHeight, this.GlobeSettings.maxBarHeight);
            this.GlobeSettings.barWidth = this.calculateNewSizeOfShape(this.GlobeSettings.barWidth, barWidthtScale, this.GlobeSettings.minBarWidth, this.GlobeSettings.maxBarWidth);

            this.cleanHeatAndBar();
            this.barsGroup = new THREE.Object3D();
            this.scene.add(this.barsGroup);
            this.averageBarVector = new THREE.Vector3();
            const len: number = this.data.dataPoints.length;
            for (let i: number = 0; i < len; ++i) {
                const renderDatum: GlobeMapDataPoint = this.data.dataPoints[i];

                if (!renderDatum.location || renderDatum.location.longitude === undefined || renderDatum.location.latitude === undefined
                    || (renderDatum.location.longitude === 0 && renderDatum.location.latitude === 0)
                ) {
                    continue;
                }

                if (renderDatum.heat > 0.001) {
                    if (renderDatum.heat < 0.1) renderDatum.heat = 0.1;
                    const x: number = (180 + renderDatum.location.longitude) / 360 * this.GlobeSettings.heatmapSize;
                    const y: number = (1 - ((90 + renderDatum.location.latitude) / 180)) * this.GlobeSettings.heatmapSize;

                    this.heatmap.addPoint(x, y, this.GlobeSettings.heatPointSize, renderDatum.heat * this.GlobeSettings.heatIntensity);
                }

                if (renderDatum.height >= 0) {
                    if (renderDatum.height < 0.01) renderDatum.height = 0.01;
                    const latRadians: number = renderDatum.location.latitude / 180 * Math.PI; // radians
                    const lngRadians: number = renderDatum.location.longitude / 180 * Math.PI;

                    const x: number = Math.cos(lngRadians) * Math.cos(latRadians);
                    const z: number = -Math.sin(lngRadians) * Math.cos(latRadians);
                    const y: number = Math.sin(latRadians);
                    const vector: THREE.Vector3 = new THREE.Vector3(x, y, z);

                    this.averageBarVector.add(vector);

                    const barHeight: number = this.GlobeSettings.barHeight * renderDatum.height;
                    // this array holds the relative series values to the actual measure for example [0.2,0.3,0.5]
                    // this is how we draw the vectors relativly to the complete value one on top of another.
                    const measuresBySeries: number[] = [];
                    // this array holds the original values of the series for the tool tips
                    const dataPointToolTip: string[] = [];
                    if (renderDatum.heightBySeries) {
                        for (let c: number = 0; c < renderDatum.heightBySeries.length; c++) {
                            if (renderDatum.heightBySeries[c] || renderDatum.heightBySeries[c] === 0) {
                                measuresBySeries.push(renderDatum.heightBySeries[c]);
                            }
                            dataPointToolTip.push(renderDatum.seriesToolTipData && renderDatum.seriesToolTipData[c] ? renderDatum.seriesToolTipData[c] : "");
                        }
                    } else {
                        // no category series so we'll just draw one value
                        measuresBySeries.push(1);
                    }

                    let previousMeasureValue = 0;
                    for (let j: number = 0; j < measuresBySeries.length; j++) {
                        previousMeasureValue += measuresBySeries[j];
                        const geometry: THREE.BoxGeometry = new THREE.BoxGeometry(this.GlobeSettings.barWidth, this.GlobeSettings.barWidth, barHeight * measuresBySeries[j]);
                        const bar: THREE.Mesh & { toolTipData } = <THREE.Mesh & { toolTipData }>new THREE.Mesh(geometry, this.getBarMaterialByIndex(i));
                        const position: THREE.Vector3 = vector.clone().multiplyScalar(this.GlobeSettings.earthRadius + ((barHeight / 2) * previousMeasureValue));
                        bar.position.set(position.x, position.y, position.z);
                        bar.lookAt(vector);
                        bar.toolTipData = dataPointToolTip.length === 0
                            ? renderDatum.toolTipData
                            : this.getToolTipDataForSeries(renderDatum.toolTipData, dataPointToolTip[j]);

                        this.barsGroup.add(bar);

                        previousMeasureValue += measuresBySeries[j];
                    }
                }
            }

            this.heatmap.update();
        }