You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何在GeoServer CSS中添加条件逻辑实现道路标签智能显示

GeoServer道路标签优化:避免缺失字段时异常显示

在GeoServer中配置道路标签时,需求是将道路编码与名称并排显示(示例:X123-Highway),但使用初始配置时,若道路编码或名称任一缺失,会出现如编码-编码或名称-名称的重复显示问题,需要优化为仅在对应内容存在时显示单项标签。

初始问题代码

[@scale < 8k] {
    label: [code]"-"[name];
    label-anchor: 0.5 0.5;
    font-fill: black;
    font-weight: bold;
    label-follow-line: true;
    halo-color: #FFFFFF;
    halo-radius: 2;
}

优化后的代码

[@scale < 8k] {
    label: [code is Not Null][name is Not Null] ? [code]" - "[name] : [code is Not Null] ? [code] : [name];
    label-anchor: 0.5 0.5;
    font-fill: black;
    font-weight: bold;
    label-follow-line: true;
    halo-color: #FFFFFF;
    halo-radius: 2;
}

代码逻辑说明

通过嵌套条件判断实现精准显示:

  • 当code和name均不为空时,显示编码 - 名称格式
  • 仅code不为空时,只显示编码内容
  • 仅name不为空时,只显示名称内容

内容的提问来源于stack exchange,提问作者Priyanka Shakya

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.06.23 05:42:34