Data-driven styling

FeatureLayer interface

google.maps.FeatureLayer interface

An interface representing a map layer containing features of a specificFeatureTypewhose style can be overridden client-side, or have events attached.

featureType
TheFeatureTypeassociated with thisFeatureLayer.
isAvailable
Type:boolean
Whether thisFeatureLayeris available, meaning whether Data-driven styling is available for this map (there is a map ID using vector tiles with thisFeatureLayerenabled in the Google Cloud Console map style.) If this is false (or becomes false), styling on thisFeatureLayerreturns to default and events are not triggered.
BetadatasetIdoptional
Type:stringoptional
The Dataset ID for thisFeatureLayer.Only present if thefeatureTypeisFeatureType.DATASET.
styleoptional
The style ofFeatures in theFeatureLayer.The style is applied when style is set. If your style function updates, you must set the style property again. AFeatureStyleFunctionmust return consistent results when it is applied over the map tiles, and should be optimized for performance. Asynchronous functions are not supported. If you use aFeatureStyleOptions,all features of that layer will be styled with the sameFeatureStyleOptions.Set the style tonullto remove the previously set style. If thisFeatureLayeris not available, setting style does nothing and logs an error.
addListener
addListener(eventName, handler)
Parameters:
  • eventName:stringObserved event.
  • handler:FunctionFunction to handle events.
Return Value:MapsEventListenerResulting event listener.
Adds the given listener function to the given event name. Returns an identifier for this listener that can be used withevent.removeListener.
click
function(event)
Arguments:
This event is fired when theFeatureLayeris clicked.
mousemove
function(event)
Arguments:
This event is fired when the user's mouse moves over theFeatureLayer.

FeatureType constants

google.maps.FeatureType constants

Identifiers for feature types.

Access by callingconst {FeatureType} = await google.maps.importLibrary( "maps" ).SeeLibraries in the Maps JavaScript API.

ADMINISTRATIVE_AREA_LEVEL_1 Indicates a first-order civil entity below the country level.
ADMINISTRATIVE_AREA_LEVEL_2 Indicates a second-order civil entity below the country level.
COUNTRY Indicates the national political entity.
BetaDATASET Indicates a third-party dataset.
LOCALITY Indicates an incorporated city or town political entity.
POSTAL_CODE Indicates a postal code as used to address postal mail within the country. Includes zip codes.
SCHOOL_DISTRICT Indicates a school district.

FeatureStyleFunction typedef

google.maps.FeatureStyleFunction typedef

A function to style aFeatureLayer.

function(FeatureStyleFunctionOptions): (FeatureStyleOptionsoptional)

FeatureStyleFunctionOptions interface

google.maps.FeatureStyleFunctionOptions interface

Options passed to aFeatureStyleFunction.

feature
Type:Feature
Featurepassed into theFeatureStyleFunctionfor styling.

FeatureStyleOptions interface

google.maps.FeatureStyleOptions interface

These options specify the way the style of aFeatureshould be modified on a map.

fillColoroptional
Type:stringoptional
Hex RGB string (like "#00FF00" for green). Only applies to polygon geometries.
fillOpacityoptional
Type:numberoptional
The fill opacity between 0.0 and 1.0. Only applies to polygon geometries.
strokeColoroptional
Type:stringoptional
Hex RGB string (like "#00FF00" for green).
strokeOpacityoptional
Type:numberoptional
The stroke opacity between 0.0 and 1.0. Only applies to line and polygon geometries.
strokeWeightoptional
Type:numberoptional
The stroke width in pixels. Only applies to line and polygon geometries.

Feature interface

google.maps.Feature interface

An interface representing a vector map tile feature. These are inputs to theFeatureStyleFunction.Do not save a reference to a particularFeatureobject because the reference will not be stable.

featureType
FeatureTypeof thisFeature.

PlaceFeature interface

google.maps.PlaceFeature interface

An interface representing a feature with a place ID which includes features of typeFeatureType.ADMINISTRATIVE_AREA_LEVEL_1,FeatureType.ADMINISTRATIVE_AREA_LEVEL_2,FeatureType.COUNTRY,FeatureType.LOCALITY,FeatureType.POSTAL_CODE,andFeatureType.SCHOOL_DISTRICT.

This interface extends Feature.

placeId
Type:string
Inherited: featureType
fetchPlace
fetchPlace()
Parameters:None
Return Value:Promise<Place>
Fetches aPlacefor thisPlaceFeature.In the resultingPlaceobject, theidand thedisplayNameproperties will be populated. The display name will be in the language the end user sees on the map. (Additional fields can be subsequently requested viaPlace.fetchFields()subject to normal Places API enablement and billing.) Do not call this from aFeatureStyleFunctionsince only synchronous FeatureStyleFunctions are supported. The promise is rejected if there was an error fetching thePlace.

DatasetFeature interface

google.maps.DatasetFeature interface

An interface representing a feature from a Dataset. ThefeatureTypeof aDatasetFeaturewill always beFeatureType.DATASET.

This interface extends Feature.

datasetAttributes
Type:Object<string, string>
Key-value mapping of the feature's attributes.
datasetId
Type:string
Dataset id of the dataset that this feature belongs to.
Inherited: featureType

FeatureMouseEvent interface

google.maps.FeatureMouseEvent interface

This object is returned from a mouse event on aFeatureLayer.

This interface extends MapMouseEvent.

features
TheFeatures at this mouse event.
Inherited: domEvent, latLng
Inherited: stop