-
Notifications
You must be signed in to change notification settings - Fork 8.3k
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
Conversation
* 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)
💔 Build Failed
Failed CI StepsMetrics [docs]
History
To update your PR or re-run it, just comment with: |
* 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?
customIcons, | ||
}) { | ||
return iconStops.map(({ stop, icon, iconSource }, index) => { | ||
const { svg, label } = |
There was a problem hiding this comment.
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[]; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
type as customIcons: CustomIcon[];
There was a problem hiding this comment.
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; |
There was a problem hiding this comment.
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;
There was a problem hiding this comment.
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
.
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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) { |
There was a problem hiding this comment.
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 } : {}; |
There was a problem hiding this comment.
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; |
There was a problem hiding this comment.
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
iconSource === ICON_SOURCE.CUSTOM | ||
? customIcons.find(({ symbolId }) => symbolId === icon) | ||
: getMakiSymbol(icon); | ||
if (!iconInfo) return; |
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
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; |
There was a problem hiding this comment.
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} |
There was a problem hiding this comment.
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
There was a problem hiding this 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
💚 Build SucceededMetrics [docs]Module Count
Async chunks
Page load bundle
Unknown metric groupsESLint disabled line counts
Total ESLint disabled count
History
To update your PR or re-run it, just comment with: |
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:
For maintainers