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

[Maps] Support custom icons in maps #113144

Merged
merged 73 commits into from
Mar 30, 2022
Merged

Conversation

nickpeihl
Copy link
Member

@nickpeihl nickpeihl commented Sep 27, 2021

Fixes #30738

Summary

Adds support for users to upload their own SVG icons for styling geo_points or clusters in Elastic Maps.

Because Elastic Maps uses WebGL, dynamic styling requires rendering SVG icons as monochromatic PNGs using a Signed Distance Function algorithm. As a result, highly detailed designs and any color definitions in SVGs uploaded to Maps are not retained. Monochromatic SVG icons such as these examples from Wikimedia work best.

Custom icons are appended to the map saved object and are not accessible in other maps. Using the custom icon in another map requires creating a copy of the existing map or uploading the icon to the new map. Custom icons can be added, edited, or deleted in Map Settings. Custom icons can also be added from within the Icon select menu.

Checklist

Delete any items that are not applicable to this PR.

Risk Matrix

Delete this section if it is not applicable to this PR.

Before closing this PR, invite QA, stakeholders, and other developers to identify risks that should be tested prior to the change/feature release.

When forming the risk matrix, consider some of the following examples and how they may potentially impact the change:

Risk Probability Severity Mitigation/Notes
Multiple Spaces—unexpected behavior in non-default Kibana Space. Low High Integration tests will verify that all features are still supported in non-default Kibana Space and when user switches between spaces.
Multiple nodes—Elasticsearch polling might have race conditions when multiple Kibana nodes are polling for the same tasks. High Low Tasks are idempotent, so executing them multiple times will not result in logical error, but will degrade performance. To test for this case we add plenty of unit tests around this logic and document manual testing procedure.
Code should gracefully handle cases when feature X or plugin Y are disabled. Medium High Unit tests will verify that any feature flag or plugin combination still results in our service operational.
See more potential risk examples

For maintainers

* Re-uses code from Canvas asset manager component to upload images
* Adds "Add Custom Icon" button to IconSelect component
* Adds CustomIcons array to VectorStyle descriptor (not yet persisted to saved object)
@nickpeihl nickpeihl changed the title [Maps] Initial work on custom icon support in maps [Maps] Support custom icons in maps Sep 27, 2021
@nickpeihl nickpeihl added the [Deprecated-Use Team:Presentation]Team:Geo Former Team Label for Geo Team. Now use Team:Presentation label Sep 27, 2021
@kibanamachine
Copy link
Contributor

kibanamachine commented Sep 28, 2021

💔 Build Failed

Failed CI Steps

Metrics [docs]

‼️ ERROR: metrics for 74d8cf0 were not reported

History

To update your PR or re-run it, just comment with:
@elasticmachine merge upstream

* Convert SVG icon to SDF
* Add SDF icon to map
* Add Image2SDF class (based on tiny-sdf)

Note: Only tested with simple monochrome SVG icons.
Examples: https://commons.wikimedia.org/wiki/Category:Black_SVG_icons
* Adds components for fine tuning cutoff and radius in SDF
* Uses bitmap-sdf library instead of custom library

Custom icon sizes still differ from maki icon sizes. Not sure why this is happening.

Maybe we consider generating SDF icons for maki on the fly as well instead of pregenerating them in a separate library?
@jsanz
Copy link
Member

jsanz commented Nov 17, 2021

I gave this a first test and it works great! The user experience is pretty good with the sliders to adapt the render for each icon.

image

I tested it rendering from all different scaling options without issues.

@elastic elastic deleted a comment from kibanamachine Jan 5, 2022
@nickpeihl nickpeihl dismissed mdefazio’s stale review March 29, 2022 20:20

Made the requested changes.

