文章目录

  • 表达式参考
    • Decision 判定操作符
      • !, !=, <, <=, ==, >, >=(高频率使用)
      • all 逻辑与(高频率使用)
      • any 逻辑或
      • case 条件 (高频率使用)
      • match (高频率使用)
    • Ramps, scales, curves
      • interpolate(高频率使用)
      • step(高频率使用)
    • String 字符串类型操作符
      • concat
      • downcase
      • upcase

表达式参考

Decision 判定操作符

!, !=, <, <=, ==, >, >=(高频率使用)

// 语法
["!", boolean]: boolean
["!=", value, value]: boolean
["<", value, value]: boolean
["<=", value, value]: boolean
["==", value, value]: boolean
[">", value, value]: boolean
[">=", value, value]: boolean

all 逻辑与(高频率使用)

如果所有输入都为真则返回真,否则返回假。输入按顺序求值,并且求值是短路的:一旦输入表达式求值为false,则结果为false,不再求输入表达式。

// 语法
["all", boolean, boolean]: boolean
'filter': ['all',['==', 'extrude', 'true'],['>', 'height', i * binWidth],['<=', 'height', (i + 1) * binWidth]
],

常用于图层过滤。

any 逻辑或

如果任何输入为真则返回真,否则返回假。输入按顺序求值,并且求值是短路的:一旦输入表达式求值为true,则结果为true,不再求输入表达式。

// 语法
["any", boolean, boolean]: boolean

case 条件 (高频率使用)

选择第一个对应的条件计算为true的输出,或者选择默认值。

// 语法
["case",condition: boolean, output: OutputType,condition: boolean, output: OutputType,...,fallback: OutputType
]: OutputType
'paint': {'fill-opacity': ['case',['boolean', ['feature-state', 'hover'], false],1,0.5]
}

match (高频率使用)

选择标签值与输入值匹配的输出,如果未找到匹配,则选择默认值。输入可以是任何表达式(例如[“get”, “building_type”])。每个标签必须是:

  • 单个字符串
  • 字符串数组,其值必须是所有字符串或所有数字(例如[100,101]或[“c”, “b”])。如果数组中的任何值匹配,则输入匹配,类似于“in”操作符。每个标签必须是唯一的。如果输入类型与标签类型不匹配,则结果将是默认值。
// 语法
["match",input: InputType (number or string),label: InputType | [InputType, InputType, ...], output: OutputType,label: InputType | [InputType, InputType, ...], output: OutputType,...,fallback: OutputType
]: OutputType
// 单个字符串
'paint': {'circle-color': ['match',['get', 'ethnicity'],'White','#fbb03b','Black','#223b53','Hispanic','#e55e5e','Asian','#3bb2d0',/* other */ '#ccc']
}
// 数组
map.setFilter('airport', ['match',['get', 'abbrev'],filtered.map(function (feature) {return feature.properties.abbrev;}),true,false
]);

Ramps, scales, curves

interpolate(高频率使用)

通过插值输入和输出值对(“停止”)产生连续的、平滑的结果。输入可以是任何数字表达式(例如,["get", "population"])。停止输入必须是严格升序的数字。输出类型必须为numberarray<number>color
插值类型:

  • ["linear"]: 在略小于或大于输入的两个端点之间进行线性内插。
  • ["exponential", base]: 在两个端点之间进行指数插值,略大于或小于输入值。base控制输出增加的速率:值越高,输出越接近范围的高端。当值接近1时,输出线性增加。
  • ["cubic-bezier", x1, y1, x2, y2]: 使用由给定控制点定义的三次贝塞尔曲线进行插值。
// 语法
["interpolate",interpolation: ["linear"] | ["exponential", base] | ["cubic-bezier", x1, y1, x2, y2],input: number,stop_input_1: number, stop_output_1: OutputType,stop_input_n: number, stop_output_n: OutputType, ...
]: OutputType (number, array<number>, or Color)
// 线性插值
'paint': {// use an 'interpolate' expression to add a smooth transition effect to the// buildings as the user zooms in'fill-extrusion-height': ['interpolate',['linear'],['zoom'],15,0,15.05,['get', 'height']],'fill-extrusion-base': ['interpolate',['linear'],['zoom'],15,0,15.05,['get', 'min_height']],
}
// 指数插值
map.setPaintProperty('building', 'fill-color', ['interpolate',['exponential', 0.5],['zoom'],15,'#e2714b',22,'#eee695'
]);

step(高频率使用)

通过计算由输入和输出值(“停止”)对定义的分段常数函数,产生离散的、阶梯式的结果。输入可以是任何数字表达式(例如,["get", "population"])。停止输入必须是严格升序的数字文字。返回仅小于输入的stop的输出值,如果输入小于第一个stop,则返回第一个输出值。

// 语法
["step",input: number,stop_output_0: OutputType,stop_input_1: number, stop_output_1: OutputType,stop_input_n: number, stop_output_n: OutputType, ...
]: OutputType
paint: {// 小于100时,circles的颜色为Blue, 大小为20px // 大于等于100且小于750之间时,circles的颜色为Yellow, 大小为30px(左闭右开区间)// 大于等于750时,circles的颜色为Pink, 大小为40px 'circle-color': ['step',['get', 'point_count'],'#51bbd6',100,'#f1f075',750,'#f28cb1'],'circle-radius': ['step',['get', 'point_count'],20,100,30,750,40]
}

String 字符串类型操作符

concat

连接字符串。

// 语法
["concat", value, value, ...]: string
'layout': {'icon-image': ['concat', 'square-rgb-', ['get', 'color']]
}

downcase

返回转换为小写的输入字符串。

// 语法
["downcase", string]: string

upcase

返回转换为大写的输入字符串。

// 语法
["upcase", string]: string
'layout': {'text-field': ['format',['upcase', ['get', 'FacilityName']],{ 'font-scale': 0.8 },'\n',{},['downcase', ['get', 'Comments']],{ 'font-scale': 0.6 }],
}

Mapbox常用表达式整理(3)相关推荐

  1. execution常用表达式整理

    2021年3月10日 学习产出: 整理execution表达式 避免以后忘记 execution(修饰符? 返回值 包名 类名 方法名 (参数)) 访问修饰符:可写可不写,不写代表可以匹配所有修饰符 ...

  2. mysql数据库 常用函数_《MySQL数据库》常用函数整理

    原标题:<MySQL数据库>常用函数整理 以下内容,是我整理出来的比较常用的字符串函数,数值函数,日期函数. 第一类:字符串函数 1.conv(n,from_base,to_base):对 ...

  3. Linux 常用命令整理(Centos7) (时区/正则/sed/htop/screen/ln/awk/……)

    目录 Linux 常用命令整理(Centos7) (附加正则.时区.git等) 一.系统查询常用命令: 1.文件中空格制表符替换sed 2.查看宿主机的用户名密码 3.last .w.lastb 查看 ...

  4. 【电赛】电设校赛常用电路整理

    电设校赛常用电路整理 写在前面 引用与致谢 单电源供电集成运放 电压比较器 单限比较器 过零比较器 改进:限制幅度和设置偏置 滞回比较器 窗口比较器 波形发生与变换 正弦波 RC正弦振荡电路 LC正弦 ...

  5. lldb 常用命令整理

    lldb 常用命令整理 -- 飘云 推荐一个不用下载就可以玩app游戏的网站,http://h5-apps.com,更新速度绝对最快,真爽啊 lldb命令支持缩写,自己慢慢研究吧 优雅人生飘云原创整理 ...

  6. oracle有哪些常用函数,Oracle常用函数整理

    点击关注上方"SQL数据库开发", 设为"置顶或星标",第一时间送达干货 之前已经给小伙伴们整理了SQL Server和Mysql的常用函数,还没有看的可以戳下 ...

  7. [JAVAEE] Thymeleaf 基本语法:常用表达式

    Thymeleaf 基本语法 常用表达式 变量表达式 ${ } 使用方法:th:xx = "${ }" 获取对象属性值给 th:xx . 后台代码: Student s=new S ...

  8. python常用命令汇总-python数据分析之pandas常用命令整理

    原标题:python数据分析之pandas常用命令整理 pandas 是基于NumPy 的一种工具,该工具是为了解决数据分析任务而创建的.Pandas 纳入了大量库和一些标准的数据模型 ,提供了高效地 ...

  9. 【Android 插件化】Hook 插件化框架 ( 反射工具类 | 反射常用操作整理 )

    Android 插件化系列文章目录 [Android 插件化]插件化简介 ( 组件化与插件化 ) [Android 插件化]插件化原理 ( JVM 内存数据 | 类加载流程 ) [Android 插件 ...

最新文章

  1. 千里之行,始于足下。职场人士必读的寓言
  2. C++实现顺序查找(附完整源码)
  3. Python、Java、C#、Perl 创始人聚首,编程语言要变天?
  4. 数据挖掘:探索性数据分析(EDA)(补充)
  5. numpy教程:数组操作
  6. HTML图片热点及表单
  7. 【评论】第一财经周刊:失败的埃洛普
  8. 基于Android的Word在线预览
  9. ASLD 高级固体激光器设计及仿真软件
  10. .net web 开发平台- 表单设计器 一(web版)
  11. 计算机学感悟,计算机学习感悟
  12. ZOJ-1003-Crashing-Balloon
  13. 使用Java处理键盘输入(DTMF)
  14. 【转】为您解决HDMI无声的烦恼
  15. 算法提高课-图论-欧拉回路和欧拉路径-AcWing 1123. 铲雪车:披着欧拉回路外衣的小学数学题
  16. conductor介绍
  17. 让apache支持pathinfo
  18. element ui 基本操作
  19. 分子生物学 第四章 DNA的生物合成
  20. ai域名火爆的原因分析

热门文章

  1. MySQL存储引擎与数据的关系_MySQL存储引擎与数据类型
  2. 2017年能源行业在大数据和人工智能领域的投资增长10倍
  3. 《Indoor Air》期刊介绍(SCI 2区)
  4. 微信平台开发与微信营销
  5. ntp服务restrict_linux设置NTP服务器及时间同步
  6. Unity文字转语音
  7. 一些关于面试常考的问题总结(计算机网络和python语法)
  8. 【售前运维】选方向必备之售前岗位详解
  9. Android 艺术字体设置
  10. kingedit 上传php_JS文件上传神器bootstrap fileinput详解