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)

ParameterTypeRequiredDescription
pathstringYesThe SVG path for the icon.
optionsSvgSymbolOptionsYesThe options for the SvgSymbol object.
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:

The SvgSymbolValue type is used by the PolylineIcon icon option and the Marker svgIcon option. Note that the Marker svgIcon option treats a string value as the full SVG code rather than a path, so use an SvgSymbol object or an SvgSymbolOptions object if you only have the path.

// SvgSymbol object
const symbolObject = G.svgSymbol({path: 'M0,6a6,6 0 1,0 12,0a6,6 0 1,0 -12,0', fillColor: '#5284ed'});

// String path value
const pathString = 'M0,6a6,6 0 1,0 12,0a6,6 0 1,0 -12,0';

// SvgSymbolOptions object
const symbolOptions = {
path: G.SymbolPath.CIRCLE,
fillColor: '#5284ed',
fillOpacity: 1,
scale: 6,
};

SvgSymbol options​

Type SvgSymbolOptions.

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

The path option is required when passing an SvgSymbolOptions object. All other options are optional.

The number options (fillOpacity, rotation, scale, strokeOpacity, and strokeWeight) also accept a number string, like '0.5'. It's converted to a number.

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.
pathstringRequired. The SVG path for the icon. You cannot set the entire SVG code. Only use the path value of the SVG. You can also use one of the SymbolPath constants, like G.SymbolPath.CIRCLE.
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. All CSS3 colors are supported except for extended named colors.
strokeOpacitynumber1The opacity of the stroke, where 0 is fully transparent and 1 is fully opaque.
strokeWeightnumberThe weight of the stroke in pixels.

Properties​

All the properties can be read and set. The number properties (fillOpacity, rotation, scale, strokeOpacity, and strokeWeight) can be set with a number or a number string, and are always returned as a number.

PropertyTypeDescription
anchorPointValueThe position of the symbol relative to the marker or polyline. It's returned as a Point object.
fillColorstringThe SVG fill color.
fillOpacitynumber|stringThe opacity of the fill.
labelOriginPointValueThe origin of the label relative to the origin of the path, if label is supplied by the marker.
pathstringThe SVG path, or one of the SymbolPath constants.
rotationnumber|stringThe rotation of the icon in degrees clockwise about the anchor point.
scalenumber|stringThe amount by which the icon is scaled.
strokeColorstringThe SVG stroke color.
strokeOpacitynumber|stringThe opacity of the stroke.
strokeWeightnumber|stringThe 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.

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

setFillColor​

setFillColor(fillColor: string): SvgSymbol

Set the SVG fill color.

ParameterTypeRequiredDescription
fillColorstringYesThe fill color value.
symbol.setFillColor('#5284ed');

setFillOpacity​

setFillOpacity(fillOpacity: number|string): SvgSymbol

Set the opacity of the fill.

ParameterTypeRequiredDescription
fillOpacitynumber|stringYesThe fill opacity value. A number string is converted to a number.
symbol.setFillOpacity(0.5);

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.

ParameterTypeRequiredDescription
labelOriginPointValueYesThe label origin value.
symbol.setLabelOrigin([0, -2]);

setOptions​

setOptions(options: SvgSymbolOptions): SvgSymbol

An alternate way to set one or more options.

ParameterTypeRequiredDescription
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.

ParameterTypeRequiredDescription
pathstringYesThe SVG path, or one of the SymbolPath constants.
symbol.setPath('M0,6a6,6 0 1,0 12,0a6,6 0 1,0 -12,0');
symbol.setPath(G.SymbolPath.CIRCLE);

setRotation​

setRotation(rotation: number|string): SvgSymbol

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

ParameterTypeRequiredDescription
rotationnumber|stringYesThe rotation value. A number string is converted to a number.
symbol.setRotation(45);

setScale​

setScale(scale: number|string): SvgSymbol

Set the amount by which the icon is scaled.

ParameterTypeRequiredDescription
scalenumber|stringYesThe scale value. A number string is converted to a number.
symbol.setScale(3);

setStrokeColor​

setStrokeColor(strokeColor: string): SvgSymbol

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

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

setStrokeOpacity​

setStrokeOpacity(strokeOpacity: number|string): SvgSymbol

Set the opacity of the stroke.

ParameterTypeRequiredDescription
strokeOpacitynumber|stringYesThe stroke opacity value. A number string is converted to a number.
symbol.setStrokeOpacity(0.5);

setStrokeWeight​

setStrokeWeight(strokeWeight: number|string): SvgSymbol

Set the weight of the stroke.

ParameterTypeRequiredDescription
strokeWeightnumber|stringYesThe stroke weight value. A number string is converted to a number.
symbol.setStrokeWeight(2);

toGoogle​

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

Get the symbol in the format that Google expects. It will be a promise value because it waits for the Google Maps library to load. If the path is one of the SymbolPath constants then it's converted to the matching google.maps.SymbolPath value.

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