ArcGis之popup列表字段自定義

ArcGis之popup列表字段自定義javascript

featureLayer圖層中能夠使用popupTemplate屬性添加彈窗。html

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

1.number格式化git

                {
                  fieldName: '面積',
                  label: '面積/m²',
                  format: {
                    digitSeparator: true, // 開啓每三位添加,
                    places: 2 // 保留小數點2位
                  }
                }

2.添加單位express

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.字典轉換api

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'
                }
              ]
            }
          ]
        }

 

 

 

鑽研不易,轉載請註明出處。。。。。。ide

相關文章
相關標籤/搜索