UNPKG

kepler.gl.geoiq

Version:

kepler.gl is a webgl based application to visualize large scale location data in the browser

133 lines (119 loc) 4.1 kB
// Copyright (c) 2023 Uber Technologies, Inc. // // Permission is hereby granted, free of charge, to any person obtaining a copy // of this software and associated documentation files (the "Software"), to deal // in the Software without restriction, including without limitation the rights // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell // copies of the Software, and to permit persons to whom the Software is // furnished to do so, subject to the following conditions: // // The above copyright notice and this permission notice shall be included in // all copies or substantial portions of the Software. // // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN // THE SOFTWARE. import openSocket from 'socket.io-client'; const socket = openSocket( 'https://platform-apis.staging.geoiq.io/socketsapi/v1.0/datasetupdate', {forceNew: true} ); export function dashboardConnection(props) { const {layers, datasets, project, auth, visStateActions} = props; const userId = auth.uid; // { // layers, // datasets, // project, // auth, // visStateActions // } const datasetKeys = Object.keys(datasets); const filteredDatasetKeys = datasetKeys.filter( dk => datasets[dk].isLiveDataset === true ); const datasetIds = filteredDatasetKeys.map(dk => datasets[dk].datasetId); socket.on('send_message_to_client', function(msg) { // $('#messagelist').append('<li>' + msg + '</li>'); // datasetIds = Object.keys(datasets); const updateDatasetIds = datasetKeys.filter( d => datasets[d].datasetId === msg.dsId ); layers.map(layer => { if (updateDatasetIds.indexOf(layer.config.dataId) > -1) { visStateActions.layerConfigChange(layer, { apiCallRequest: true }); } }); }); socket.emit('invoke_pg', { userId, datasetIds }); } export function removeDashboardConnection(props) { const {auth, datasets} = props; const userId = auth.uid; const datasetKeys = Object.keys(datasets); const filteredDatasetKeys = datasetKeys.filter( dk => datasets[dk].isLiveDataset === true ); const datasetIds = filteredDatasetKeys.map(dk => datasets[dk].datasetId); socket.emit('remove_from_room', { userId, datasetIds }); } export function removeDatasetSocket(datasetIds, auth) { const userId = auth.uid; socket.emit('remove_from_room', { userId, datasetIds }); } export function addDatasetSocket(props, updateSocketLayer) { const { auth, listenToSocket, datasets, layers, visStateActions, datasetIdsToAdd } = props; const userId = auth.uid; // socket.on('send_message_to_client', function(msg) { // // $('#messagelist').append('<li>' + msg + '</li>'); // console.log( // 'socket.io msg client ', // msg // // , typeof msg, JSON.parse(msg) // ); // // datasetIds = Object.keys(datasets); // const datasetKeys = Object.keys(datasets); // const updateDatasetIds = datasetKeys.filter( // d => datasets[d].datasetId === msg.dsId // ); // layers.map(layer => { // if (updateDatasetIds.indexOf(layer.config.dataId) > -1) { // visStateActions.layerConfigChange(layer, { // apiCallRequest: true // }); // } // }); // }); if (listenToSocket === true) { socket.on('send_message_to_client', data => updateSocketLayer(data)); } socket.emit('invoke_pg', { userId, datasetIds: datasetIdsToAdd }); } export function listenDataUpdates(updateSocketLayer) { return socket.on('send_message_to_clients', data => updateSocketLayer(data)); }