Skip to main content

SvgSymbol

The SvgSymbol object represents an SVG symbol that can be used for a marker's icon or display on a polyline.

SvgSymbol extends Base.

Usage example

 const icon = G.svgSymbol({
path: 'M0,6a6,6 0 1,0 12,0a6,6 0 1,0 -12,0',
fillColor: '#5284ed',
fillOpacity: 1,
scale: 1,
strokeColor: '#5284ed',
strokeOpacity: 0.5,
strokeWeight: 4,
});

Creating the SvgSymbol object

G.svgSymbol(path?: SvgSymbolValue, options?: SvgSymbolOptions): SvgSymbol

There are a few ways to setup the SvgSymbol object.

No parameters.

G.svgSymbol()

const symbol = G.svgSymbol();

Pass the path only.

G.svgSymbol(path: string)

ParameterTypeRequiredDescription
pathstringYesThe SVG path for the icon.
const symbol = G.svgSymbol('M0,6a6,6 0 1,0 12,0a6,6 0 1,0 -12,0');

**Pass the path and the options.**

`G.svgSymbol(path: string, options: SvgSymbolOptions)`

| Parameter | Type | Required | Description |
|-----------|------|----------|-------------|
| path | string | Yes | The SVG path for the icon. |
| options | [SvgSymbolOptions](#svgsymbol-options) | Yes | The options for the SvgSymbol object. |

```js
const symbol = G.svgSymbol('M0,6a6,6 0 1,0 12,0a6,6 0 1,0 -12,0', {
fillColor: '#5284ed',
fillOpacity: 1,
scale: 1,
strokeColor: '#5284ed',
strokeOpacity: 0.5,
strokeWeight: 4,
});

Pass the options only.

G.svgSymbol(options: SvgSymbolOptions)

ParameterTypeRequiredDescription
optionsSvgSymbolOptionsYesThe options for the SvgSymbol object.
const symbol = G.svgSymbol({
path: 'M0,6a6,6 0 1,0 12,0a6,6 0 1,0 -12,0',
fillColor: '#5284ed',
fillOpacity: 1,
scale: 1,
strokeColor: '#5284ed',
strokeOpacity: 0.5,
strokeWeight: 4,
});

Pass an existing SvgSymbol object.

G.svgSymbol(object: SvgSymbol): SvgSymbol

In this case the SvgSymbol object is simply returned.

ParameterTypeRequiredDescription
objectSvgSymbolYesA SvgSymbol object.
const symbol = G.svgSymbol(symbolObject);

SvgSymbolValue type

When other objects accept a SvgSymbol value the value type that they accept is a SvgSymbolValue.

The SvgSymbolValue can be one of the following values:

  • An SvgSymbol object.
  • A string (The SVG path value).
  • An SvgSymbolOptions object.

SvgSymbol options

Type SvgSymbolOptions.

SvgSymbolOptions is an object containing the configuration options for the SvgSymbol object.

OptionTypeDefaultDescription
anchorPointValue[0, 0]The position of the symbol relative to the marker or polyline. By default, the anchor is located along the center point of the bottom of the image. This causes the SVG to appear off of the bottom right of the marker. Often you want to adjust the anchor so that the SVG is centered on the marker. The x value should be half the SVG width and the y value should be half the SVG height.
fillColorstring#000000The SVG fill color.
fillOpacitynumber1The opacity of the fill.
labelOriginPointValue[0, 0]The origin of the label relative to the origin of the path, if label is supplied by the marker. By default, the origin is located in the center point of the image.
pathstringThe SVG path for the icon. You cannot set the entire SVG code. Only use the path value of the SVG.
rotationnumber0The rotation of the icon in degrees clockwise about the anchor point.
scalenumber1The amount by which the icon is scaled.
strokeColorstring#000000The SVG stroke color.
strokeOpacitynumber1The opacity of the stroke.
strokeWeightnumberThe weight of the stroke.

Properties

PropertyTypeDescription
anchorPointThe position of the symbol relative to the marker or polyline.
fillColorstringThe SVG fill color.
fillOpacitynumberThe opacity of the fill.
labelOriginPointThe origin of the label relative to the origin of the path, if label is supplied by the marker.
pathstringThe SVG path.
rotationnumberThe rotation of the icon in degrees clockwise about the anchor point.
scalenumberThe amount by which the icon is scaled.
strokeColorstringThe SVG stroke color.
strokeOpacitynumberThe opacity of the stroke.
strokeWeightnumberThe weight of the stroke.

Examples:

symbol.anchor = [0, -10];
const anchor = symbol.anchor;

symbol.strokeColor = '#9E008B';

Methods

  • Methods inherited from Base.

setAnchor

setAnchor(anchor: PointValue): SvgSymbol

Set the position at which to anchor an image in correspondence to the location of the marker on the map.

OptionTypeRequiredDescription
anchorPointValueYesThe anchor value.
symbol.setAnchor([10, 32]);

setLabelOrigin

setLabelOrigin(labelOrigin: PointValue): SvgSymbol

Set the origin of the label relative to the top-left corner of the icon image, if a label is supplied by the marker.

OptionTypeRequiredDescription
labelOriginPointValueYesThe label origin value.
symbol.setAnchor([0, -2]);

setOptions

setOptions(options: SvgSymbolOptions): SvgSymbol

An alternate way to set one or more options.

OptionTypeRequiredDescription
optionsSvgSymbolOptionsYesThe options for the SvgSymbol object.
const symbol = G.svgSymbol('M0,6a6,6 0 1,0 12,0a6,6 0 1,0 -12,0').setOptions({
path: 'M0,6a6,6 0 1,0 12,0a6,6 0 1,0 -12,0',
fillColor: '#5284ed',
fillOpacity: 1,
scale: 1,
strokeColor: '#5284ed',
strokeOpacity: 0.5,
strokeWeight: 4,
});

setPath

setPath(path: string): SvgSymbol

Set the SVG path for the symbol.

OptionTypeRequiredDescription
pathstringYesThe SVG path.
symbol.setPath('M0,6a6,6 0 1,0 12,0a6,6 0 1,0 -12,0');

setRotation

setRotation(rotation: number): SvgSymbol

Set the rotation of the icon in degrees clockwise about the anchor point.

OptionTypeRequiredDescription
rotationnumberYesThe rotation value.
symbol.setRotation(45);

setScale

setScale(scale: number): SvgSymbol

Set the amount by which the icon is scaled.

OptionTypeRequiredDescription
scalenumberYesThe scale value.
symbol.setScale(3);

setStrokeColor

setStrokeColor(strokeColor: string): SvgSymbol

Set the SVG stroke color. All CSS3 colors are supported except for extended named colors.

OptionTypeRequiredDescription
strokeColorstringYesThe color value. All CSS3 colors are supported except for extended named colors.
symbol.setStrokeColor('#ff000');

setStrokeOpacity

setStrokeOpacity(strokeOpacity: number): SvgSymbol

Set the opacity of the stroke.

OptionTypeRequiredDescription
strokeOpacitynumberYesThe stroke opacity value.
symbol.setStrokeOpacity(0.5);

setStrokeWeight

setStrokeWeight(strokeWeight: number): SvgSymbol

Set the weight of the stroke.

OptionTypeRequiredDescription
strokeWeightnumberYesThe stroke weight value.
symbol.setStrokeWeight(2);

toGoogle

toGoogle(): Promise<google.maps.Symbol>

Get the icons in the format that the Google expects.

symbol.toGoogle().then((symbol) => {
const gmSymbol = symbol;
});