UNPKG

kepler.gl.geoiq

Version:

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

149 lines (137 loc) 4.42 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 CategoryWidgetIcon from './category-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 'Category'; } get isAggregated() { return false; } get widgetIcon() { return CategoryWidgetIcon; } get widgetAggregatedData() { return null; } calculateAggregationData( newWidget, filters, datasets, mapState, auth, project ) { const {dataId, aggregationType, bounds} = newWidget.config; var {fields, indexName} = datasets[dataId]; let sortableCategories = []; const categoryField = newWidget.config.categoryField; const fieldName = newWidget.config.fieldName; const fieldIdx = fields.findIndex(f => f.name === fieldName); const {uid} = auth; const {isEdit} = project; let boundingBox; let boundingPolygon; let cLL; let cLR; let cUL; let cUR; if (!aggregationType || (aggregationType !== 'count' && fieldIdx <= 0)) return null; 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]] }; } // newWidget.config.fieldName || const apiCallData = { aggregationType, filters: JSON.stringify(filters.filter(f => f.dataId.includes(dataId))), viewport: JSON.stringify(boundingPolygon), fieldName, dynamic: Boolean(bounds), categoryField, userId: uid, fieldType: fieldName ? fields[fieldIdx].type === 'string' ? 'string' : 'numeric' : null, indexName, 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 => { sortableCategories = result.data.aggregatedData; sortableCategories = sortableCategories.sort(function(a, b) { return b[1] - a[1]; }); sortableCategories.length = 5; sortableCategories = sortableCategories.map(sc => { return {y: sc[0], x: sc[1]}; }); // this.updateWidgetConfig({aggregatedData: sortableCategories}); // newWidget.config.aggregatedData = sortableCategories; return sortableCategories; }); return response; } }