首页 > 解决方案 > How to color polygons based on different value ranges and null values in mapbox-gl-js?

问题描述

I'm trying to color polygons based on different value ranges. However, null values display as black. I'm not sure what would be the expression to explicitly say "use white colors for null values".

 paint: {
          "fill-color": [
  "step",
  ["get", "value"],
  "#f1eef6",
  100,
  "#bdc9e1",
  200,
  "#74a9cf",
  300,
  "#2b8cbe",
  400,
  "#045a8d"
],
  "fill-opacity": 1
  },

标签: mapboxmapbox-gl-jsmapbox-gl

解决方案


一种简单的方法是使用["match"]并将白色设置为默认颜色。这也捕获了您可能没有想到的任何其他值。

 "fill-color": [
  "match",
  ["get", "value"],
  "#f1eef6",
  100,
  "#bdc9e1",
  200,
  "#74a9cf",
  300,
  "#2b8cbe",
  400,
  "#045a8d",
  "white"
],

推荐阅读