如何映射数组来为填充分区统计图着色?
我正在尝试手动将包含 6 个条目的 geojson 填充层映射到颜色数组。我尝试了以下方法,但它不起作用。
基本上希望颜色是countrypalette[id]
我尝试了countrypalette["get", "id"],但这也不起作用。
const countrypalette = ["#f0d27e", "#789d23", "#c06e51", "#b3e467", "#84241a", "#d9c0c7"]
map.addLayer(
{
id: 'Mekong_countries',
type: 'fill',
source: 'Mekong_countries',
paint: {
"fill-color": ["at", "id", ["array", countrypalette]]
}
}
)
I am trying to manually map a geojson fill layer with 6 entries to an array of colors. I tried the following but it doesn't work.
Basically was hoping that the colour be countrypalette[id]
I tried countrypalette["get", "id"], but that doesn't work either.
const countrypalette = ["#f0d27e", "#789d23", "#c06e51", "#b3e467", "#84241a", "#d9c0c7"]
map.addLayer(
{
id: 'Mekong_countries',
type: 'fill',
source: 'Mekong_countries',
paint: {
"fill-color": ["at", "id", ["array", countrypalette]]
}
}
)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您缺少
id
的属性查找(我猜这是您功能的整数属性)。第二件事有点奇怪,似乎我们需要一个to-color
转换函数才能完成这项工作:在您的代码中:
似乎添加了
to-color
code> 是强制性的,否则 Mapbox 会抱怨类型错误。 此问题中描述了该错误。You are missing a property lookup for your
id
(I guess it's an integer property of your features). The second thing is a bit odd, it seems like we need to at ato-color
conversion function to make this work:In your code:
It seems like adding the
to-color
is mandatory, otherwise mapbox complains about a type error. The bug is described in this issue.