Skip to main content

Size

The Size object represents the height and width of an element.

Size extends Base.

Some example usages include:

  • Setting the size of a marker icon.
  • Setting the offset for an InfoWindow.

Usage example

const size = G.size(15, 30)

Creating the Size object

G.size(width?: SizeValue, height?: number | string): Size

There are a few ways to setup the Size object.

No parameters.

G.size(): Size

const size = G.size();

Pass the width and height values.

G.size(width: number, height: number): Size

ParameterTypeRequiredDescription
widthnumberYesThe width value.
heightnumberYesThe height value.
const size = G.size(15, 30);

Pass the width and height values as an array.

G.size([width: number, height: number]): Size

ParameterTypeRequiredDescription
valueArrayYesAn array containing the width and height values
const size = G.size([15, 30]);

Pass the width and height values as an object.

G.size({width: width: number, height: height: number}): Size

ParameterTypeRequiredDescription
valueobjectYesAn object containing the width and height values
const size = G.size({width: 15, height: 30});

Pass an existing Size object.

G.size(sizeObj: Size): Size

In this case the Size object is simply returned.

ParameterTypeRequiredDescription
sizeObjSizeYesA Size object.
const size = G.size(sizeObject);

SizeValue type

The G.size() function and other methods that accept the width/height size values accept a SizeValue as the width value.

The SizeValue can be one of the following values:

  • A number for the width value. In this case, the height value should also be set. For example: 3.
  • A string for the width value that is a number. In this case, the height value should also be set. For example: '3'.
  • An array where the first value is the width value and the second value is the height value. For example:
    • Numbers: [3, 10]
    • Strings: ['3', '10']
    • Mixed values: [3, '10']
  • An object setting the width and height values. For example:
    • Numbers: {width: 3, height: 10}
    • Strings: {width: '3', height: '10'}
    • Mixed: {width: '3', height: 10}
  • A Size object.

Properties

PropertyTypeDescription
heightnumberThe height value
widthnumberThe width value
size.height = 30;
const height = size.height;

size.width = '45';
const width = size.width;

Methods

  • Methods inherited from Base.

clone

clone(): Size

Clones the Size object and returns a new one.

const clone = size.clone();

getHeight

getHeight(): number

Get the y value.

const height = size.getHeight();

getWidth

getWidth(): number

Get the width value.

const width = size.getWidth();

isValid

isValid(): boolean

Returns whether the width/height pair is a valid value.

if (size.isValid()) {
// Do something here
}

set

set(width: SizeValue, height?: number): Size

ParameterTypeRequiredDescription
widthSizeValueYesThe width value, array of width/height values, or an object containing the width/height values
heightnumberThe height value. Only set if the width value is set as a number.

Set the width and height values. This accepts the values in the following ways:

size.set(width: number, height: number)

ParameterTypeRequiredDescription
widthnumberYesThe width value.
heightnumberYesThe height value.
size.set(15, 30);

size.set([width: number, height: number])

ParameterTypeRequiredDescription
valueArrayYesAn array containing the width and height values
size.set([15, 30]);

size.set({width: width: number, height: height: number})

ParameterTypeRequiredDescription
valueobjectYesAn object containing the width and height values
size.set({width: 15, height: 30});

size.set(sizeObj: Size)

ParameterTypeRequiredDescription
sizeObjSizeYesA Size object. In this case the width and height values from the object are used.
size.set(sizeObject);

setHeight

setHeight(height: number): Size

Set the height value. Use this if you want to change the height value after the object is created.

ParameterTypeRequiredDescription
heightnumberYesThe height value.
size.setHeight(30);

setWidth

setWidth(width: number): Size

Set the width value. Use this if you want to change the width value after the object is created.

ParameterTypeRequiredDescription
widthnumberYesThe width value.
size.setWidth(15);

toGoogle

toGoogle(): google.maps.Size|null

Get the Google Maps Size object. null is only returned if the Google maps library hasn't loaded yet.

const gmSize = size.toGoogle();