customIcons,
}) {
return iconStops.map(({ stop, icon, iconSource }, index) => {
const { svg, label } =
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

customIcons.find(({ symbolId }) => symbolId === icon) and getMakiSymbol(icon) can return undefined and you can not spread undefined. Add logic to handle case where icon is not found

@@ -27,9 +28,11 @@ export interface Props<StaticOptions, DynamicOptions> {
defaultDynamicStyleOptions: DynamicOptions;
disabled?: boolean;
disabledBy?: VECTOR_STYLES;
customIcons?: CustomIcon[];
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

type as customIcons: CustomIcon[];

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Classes like VectorStyleColorEditor and VectorStyleSizeEditor inherit from StylePropEditor but don't use customIcons, so I don't require them here.

fields: StyleField[];
onDynamicStyleChange: (propertyName: VECTOR_STYLES, options: DynamicOptions) => void;
onStaticStyleChange: (propertyName: VECTOR_STYLES, options: StaticOptions) => void;
onCustomIconsChange?: (customIcons: CustomIcon[]) => void;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Type as onCustomIconsChange: (customIcons: CustomIcon[]) => void;

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Classes like VectorStyleColorEditor and VectorStyleSizeEditor inherit from StylePropEditor but don't use onCustomIconsChange.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

then should onCustomIconsChange be moved to VectorStyleIconEditor?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The updateCustomIcons function from map_actions is mapped as a Prop in the StyleSettings and passed to the layer.renderStyleEditor method. I'm not sure if there's a better way to connect the map action directly to VectorStyleIconEditor?

@@ -697,12 +711,32 @@ export class VectorStyle implements IVectorStyle {
return formatters ? formatters[fieldName] : null;
};

getIconSvg(symbolId: string) {
const meta = this._getIconMeta(symbolId);
if (meta) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Change to

return meta ? meta.svg : undefined

return { ...icon, iconSource: ICON_SOURCE.CUSTOM };
}
const symbol = getMakiSymbol(symbolId);
return symbol ? { ...symbol, iconSource: ICON_SOURCE.MAKI } : {};
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Change to return symbol ? { ...symbol, iconSource: ICON_SOURCE.MAKI } : undefined;

_getIconMeta(
symbolId: string
): { svg: string; label: string; iconSource: ICON_SOURCE } | undefined {
if (!symbolId) return;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

remove !symbolId check, symbolId is required

@nickpeihl nickpeihl requested a review from nreese March 29, 2022 21:21
iconSource === ICON_SOURCE.CUSTOM
? customIcons.find(({ symbolId }) => symbolId === icon)
: getMakiSymbol(icon);
if (!iconInfo) return;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This may cause problems. You are in map function so returning undefined will return an array of ReactNode and undefined. How about adding a filter after iconStops.map to remove undefineds?

@@ -92,7 +93,8 @@ export interface ILayer {
isVisible(): boolean;
cloneDescriptor(): Promise<LayerDescriptor>;
renderStyleEditor(
onStyleDescriptorChange: (styleDescriptor: StyleDescriptor) => void
onStyleDescriptorChange: (styleDescriptor: StyleDescriptor) => void,
onCustomIconChange: (customIcons: CustomIcon[]) => void
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

change to onCustomIconsChange so its the same as in implementation and shows up in search results

@@ -32,6 +37,8 @@ interface StyleOptionChanges {
interface Props {
customIconStops?: IconStop[];
iconPaletteId: string | null;
customIcons: CustomIcon[];
onCustomIconsChange?: (customIcons: CustomIcon[]) => void;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Type as onCustomIconsChange: (customIcons: CustomIcon[]) => void;

onCustomIconsChange is passed to IconSelect which does not have a guard that onCustomIconsChange is undefined

onStaticStyleChange={this._onStaticStyleChange}
onDynamicStyleChange={this._onDynamicStyleChange}
onCustomIconsChange={this._onCustomIconsChange}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just make onCustomIconsChange={this.props.onCustomIconsChange} and remove _onCustomIconsChange

Copy link
Contributor

@nreese nreese left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM
This is a huge feature, thanks for putting together such a great enhancement. All the UIs look great and are easy to use and the icons look great on the map. Can't wait to see what users do with this.
code review, tested in chrome

@nickpeihl nickpeihl enabled auto-merge (squash) March 30, 2022 02:11
@nickpeihl nickpeihl added the backport:skip This commit does not require backporting label Mar 30, 2022
@kibana-ci
Copy link
Collaborator

💚 Build Succeeded

Metrics [docs]

Module Count

Fewer modules leads to a faster build time

id before after diff
maps 779 961 +182

Async chunks

Total size of all lazy-loaded chunks that will be downloaded as the user navigates the app

id before after diff
maps 2.5MB 2.6MB +86.0KB

Page load bundle

Size of the bundles that are downloaded on every page load. Target size is below 100kb

id before after diff
maps 69.3KB 69.7KB +387.0B
Unknown metric groups

ESLint disabled line counts

id before after diff
maps 37 38 +1

Total ESLint disabled count

id before after diff
maps 65 66 +1

History

To update your PR or re-run it, just comment with:
@elasticmachine merge upstream

@nickpeihl nickpeihl merged commit 118321f into elastic:main Mar 30, 2022
@nickpeihl nickpeihl deleted the maps-custom-icons branch March 30, 2022 04:20
@tylersmalley tylersmalley added ci:cloud-deploy Create or update a Cloud deployment and removed ci:deploy-cloud labels Aug 17, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
backport:skip This commit does not require backporting ci:cloud-deploy Create or update a Cloud deployment [Deprecated-Use Team:Presentation]Team:Geo Former Team Label for Geo Team. Now use Team:Presentation release_note:enhancement v8.2.0
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[Maps] Custom icons point styling
9 participants