Skip to main content

MapTypeControl

The MapTypeControl object is used to configure the Map Type control on the map.

You can change the position, the map types to use, and the display of the map type control.

See the Map Controls guide page for more information.

Example usage

const mapTypeControl = G.mapTypeControl({
mapTypeIds: [G.MapTypeId.ROADMAP, G.MapTypeId.TERRAIN],
position: G.ControlPosition.TOP_CENTER,
style: G.MapTypeControlStyle.DROPDOWN_MENU,
});

const map = G.map('map', {
center: [40.7128, -74.0060],
mapTypeControl: mapTypeControl,
});

Creating the MapTypeControl object

G.mapTypeControl(options?: MapTypeControlValue): MapTypeControl

There are a few ways to setup the MapTypeControl object.

Pass no value.

G.mapTypeControl(): MapTypeControl

const control = G.mapTypeControl();
control.satellite = false;
control.position = G.ControlPosition.TOP_CENTER;

Pass a boolean value to disable the Map Type control.

G.mapTypeControl(value: boolean): MapTypeControl

ParameterTypeRequiredDescription
valuebooleanYesWhether to enable the Map Type control.

If you pass a false value to the mapTypeControl method then that will disable and hide the Map Type control when this is associated with a map.

const control = G.mapTypeControl(false);

Pass an object of options.

G.mapTypeControl(options: MapTypeControlOptions): MapTypeControl

ParameterTypeRequiredDescription
optionsMapTypeControlOptionsYesThe configuration options.
const mapTypeControl = G.mapTypeControl({
mapTypeIds: [G.MapTypeId.ROADMAP, G.MapTypeId.TERRAIN],
position: G.ControlPosition.TOP_CENTER,
style: G.MapTypeControlStyle.DROPDOWN_MENU,
});

Pass an existing MapTypeControl object.

G.mapTypeControl(value: MapTypeControl): MapTypeControl

ParameterTypeRequiredDescription
valueMapTypeControlYesThe existing MapTypeControl object.
const control = G.mapTypeControl(existingMapTypeControlObject);

Map Type Control options

Type MapTypeControlOptions.

MapTypeControlOptions is an object containing the configuration options for the MapTypeControl object.

OptionTypeDefaultDescription
enabledbooleantrueWhether the Map Type control is enabled and will display on the map.
mapTypeIdsMapTypeId[][ROADMAP, SATELLITE, HYBRID, TERRAIN]The map types to use.
positionControlPositionBLOCK_START_INLINE_STARTThe display position of the control.
styleMapTypeControlStyleDEFAULTThe style of the control.

Properties

PropertyTypeDescription
enabledbooleanWhether the Map Type control is enabled and will display on the map.
hybridbooleanWhether the hybrid map type is used.
positionControlPositionThe display position of the control.
roadmapbooleanWhether the roadmap map type is used.
satellitebooleanWhether the satellite map type is used.
styleMapTypeControlStyleThe style of the control.
terrainbooleanWhether the terrain map type is used.

The hybrid, roadmap, satellite, and terrain properties give you an alternate way to turn on and off individual map types.

// Turn the roadmap map type off
control.roadmap = false;

Methods

disable

disable(): MapTypeControl

Disables and hides the Map Type control.

control.disable();

enable

enable(): MapTypeControl

Enables and shows the Map Type control.

control.enable();

hasMapType

hasMapType(mapTypeId: MapTypeIdValue): boolean

Returns whether the passed map type is one of the map types that are enabled for the Map Type control.

ParameterTypeRequiredDescription
mapTypeIdMapTypeId[]YesOne of the map type ids to test.
if (control.hasMapType(G.MapTypeId.HYBRID)) {
// Do something
}

setMapTypeIds

setMapTypeIds(mapTypeIds: MapTypeId[]): MapTypeControl

Set the map type ids to include in the control.

ParameterTypeRequiredDescription
mapTypeIdsMapTypeId[]YesThe map types to use.
control.setMapTypeIds([
G.MapTypeId.HYBRID,
G.MapTypeId.TERRAIN
]);

setPosition

setPosition(position: ControlPosition): MapTypeControl

Set the display position of the control on the map.

ParameterTypeRequiredDescription
positionControlPositionYesThe display position of the control.
control.setPosition(G.ControlPosition.BLOCK_END_INLINE_START)

setStyle

setStyle(style: MapTypeControlStyleValue): MapTypeControl

Set the style of the control.

ParameterTypeRequiredDescription
mapTypeIdsMapTypeControlStyleYesThe style of the control.
control.setStyle(G.MapTypeControlStyle.DROPDOWN_MENU);

toGoogle

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

Get the object to use to pass the MapTypeControl options to the Google Map instance.

control.toGoogle().then((options) => {
// Do something with the options
});