Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow custom MVT sources to style the map layers and provide custom legend #200656

Merged
merged 9 commits into from
Nov 26, 2024
Original file line number Diff line number Diff line change
Expand Up @@ -426,6 +426,11 @@ export class MvtVectorLayer extends AbstractVectorLayer {
this._setMbPointsProperties(mbMap, sourceData.tileSourceLayer);
this._setMbLinePolygonProperties(mbMap, sourceData.tileSourceLayer);
this._syncTooManyFeaturesProperties(mbMap);
const myLayers = mbMap.getStyle().layers.filter((mbLayer:any) => {
return this.ownsMbLayerId(mbLayer.id)
});
const layerIds = myLayers.map(layer=>layer.id)
this.getSource().syncSourceStyle(mbMap,layerIds)
desean1625 marked this conversation as resolved.
Show resolved Hide resolved
}

// TODO ES MVT specific - move to es_tiled_vector_layer implementation
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
* 2.0.
*/

import React from 'react';
import React, { ReactElement } from 'react';
import {
FeatureCollection,
GeoJsonProperties,
Expand All @@ -17,7 +17,7 @@ import {
import type { KibanaExecutionContext } from '@kbn/core/public';
import { i18n } from '@kbn/i18n';
import type { Query } from '@kbn/data-plugin/common';
import type { MapGeoJSONFeature } from '@kbn/mapbox-gl';
import type { MapGeoJSONFeature, Map as MbMap, } from '@kbn/mapbox-gl';
import { Filter } from '@kbn/es-query';
import type { TimeRange } from '@kbn/es-query';
import { Adapters } from '@kbn/inspector-plugin/common/adapters';
Expand All @@ -36,6 +36,7 @@ import {
} from '../../../../common/descriptor_types';
import { DataRequest } from '../../util/data_request';
import { FeatureGeometryFilterForm } from '../../../connected_components/mb_map/tooltip_control/features_tooltip';
import { IVectorStyle } from '../../styles/vector/vector_style';

export function hasVectorSourceMethod(
source: ISource,
Expand Down Expand Up @@ -145,9 +146,27 @@ export interface IVectorSource extends ISource {
* Provide unique ids for managing source requests in Inspector
*/
getInspectorRequestIds(): string[];

/**
* Syncs source specific styling with mbMap this allows custom sources to further style the map layers/filters
*/
syncSourceStyle(mbMap:MbMap,layers:string[]):void
desean1625 marked this conversation as resolved.
Show resolved Hide resolved

/**
* specifies if a source provides its own legend details or if the default vector_style is used if the source has this method it must also implement renderLegendDetails
*/
hasLegendDetails?(): Promise<boolean>
/**
* specifies if a source provides its own legend details or if the default vector_style is used
*/
renderLegendDetails?(vectorStyle:IVectorStyle): ReactElement<any> | null
}

export class AbstractVectorSource extends AbstractSource implements IVectorSource {

syncSourceStyle(mbMap: MbMap, layers: string[]): void {
desean1625 marked this conversation as resolved.
Show resolved Hide resolved
//Nothing internal currently implements this
}
isMvt() {
return false;
}
Expand Down Expand Up @@ -199,7 +218,7 @@ export class AbstractVectorSource extends AbstractSource implements IVectorSourc

// Allow source to filter and format feature properties before displaying to user
async getTooltipProperties(
properties: GeoJsonProperties,
properties: any,
desean1625 marked this conversation as resolved.
Show resolved Hide resolved
executionContext: KibanaExecutionContext
): Promise<ITooltipProperty[]> {
const tooltipProperties: ITooltipProperty[] = [];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -721,13 +721,18 @@ export class VectorStyle implements IVectorStyle {
};

async hasLegendDetails() {
if(this._source.hasLegendDetails){
return await this._source.hasLegendDetails()
}
return this._getLegendDetailStyleProperties().length > 0;
}

renderLegendDetails() {
const symbolId = this._getSymbolId();
const svg = symbolId ? this.getIconSvg(symbolId) : undefined;

if(this._source.renderLegendDetails){
desean1625 marked this conversation as resolved.
Show resolved Hide resolved
return this._source.renderLegendDetails(this) || <></>
}
return (
<VectorStyleLegend
masks={this._layer.getMasks()}
Expand Down