@geogirafe/lib-geoportal
Version:
GeoGirafe is a flexible application to build online geoportals.
71 lines (70 loc) • 2.63 kB
TypeScript
import type OlFeature from 'ol/Feature';
/**
* Represents a grid data organized by unique ids.
*/
export type GridDataById = Record<string, GridData>;
/**
* Represents the data structure for a grid, based on multiple features
* for a same ID (and with a same structure, geom type and properties).
* - Columns are every (not ol) features properties name;
* - Data are every (not ol) features properties values;
* - Features are every Ol features (backref);
* - notOlProperties are every property but without ol specific one.
*/
export interface GridData {
columns: string[];
data: unknown[][];
features: OlFeature[];
notOlProperties: Record<string, unknown>[];
}
/**
* Options for converting feature data to grid data.
*/
export interface FeatureToGridDataOptions {
/** Determines whether to keep the geometry property as a property value. */
keepGeomProperty?: boolean;
/** Determines whether to keep (always) empty columns or not in columns and data. */
removeEmptyColumns?: boolean;
}
/**
* A feature-to-grid data converter, to show feature's properties in grid-like system.
*/
export default class FeatureToGridDataById {
options: FeatureToGridDataOptions;
constructor(options: FeatureToGridDataOptions);
/**
* Takes an array of OpenLayers features and converts them into a grid data object, where each feature
* is mapped by its ID as the key.
* @returns The grid data objects, by id.
*/
toGridDataById(features: OlFeature[]): GridDataById;
/**
* @returns a gridDataByID for a single converted OL feature.
* @private
*/
private addFeatureToGridDataById;
/**
* @returns {GridData} A new empty grid data object with columns from given properties.
* @static
*/
static createGridDataWithColumns(properties: Record<string, unknown>): GridData;
/**
* Removes empty columns (columns and data) from a given gridData object.
* It's expected that all features in the gridData have the same properties.
* @static
*/
static removeEmptyColumns(gridData: GridData): void;
/**
* This method finds the indexes of empty columns in a given 2D array.
* @param data - The 2D array to search for empty columns.
* @returns An array of indexes representing the empty columns.
* @static
*/
static findEmptyColumnIndexOf(data: unknown[][]): number[];
/**
* @return The ID of the feature or 'UNKNOWN' if undefined.
* @static
*/
static getUserFeatureId(feature: OlFeature): string;
static getUserFeatureType(feature: OlFeature): string;
}