我在Web应用程序上工作,如果它们的值为空或空,则需要将标签排除在渲染中。在我的LabelingInfo中,当标签没有有效的值时会出现问题 - 符号的背景颜色仍显示,这导致呈现空框。 我正在尝试通过在标签为空或空的时动态隐藏背景来解决此问题。这是我目前的实施:

问题描述 投票:0回答:1
通过纠正用于检查字段是否为空的条件来解决该问题。在原始实现中,逻辑是有缺陷的,导致背景颜色持续使用空白标签。以下是更新的配置。

提出的实施

: 条件不当检查无效的值,导致不正确的行为:
'icon-image': [
    'case',
    ['==', ['get', ['to-string', ['get', objectIdField?.name]], ['literal', { ...textExpression[2][1] }]], null],
    null, // Use the icon if the field has a value
    background, // Hide the icon otherwise
],
mapbox mapbox-gl-js mapbox-gl
1个回答
0
投票

任期实施

: 该条件已被简化并纠正以直接检查字段值是否为null:

'icon-image': [ 'case', ['==', ['get', 'fieldName'], null], // Check if the field is null 'none', // Hide the icon for null values background, // Use the specified background icon for non-null values ],

此修复程序可确保仅在关联字段具有值时显示图标。它还消除了为空标签呈现背景颜色的问题。
	

最新问题
© www.soinside.com 2019 - 2025. All rights reserved.