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

 

 

 

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

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM