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
Parameter | Type | Required | Description |
---|---|---|---|
width | number | Yes | The width value. |
height | number | Yes | The height value. |
const size = G.size(15, 30);
Pass the width and height values as an array.
G.size([width: number, height: number]): Size
Parameter | Type | Required | Description |
---|---|---|---|
value | Array | Yes | An 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
Parameter | Type | Required | Description |
---|---|---|---|
value | object | Yes | An 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.
Parameter | Type | Required | Description |
---|---|---|---|
sizeObj | Size | Yes | A 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, theheight
value should also be set. For example:3
. - A string for the
width
value that is a number. In this case, theheight
value should also be set. For example:'3'
. - An array where the first value is the
width
value and the second value is theheight
value. For example:- Numbers:
[3, 10]
- Strings:
['3', '10']
- Mixed values:
[3, '10']
- Numbers:
- An object setting the
width
andheight
values. For example:- Numbers:
{width: 3, height: 10}
- Strings:
{width: '3', height: '10'}
- Mixed:
{width: '3', height: 10}
- Numbers:
- A Size object.
Properties
Property | Type | Description |
---|---|---|
height | number | The height value |
width | number | The 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
Parameter | Type | Required | Description |
---|---|---|---|
width | SizeValue | Yes | The width value, array of width/height values, or an object containing the width/height values |
height | number | The 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)
Parameter | Type | Required | Description |
---|---|---|---|
width | number | Yes | The width value. |
height | number | Yes | The height value. |
size.set(15, 30);
size.set([width: number, height: number])
Parameter | Type | Required | Description |
---|---|---|---|
value | Array | Yes | An array containing the width and height values |
size.set([15, 30]);
size.set({width: width: number, height: height: number})
Parameter | Type | Required | Description |
---|---|---|---|
value | object | Yes | An object containing the width and height values |
size.set({width: 15, height: 30});
size.set(sizeObj: Size)
Parameter | Type | Required | Description |
---|---|---|---|
sizeObj | Size | Yes | A 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.
Parameter | Type | Required | Description |
---|---|---|---|
height | number | Yes | The 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.
Parameter | Type | Required | Description |
---|---|---|---|
width | number | Yes | The 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();