Mapbox Style Specification—Feature data、Lookup、Decision

Feature data

feature-state

从当前要素状态中获取属性值,如果请求属性不在要素的属性状态中,则返回null。一个要素的状态不是Geojson或者矢量瓦片数据的一部分,而是以编程的方式在每个要素中设置。注意feature-state仅仅能被使用在paint属性支持data-driven样式中。

["feature-state", string]: value

geometry-type

获取要素的几何类型:点、多点、线、多线、面、多面

["geometry-type"]: string

id

获取要素的id,如果有id的话

["id"]: value

properties

获取要素属性对象,注意在有些情况下,直接使用 ["get", "property_name"] 更有效率。

["properties"]: object

Lookup

at

从数组中取回一项

["at", number, array]: ItemType

get

从当前要素的属性中取回一个合适的值,如果提供了其他参数,也可以从其中获取属性值,如果请求的属性没有的话,返回null。

["get", string]: value
["get", string, object]: value

has

用于测试一个要素属性中是否有某一个属性,如果有第二个参数,就从第二个参数中去取。

["has", string]: boolean
["has", string, object]: boolean

length

获取一个数组或字符串的长度

["length", string | array | value]: number

Decision

本章节的表达式是用来在你的样式中添加逻辑判断条件,例如case表达式提供基础的if then else逻辑,match表达式允许你从一个输入表达式的值来匹配输出表达式的值。

!

逻辑否,输入为ture时返回false,输入为false时返回true

["!", boolean]: boolean

!=

如果不等于返回true,否则返回false。比较严格限制类型:运行时不同类型通常被认为不相等。当在解析时发现类型不同时,会报错。可以接收一个collator参数来控制字符串比较规则。

["!=", value, value]: boolean
["!=", value, value, collator]: boolean

<

如果第一个值小于第二个返回true,否则返回false。参数要求两个都为数值或者字符串。如果在运算期间发现不是字符串或数值,就报错。可以接收一个collator参数来控制字符串比较规则。

["<", value, value]: boolean
["<", value, value, collator]: boolean

<===>>=都同上类似,不细说了。

all

如果都为true,则返回true,否则返回false。计算的时候会按顺序计算,一旦发现计算值为false,则返回false,且后面不在计算。

["all", boolean, boolean]: boolean
["all", boolean, boolean, ...]: boolean

any

如果有一个为true,返回true,否则返回false。同上,一旦发现计算值为true,返回true,后面不再计算。

["any", boolean, boolean]: boolean
["any", boolean, boolean, ...]: boolean

case

类似编译语言中switch case结构,一旦满足case的条件,返回此case的值。

["case",
    condition: boolean, output: OutputType, condition: boolean, output: OutputType, ...,
    default: OutputType
]: OutputType

coalesce

连接各个表达式,直到获取到第一个非空值为止,返回这个值。

["coalesce", OutputType, OutputType, ...]: OutputType

match

选择输入值与标签值相匹配的的输出值,如果匹配不到,返回默认值。输入可以是任何一个表达式(e.g. ["get", "building_type"])。每个标签必须是一个单独合法的值或者合法的数列(e.g. "a" or ["c", "b"])。这些值必须全是字符串或者数值,在同一个表达式中1和“1”不能同时作为标签,如果输入值不匹配任何一个标签值,结果返回默认值

["match",
    input: InputType (number or string),
    label_1: InputType | [InputType, InputType, ...], output_1: OutputType,
    label_n: InputType | [InputType, InputType, ...], output_n: OutputType, ...,
    default: OutputType
]: OutputType
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值