jansule commented on code in PR #39760: URL: https://github.com/apache/superset/pull/39760#discussion_r4400962907
########## superset-frontend/src/explore/components/controls/LayerConfigsControl/geoStylerUtil.ts: ########## @@ -0,0 +1,183 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +import { FeatureCollection, GeoJsonGeometryTypes } from 'geojson'; +import { VectorData } from 'geostyler-data'; +import { GeoStylerContextInterface, GeoStylerLocale, locale } from 'geostyler'; + +import { Style, Symbolizer } from 'geostyler-style'; +import { ColTypeMapping } from './types'; +import { SupersetTheme } from '@apache-superset/core/theme'; + +/** + * Map Superset column type to GeoStyler column type. + * @param colType The Superset columntype + * @returns The GeoStyler column type. + */ +export const colTypeToGeoStylerType = (colType: string) => { + // TODO add missing types + switch (colType) { + case 'LONGINTEGER': + case 'INTEGER': + return 'integer'; + case 'STRING': + return 'string'; + case 'DATETIME': + case 'DATE': + case 'FLOAT': + case 'DECIMAL': + return 'number'; + default: + return colType; + } +}; + +/** + * Map Superset column types to GeoStyler data. + * @param colTypes The superset column types. + * @returns A geotyler-data object. + */ +export const colTypesToGeoStylerData = ( + colTypes: ColTypeMapping, + dataFeatureCollection: FeatureCollection = { + type: 'FeatureCollection', + features: [], + }, +) => { + const data: VectorData = { + schema: { + type: 'object', + properties: Object.keys(colTypes).reduce( + (prev, cur) => ({ + ...prev, + [cur]: { + type: colTypeToGeoStylerType(colTypes[cur]), + }, + }), + {}, + ), + }, + exampleFeatures: dataFeatureCollection, + }; + return data; +}; + +/** + * Create a GeoStylerContext. + * + * Sets the locales, GsData, and enables and disables certain features + * depending on given data and their geometries. + * + * @param gsLocale The locales of the active language. + * @param data The GeoStyler Data. + * @param geomTypes List of distinct geometry types. + * @returns The GeoStylerContext. + */ +export const createGeoStylerContext = ( + gsLocale: GeoStylerLocale, + data: VectorData | undefined, + composition: GeoStylerContextInterface['composition'], +) => { + const context: GeoStylerContextInterface = { + locale: gsLocale, + composition: composition ?? {}, + }; + + if (data) { + context.data = data; + } + + if (!context.composition!.Rules) { + context.composition!.Rules = {}; + } + context.composition!.Rules.disableClassification = Review Comment: The first thought was to ensure classification will not be disabled unintentionally. But it makes sense to allow for explicit disabling. Adjusted in https://github.com/apache/superset/pull/39760/commits/7df9a0a5019a3068919eb060b4cd48d29a28e244 -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected] --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
