UNPKG

kepler.gl.geoiq

Version:

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

142 lines (131 loc) 4.07 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 Widget from '../base-widget'; import FunctionWidgetIcon from './function-widget-icon'; import geoViewport from '@mapbox/geo-viewport'; import WebMercatorViewport from 'viewport-mercator-project'; import axios from 'axios'; import {ON_PREMESIS_URL} from 'constants/default-settings'; export default class FunctionWidget extends Widget { constructor(props) { super(props); } get type() { return 'Function'; } get isAggregated() { return false; } get widgetIcon() { return FunctionWidgetIcon; } get widgetAggregatedData() { return null; } calculateAggregationData( newWidget, filters, datasets, mapState, auth, project ) { const {dataId, aggregationType, bounds} = newWidget.config; let cLL; let cLR; let cUL; let cUR; const fieldName = newWidget.config.fieldName; var {fields, indexName} = datasets[dataId]; const fieldIdx = fields.findIndex(f => f.name === fieldName); const {uid} = auth; const {isEdit} = project; let boundingBox; let boundingPolygon; if (mapState && bounds) { const { longitude, latitude, height, width, zoom, pitch, bearing } = mapState; boundingBox = geoViewport.bounds([longitude, latitude], zoom, [ width, height ]); const viewport = new WebMercatorViewport({ width, height, longitude, latitude, zoom, pitch, bearing }); cUL = viewport.unproject([0, 0]); cUR = viewport.unproject([width, 0]); cLR = viewport.unproject([width, height]); cLL = viewport.unproject([0, height]); boundingPolygon = { type: 'Polygon', coordinates: [[cUL, cUR, cLR, cLL, cUL]] }; } // fieldType // numeric // string var filter = filters.filter(f => f.dataId.includes(dataId)); const apiCallData = { aggregationType, filters: JSON.stringify(filter), viewport: JSON.stringify(boundingPolygon), fieldName, dynamic: Boolean(bounds), userId: uid, indexName, fieldType: fieldName ? fields[fieldIdx].type === 'string' ? 'string' : 'numeric' : null, permissionType: isEdit }; const config = { headers: { 'Content-Type': 'application/json' } }; const response = axios .post( `${ON_PREMESIS_URL }/geoiqutilities/widget/v1.0/fetch`, apiCallData, config ) .then(result => { // newWidget.config.aggregatedData = result.data.aggregatedData[0]; // newWidget.config.isCalculating = false; // this.updateWidgetConfig({ // aggregatedData: result.data.aggregatedData[0], // isCalculating: false // }); return result.data.aggregatedData[0]; }); return response; } }