Data-driven styling

FeatureLayer 接口

google.maps.FeatureLayer 接口

一种接口,表示包含特定 FeatureType 的要素的地图图层,其样式可在客户端被替换,或附加了事件。

featureType
类型:  FeatureType
与此 FeatureLayer 关联的 FeatureType
isAvailable
类型:  boolean
FeatureLayer 是否可用,即相应地图是否支持数据驱动型样式设置(在 Google Cloud 控制台地图样式中,存在一个使用矢量图块且此 FeatureLayer 已启用的地图 ID)。如果此值为 false(或变为 false),则此 FeatureLayer 的样式会恢复为默认样式,并且不会触发任何事件。
BetadatasetId optional
类型:  string optional
相应 FeatureLayer 的数据集 ID。仅当 featureTypeFeatureType.DATASET 时才会存在。
style optional
FeatureLayerFeature 的样式。设置样式时应用样式。如果样式函数更新,您必须重新设置样式属性。FeatureStyleFunction 在应用于地图图块时必须返回一致的结果,并且应针对性能进行优化。不支持异步函数。如果您使用 FeatureStyleOptions,相应图层的所有要素都将采用相同的 FeatureStyleOptions 样式。将样式设置为 null 可移除之前设置的样式。如果此 FeatureLayer 不可用,则设置样式不会执行任何操作,并会记录错误。
addListener
addListener(eventName, handler)
参数: 
  • eventNamestring观测到的事件。
  • handlerFunction 用于处理事件的函数。
返回值:生成的事件监听器。MapsEventListener
将给定的监听器函数添加到给定的事件名称。返回此监听器的标识符,该标识符可与 event.removeListener 搭配使用。
click
function(event)
实参: 
点击 FeatureLayer 时会触发此事件。
mousemove
function(event)
实参: 
当用户的鼠标移到 FeatureLayer 上时,系统会触发此事件。

FeatureType 常量

google.maps.FeatureType 常量

功能类型的标识符。

通过调用 const {FeatureType} = await google.maps.importLibrary("maps") 进行访问。
请参阅 Maps JavaScript API 中的库

ADMINISTRATIVE_AREA_LEVEL_1 表示国家/地区级别以下的一级行政实体。
ADMINISTRATIVE_AREA_LEVEL_2 表示国家/地区级别以下的二级行政实体。
COUNTRY 表示国家政治实体。
BetaDATASET 表示第三方数据集。
LOCALITY 表示有建制的城市或城镇政治实体。
POSTAL_CODE 表示国家/地区内邮寄地址所用的邮政编码。包括邮政编码。
SCHOOL_DISTRICT 表示学区。

FeatureStyleFunction typedef

google.maps.FeatureStyleFunction typedef

用于设置 FeatureLayer 样式的函数。

function(FeatureStyleFunctionOptions): (FeatureStyleOptions optional)

FeatureStyleFunctionOptions 接口

google.maps.FeatureStyleFunctionOptions 接口

传递给 FeatureStyleFunction 的选项。

feature
类型:  Feature
Feature 传递到 FeatureStyleFunction 以设置样式。

FeatureStyleOptions 接口

google.maps.FeatureStyleOptions 接口

这些选项用于指定应如何在地图上修改 Feature 的样式。

fillColor optional
类型:  string optional
十六进制 RGB 字符串(例如“#00FF00”表示绿色)。仅适用于多边形几何图形。
fillOpacity optional
类型:  number optional
介于 0.0 和 1.0 之间的填充不透明度。仅适用于多边形几何图形。
strokeColor optional
类型:  string optional
十六进制 RGB 字符串(例如“#00FF00”表示绿色)。
strokeOpacity optional
类型:  number optional
描边不透明度,介于 0.0 和 1.0 之间。仅适用于线和多边形几何图形。
strokeWeight optional
类型:  number optional
描边宽度(以像素为单位)。仅适用于线和多边形几何图形。

功能接口

google.maps.Feature 接口

表示矢量地图图块功能的接口。这些是 FeatureStyleFunction 的输入。请勿保存对特定 Feature 对象的引用,因为该引用不稳定。

featureType
类型:  FeatureType
相应 FeatureFeatureType

PlaceFeature 接口

google.maps.PlaceFeature 接口

一种接口,表示具有地点 ID 的功能,其中包括类型为 FeatureType.ADMINISTRATIVE_AREA_LEVEL_1FeatureType.ADMINISTRATIVE_AREA_LEVEL_2FeatureType.COUNTRYFeatureType.LOCALITYFeatureType.POSTAL_CODEFeatureType.SCHOOL_DISTRICT 的功能。

此接口扩展了 Feature

placeId
类型:  string
继承自featureType
fetchPlace
fetchPlace()
参数:无
返回值:  Promise<Place>
为相应 PlaceFeature 获取 Place。在生成的 Place 对象中,iddisplayName 属性将被填充。显示名称将采用最终用户在地图上看到的语言。(后续可以通过 Place.fetchFields() 请求其他字段,但需启用 Places API 并支付相应费用。)请勿从 FeatureStyleFunction 调用此函数,因为仅支持同步 FeatureStyleFunction。如果提取 Place 时出错,则拒绝相应 promise。

DatasetFeature 接口

google.maps.DatasetFeature 接口

表示数据集中的一项特征的接口。DatasetFeaturefeatureType 将始终为 FeatureType.DATASET

此接口扩展了 Feature

datasetAttributes
类型:  Object<string, string>
相应功能的属性的键值对映射。
datasetId
类型:  string
相应功能所属的数据集的 ID。
继承自featureType

FeatureMouseEvent 接口

google.maps.FeatureMouseEvent 接口

此对象是从 FeatureLayer 上的鼠标事件返回的。

此接口扩展了 MapMouseEvent

features
类型:  Array<Feature>
相应鼠标事件的 Feature
继承自domEventlatLng
继承自stop