Skip to content

Commit

Permalink
Allow custom MVT sources to style the map layers and provide custom l…
Browse files Browse the repository at this point in the history
…egend (elastic#200656)

## Summary

This lets third party mvt sources run custom maplibre layer filters, and
create custom styles.




### Checklist

Check the PR satisfies following conditions. 

Reviewers should verify this PR satisfies this list as well.

- [x ] Any text added follows [EUI's writing
guidelines](https://elastic.github.io/eui/#/guidelines/writing), uses
sentence case text and includes [i18n
support](https://github.com/elastic/kibana/blob/main/packages/kbn-i18n/README.md)
- [x ]
[Documentation](https://www.elastic.co/guide/en/kibana/master/development-documentation.html)
was added for features that require explanation or tutorials
- [x ] [Unit or functional
tests](https://www.elastic.co/guide/en/kibana/master/development-tests.html)
were updated or added to match the most common scenarios
- [x ] If a plugin configuration key changed, check if it needs to be
allowlisted in the cloud and added to the [docker
list](https://github.com/elastic/kibana/blob/main/src/dev/build/tasks/os_packages/docker_generator/resources/base/bin/kibana-docker)
- [x ] This was checked for breaking HTTP API changes, and any breaking
changes have been approved by the breaking-change committee. The
`release_note:breaking` label should be applied in these situations.
- [x ] [Flaky Test
Runner](https://ci-stats.kibana.dev/trigger_flaky_test_runner/1) was
used on any tests changed
- [ ] The PR description includes the appropriate Release Notes section,
and the correct `release_node:*` label is applied per the
[guidelines](https://www.elastic.co/guide/en/kibana/master/contributing.html#kibana-release-notes-process)

### Identify risks

Does this PR introduce any risks? For example, consider risks like hard
to test bugs, performance regression, potential of data loss.

Describe the risk, its severity, and mitigation for each identified
risk. Invite stakeholders and evaluate how to proceed before merging.

- [ ] [See some risk
examples](https://github.com/elastic/kibana/blob/main/RISK_MATRIX.mdx)
- [ ] ...

---------

Co-authored-by: Sean Sullivan <[email protected]>
  • Loading branch information
2 people authored and paulinashakirova committed Nov 26, 2024
1 parent 8829f88 commit b663b43
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -426,6 +426,12 @@ export class MvtVectorLayer extends AbstractVectorLayer {
this._setMbPointsProperties(mbMap, sourceData.tileSourceLayer);
this._setMbLinePolygonProperties(mbMap, sourceData.tileSourceLayer);
this._syncTooManyFeaturesProperties(mbMap);
(this.getSource() as IMvtVectorSource).syncSourceStyle?.(mbMap, () =>
mbMap
.getStyle()
.layers.filter((mbLayer) => this.ownsMbLayerId(mbLayer.id))
.map((layer) => layer.id)
);
}

// 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,6 +5,7 @@
* 2.0.
*/

import type { Map as MbMap } from '@kbn/mapbox-gl';
import { VectorSourceRequestMeta } from '../../../../common/descriptor_types';
import { IVectorSource } from '.';

Expand All @@ -25,4 +26,9 @@ export interface IMvtVectorSource extends IVectorSource {
* Use getTileSourceLayer to specify the displayed source layer.
*/
getTileSourceLayer(): string;

/**
* Syncs source specific styling with mbMap this allows custom sources to further style the map layers/filters
*/
syncSourceStyle?(mbMap: MbMap, getLayerIds: () => string[]): void;
}
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 @@ -22,6 +22,7 @@ import { Filter } from '@kbn/es-query';
import type { TimeRange } from '@kbn/es-query';
import { Adapters } from '@kbn/inspector-plugin/common/adapters';
import { ActionExecutionContext, Action } from '@kbn/ui-actions-plugin/public';
import { IVectorStyle } from '../../styles/vector/vector_style';
import { GEO_JSON_TYPE, VECTOR_SHAPE_TYPE } from '../../../../common/constants';
import { TooltipFeatureAction } from '../../../../common/descriptor_types';
import { ITooltipProperty, TooltipProperty } from '../../tooltips/tooltip_property';
Expand Down Expand Up @@ -145,6 +146,15 @@ export interface IVectorSource extends ISource {
* Provide unique ids for managing source requests in Inspector
*/
getInspectorRequestIds(): string[];

/**
* 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 {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ export interface IVectorStyle extends IStyle {
getIconSvg(symbolId: string): string | undefined;
isUsingCustomIcon(symbolId: string): boolean;
hasLegendDetails: () => Promise<boolean>;
renderLegendDetails: () => ReactElement;
renderLegendDetails: () => ReactElement | null;
clearFeatureState: (featureCollection: FeatureCollection, mbMap: MbMap, sourceId: string) => void;
setFeatureStateAndStyleProps: (
featureCollection: FeatureCollection,
Expand Down Expand Up @@ -721,14 +721,18 @@ export class VectorStyle implements IVectorStyle {
};

async hasLegendDetails() {
return this._getLegendDetailStyleProperties().length > 0;
return this._source.hasLegendDetails && this._source.renderLegendDetails
? await this._source.hasLegendDetails()
: this._getLegendDetailStyleProperties().length > 0;
}

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

return (
return this._source.renderLegendDetails ? (
this._source.renderLegendDetails(this)
) : (
<VectorStyleLegend
masks={this._layer.getMasks()}
styles={this._getLegendDetailStyleProperties()}
Expand Down

0 comments on commit b663b43

Please sign in to comment.