ArcGis之popup列表字段自定义

ArcGis之popup列表字段自定义

featureLayer图层中可以使用popupTemplate属性添加弹窗。

API:https://developers.arcgis.com/javascript/latest/api-reference/esri-layers-FeatureLayer.html#popupTemplate

1.number格式化

                {
                  fieldName: '面积',
                  label: '面积/m²',
                  format: {
                    digitSeparator: true, // 开启每三位添加,
                    places: 2 // 保留小数点2位
                  }
                }

2.添加单位

expressionInfos属性可以对字段进行格式化,fieldName属性引用expressionInfos定义的格式。
案例:https://developers.arcgis.com/javascript/latest/sample-code/popuptemplate-arcade/index.html
        popupTemplate: {
          title: '{name}',
          expressionInfos: [
            {
              name: 'redLineArea',
              title: '面积',
              expression: 'Round($feature.type, 2) + "m²"'
            }
          ],
          content: [
            {
              type: 'fields',
              fieldInfos: [
                {
                  fieldName: 'expression/redLineArea'
                }
              ]
            }
          ]
        }

3.字典转换

expression中使用了字符模板的写法。
案例:https://developers.arcgis.com/javascript/latest/guide/arcade/
        popupTemplate: {
          title: '{name}',
          expressionInfos: [
            {
              name: 'redLineType',
              title: '地块类型',
              expression:
                `if ($feature.type == "01") {
                        return '功能区'
                }
                else if($feature.type == "02") {
                        return '环境区'
                }`
            }
          ],
          content: [
            {
              type: 'fields',
              fieldInfos: [
                {
                  fieldName: 'expression/redLineType'
                }
              ]
            }
          ]
        }

钻研不易,转载请注明出处。。。。。。

原文地址:https://www.cnblogs.com/s313139232/p/10895462.html