Data-driven styling

FeatureLayer 接口

google.maps.FeatureLayer 接口

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

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

FeatureType 常量

google.maps.FeatureType 常量
库 "maps"

地图项类型的标识符。

这些常量也可以用作字符串。在 TypeScript 中,字符串字面量由 FeatureTypeString 类型定义。

const {FeatureType} = await google.maps.importLibrary("maps");
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
可选
类型:string optional
十六进制 RGB 字符串(例如“#00FF00”表示绿色)。仅适用于多边形几何图形。
fillOpacity
可选
类型:number optional
填充不透明度介于 0.0 和 1.0 之间。仅适用于多边形几何图形。
strokeColor
可选
类型:string optional
十六进制 RGB 字符串(例如“#00FF00”表示绿色)。
strokeOpacity
可选
类型:number optional
描边不透明度介于 0.0 和 1.0 之间。仅适用于线和多边形几何图形。
strokeWeight
可选
类型:number optional
描边宽度(以像素为单位)。仅适用于线和多边形几何图形。

Feature 接口

google.maps.Feature 接口

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

featureType
类型:FeatureType
FeatureType(共 Feature 个)。

PlaceFeature 接口

google.maps.PlaceFeature interface
extends Feature

一个表示具有地点 ID 的地图项的接口,包括 FeatureType.ADMINISTRATIVE_AREA_LEVEL_1、FeatureType.ADMINISTRATIVE_AREA_LEVEL_2、FeatureType.COUNTRY、FeatureType.LOCALITY、FeatureType.POSTAL_CODE 和 FeatureType.SCHOOL_DISTRICT 类型的地图项。

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

DatasetFeature 接口

google.maps.DatasetFeature interface
extends Feature

表示数据集中的特征的接口。DatasetFeature 的 featureType 始终为 FeatureType.DATASET。

datasetAttributes
类型:Object<string, string>
特征属性的键值对映射。
datasetId
类型:string
此特征所属数据集的数据集 ID。
继承: featureType

FeatureMouseEvent 接口

google.maps.FeatureMouseEvent interface
extends MapMouseEvent

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

features
类型:Array<Feature>
此鼠标事件中的 Feature。
继承的方法: domEvent、latLng
继承: stop