Skip to content

Commit

Permalink
[8.x] Allow custom MVT sources to style the map layers and provide cu…
Browse files Browse the repository at this point in the history
…stom legend (#200656) (#201864)

# Backport

This will backport the following commits from `main` to `8.x`:
- [Allow custom MVT sources to style the map layers and provide custom
legend (#200656)](#200656)

<!--- Backport version: 9.4.3 -->

### Questions ?
Please refer to the [Backport tool
documentation](https://github.com/sqren/backport)

<!--BACKPORT [{"author":{"name":"Sean
Sullivan","email":"[email protected]"},"sourceCommit":{"committedDate":"2024-11-26T20:07:12Z","message":"Allow
custom MVT sources to style the map layers and provide custom legend
(#200656)\n\n## Summary\r\n\r\nThis lets third party mvt sources run
custom maplibre layer filters, and\r\ncreate custom
styles.\r\n\r\n\r\n\r\n\r\n### Checklist\r\n\r\nCheck the PR satisfies
following conditions. \r\n\r\nReviewers should verify this PR satisfies
this list as well.\r\n\r\n- [x ] Any text added follows [EUI's
writing\r\nguidelines](https://elastic.github.io/eui/#/guidelines/writing),
uses\r\nsentence case text and includes
[i18n\r\nsupport](https://github.com/elastic/kibana/blob/main/packages/kbn-i18n/README.md)\r\n-
[x
]\r\n[Documentation](https://www.elastic.co/guide/en/kibana/master/development-documentation.html)\r\nwas
added for features that require explanation or tutorials\r\n- [x ] [Unit
or
functional\r\ntests](https://www.elastic.co/guide/en/kibana/master/development-tests.html)\r\nwere
updated or added to match the most common scenarios\r\n- [x ] If a
plugin configuration key changed, check if it needs to be\r\nallowlisted
in the cloud and added to the
[docker\r\nlist](https://github.com/elastic/kibana/blob/main/src/dev/build/tasks/os_packages/docker_generator/resources/base/bin/kibana-docker)\r\n-
[x ] This was checked for breaking HTTP API changes, and any
breaking\r\nchanges have been approved by the breaking-change committee.
The\r\n`release_note:breaking` label should be applied in these
situations.\r\n- [x ] [Flaky
Test\r\nRunner](https://ci-stats.kibana.dev/trigger_flaky_test_runner/1)
was\r\nused on any tests changed\r\n- [ ] The PR description includes
the appropriate Release Notes section,\r\nand the correct
`release_node:*` label is applied per
the\r\n[guidelines](https://www.elastic.co/guide/en/kibana/master/contributing.html#kibana-release-notes-process)\r\n\r\n###
Identify risks\r\n\r\nDoes this PR introduce any risks? For example,
consider risks like hard\r\nto test bugs, performance regression,
potential of data loss.\r\n\r\nDescribe the risk, its severity, and
mitigation for each identified\r\nrisk. Invite stakeholders and evaluate
how to proceed before merging.\r\n\r\n- [ ] [See some
risk\r\nexamples](https://github.com/elastic/kibana/blob/main/RISK_MATRIX.mdx)\r\n-
[ ] ...\r\n\r\n---------\r\n\r\nCo-authored-by: Sean Sullivan
<[email protected]>","sha":"d993bf4e0c0445580881a1d1f996b4126acea38c","branchLabelMapping":{"^v9.0.0$":"main","^v8.18.0$":"8.x","^v(\\d+).(\\d+).\\d+$":"$1.$2"}},"sourcePullRequest":{"labels":["release_note:enhancement","Team:Presentation","💝community","v9.0.0","Feature:Maps","backport:version","v8.18.0"],"title":"Allow
custom MVT sources to style the map layers and provide custom
legend","number":200656,"url":"https://github.com/elastic/kibana/pull/200656","mergeCommit":{"message":"Allow
custom MVT sources to style the map layers and provide custom legend
(#200656)\n\n## Summary\r\n\r\nThis lets third party mvt sources run
custom maplibre layer filters, and\r\ncreate custom
styles.\r\n\r\n\r\n\r\n\r\n### Checklist\r\n\r\nCheck the PR satisfies
following conditions. \r\n\r\nReviewers should verify this PR satisfies
this list as well.\r\n\r\n- [x ] Any text added follows [EUI's
writing\r\nguidelines](https://elastic.github.io/eui/#/guidelines/writing),
uses\r\nsentence case text and includes
[i18n\r\nsupport](https://github.com/elastic/kibana/blob/main/packages/kbn-i18n/README.md)\r\n-
[x
]\r\n[Documentation](https://www.elastic.co/guide/en/kibana/master/development-documentation.html)\r\nwas
added for features that require explanation or tutorials\r\n- [x ] [Unit
or
functional\r\ntests](https://www.elastic.co/guide/en/kibana/master/development-tests.html)\r\nwere
updated or added to match the most common scenarios\r\n- [x ] If a
plugin configuration key changed, check if it needs to be\r\nallowlisted
in the cloud and added to the
[docker\r\nlist](https://github.com/elastic/kibana/blob/main/src/dev/build/tasks/os_packages/docker_generator/resources/base/bin/kibana-docker)\r\n-
[x ] This was checked for breaking HTTP API changes, and any
breaking\r\nchanges have been approved by the breaking-change committee.
The\r\n`release_note:breaking` label should be applied in these
situations.\r\n- [x ] [Flaky
Test\r\nRunner](https://ci-stats.kibana.dev/trigger_flaky_test_runner/1)
was\r\nused on any tests changed\r\n- [ ] The PR description includes
the appropriate Release Notes section,\r\nand the correct
`release_node:*` label is applied per
the\r\n[guidelines](https://www.elastic.co/guide/en/kibana/master/contributing.html#kibana-release-notes-process)\r\n\r\n###
Identify risks\r\n\r\nDoes this PR introduce any risks? For example,
consider risks like hard\r\nto test bugs, performance regression,
potential of data loss.\r\n\r\nDescribe the risk, its severity, and
mitigation for each identified\r\nrisk. Invite stakeholders and evaluate
how to proceed before merging.\r\n\r\n- [ ] [See some
risk\r\nexamples](https://github.com/elastic/kibana/blob/main/RISK_MATRIX.mdx)\r\n-
[ ] ...\r\n\r\n---------\r\n\r\nCo-authored-by: Sean Sullivan
<[email protected]>","sha":"d993bf4e0c0445580881a1d1f996b4126acea38c"}},"sourceBranch":"main","suggestedTargetBranches":["8.x"],"targetPullRequestStates":[{"branch":"main","label":"v9.0.0","branchLabelMappingKey":"^v9.0.0$","isSourceBranch":true,"state":"MERGED","url":"https://github.com/elastic/kibana/pull/200656","number":200656,"mergeCommit":{"message":"Allow
custom MVT sources to style the map layers and provide custom legend
(#200656)\n\n## Summary\r\n\r\nThis lets third party mvt sources run
custom maplibre layer filters, and\r\ncreate custom
styles.\r\n\r\n\r\n\r\n\r\n### Checklist\r\n\r\nCheck the PR satisfies
following conditions. \r\n\r\nReviewers should verify this PR satisfies
this list as well.\r\n\r\n- [x ] Any text added follows [EUI's
writing\r\nguidelines](https://elastic.github.io/eui/#/guidelines/writing),
uses\r\nsentence case text and includes
[i18n\r\nsupport](https://github.com/elastic/kibana/blob/main/packages/kbn-i18n/README.md)\r\n-
[x
]\r\n[Documentation](https://www.elastic.co/guide/en/kibana/master/development-documentation.html)\r\nwas
added for features that require explanation or tutorials\r\n- [x ] [Unit
or
functional\r\ntests](https://www.elastic.co/guide/en/kibana/master/development-tests.html)\r\nwere
updated or added to match the most common scenarios\r\n- [x ] If a
plugin configuration key changed, check if it needs to be\r\nallowlisted
in the cloud and added to the
[docker\r\nlist](https://github.com/elastic/kibana/blob/main/src/dev/build/tasks/os_packages/docker_generator/resources/base/bin/kibana-docker)\r\n-
[x ] This was checked for breaking HTTP API changes, and any
breaking\r\nchanges have been approved by the breaking-change committee.
The\r\n`release_note:breaking` label should be applied in these
situations.\r\n- [x ] [Flaky
Test\r\nRunner](https://ci-stats.kibana.dev/trigger_flaky_test_runner/1)
was\r\nused on any tests changed\r\n- [ ] The PR description includes
the appropriate Release Notes section,\r\nand the correct
`release_node:*` label is applied per
the\r\n[guidelines](https://www.elastic.co/guide/en/kibana/master/contributing.html#kibana-release-notes-process)\r\n\r\n###
Identify risks\r\n\r\nDoes this PR introduce any risks? For example,
consider risks like hard\r\nto test bugs, performance regression,
potential of data loss.\r\n\r\nDescribe the risk, its severity, and
mitigation for each identified\r\nrisk. Invite stakeholders and evaluate
how to proceed before merging.\r\n\r\n- [ ] [See some
risk\r\nexamples](https://github.com/elastic/kibana/blob/main/RISK_MATRIX.mdx)\r\n-
[ ] ...\r\n\r\n---------\r\n\r\nCo-authored-by: Sean Sullivan
<[email protected]>","sha":"d993bf4e0c0445580881a1d1f996b4126acea38c"}},{"branch":"8.x","label":"v8.18.0","branchLabelMappingKey":"^v8.18.0$","isSourceBranch":false,"state":"NOT_CREATED"}]}]
BACKPORT-->

Co-authored-by: Sean Sullivan <[email protected]>
  • Loading branch information
kibanamachine and desean1625 authored Nov 26, 2024
1 parent e584318 commit 4ee7416
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 4ee7416

Please sign in to comment.