简体   繁体   English

Mapbox GL JS 忽略属性表达式

[英]Mapbox GL JS ignore property expression

I'm trying to make geojson layer of polygons with diffrent fills.我正在尝试用不同的填充制作多边形的 geojson 层。 Some of them need to use "fill-patern" so they have "fill-patern" property, but some of them don't.其中一些需要使用“填充模式”,因此它们具有“填充模式”属性,但其中一些没有。 I'm getting both of the "fill-patern" and "fill-color" proreties by expressions:我通过表达式获得了“填充模式”和“填充颜色”两个属性:

   paint: {
            "fill-pattern": ["get", "fill-pattern"],
            "fill-color": ["get", "fill-color"],
          },

But "fill-patern" property with any value (even null, or undefined) makes layer ignore "fill-color" property of this feature.但是具有任何值的“填充模式”属性(甚至 null 或未定义)会使图层忽略此功能的“填充颜色”属性。 So is that possible to fully ignore property if feature doesn't have it?那么,如果功能没有属性,是否可以完全忽略它?

You're correct that, as noted in the documentation for the fill-color property here , fill-color is disabled by fill-pattern .您是对的,正如此处关于fill-color属性的文档中所述, fill-colorfill-pattern禁用。 In this scenario, the best approach would be to make two separate layers, one for the polygons that need to use fill-pattern and one for the polygons that don't.在这种情况下,最好的方法是制作两个单独的图层,一个用于需要使用fill-pattern的多边形,一个用于不需要使用填充图案的多边形。 You could either use the same source for each layer and apply a filter expression as needed, or break up your original source into two separate sources.您可以为每个图层使用相同的源并根据需要应用filter表达式,或者将原始源分解为两个单独的源。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM