• SuperMap iClient for JavaScript如何获取字段别名




    作者:kxj

    前言

      别名为属性表中属性字段的别名称,别名称主要作为属性表中属性字段的显示名称。前端对查询结果进行展示时可能需要用字段别名进行展示而不是字段名称,下面介绍一下地图服务和数据服务前端获取数据别名的方法。

    地图服务

    地图服务在前端做查询时可以直接通过设置查询参数返回字段别名:
    在这里插入图片描述QueryByBoundsParameters、QueryByDistanceParameters、QueryByGeometryParameters、QueryBySQLParameters均可以设置returnFeatureWithFieldCaption参数来控制返回字段名称还是字段别名
    参考代码(以SQL查询为例):

     var param = new SuperMap.QueryBySQLParameters({
                queryParams: {
                    name: "四川省_R_1@China",
                    attributeFilter: "SMID < 10",
                    returnFeatureWithFieldCaption:true,
                }
            });
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7

    查询结果:
    在这里插入图片描述
    serviceResult.result.recordsets[0].fieldCaptions即为字段别名。

    数据服务

    数据服务查询无法像地图服务查询一样直接在前端通过设置参数来获取到字段别名,可以通过对 fields 资源执行 GET 请求获取数据集中的字段信息列表,其中name为字段名称,唯一标识一个字段,没有重名;caption为字段别名,不同的字段可以有相同的别名。

    1.对示例 fields 资源:http://localhost:8090/iserver/services/data-BieMing-2/rest/data/datasources/China/datasets/四川省_R_1/fields.rjson 执行 GET 请求,获取China数据源四川省_R_1 数据集中的字段信息集合,rjson 格式的资源表述如下:

    {
        "fieldNames": [
            "SmID",
            "SmUserID",
            "SmArea",
            "SmPerimeter",
            "SmGeometry",
            "name",
            "level_User",
            "province"
        ],
        "childUriList": [
            "http://localhost:8090/iserver/services/data-BieMing-2/rest/data/datasources/China/datasets/四川省_R_1/fields/SmID",
            "http://localhost:8090/iserver/services/data-BieMing-2/rest/data/datasources/China/datasets/四川省_R_1/fields/SmUserID",
            "http://localhost:8090/iserver/services/data-BieMing-2/rest/data/datasources/China/datasets/四川省_R_1/fields/SmArea",
            "http://localhost:8090/iserver/services/data-BieMing-2/rest/data/datasources/China/datasets/四川省_R_1/fields/SmPerimeter",
            "http://localhost:8090/iserver/services/data-BieMing-2/rest/data/datasources/China/datasets/四川省_R_1/fields/SmGeometry",
            "http://localhost:8090/iserver/services/data-BieMing-2/rest/data/datasources/China/datasets/四川省_R_1/fields/name",
            "http://localhost:8090/iserver/services/data-BieMing-2/rest/data/datasources/China/datasets/四川省_R_1/fields/level_User",
            "http://localhost:8090/iserver/services/data-BieMing-2/rest/data/datasources/China/datasets/四川省_R_1/fields/province"
        ]
    }
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
    • 18
    • 19
    • 20
    • 21
    • 22

    返回的字段信息(field 资源)访问路径列表可以获取到每一个字段的访问路径,通过提供的每一个字段的访问路径可以获取到每个字段的详细描述信息,其中"caption"为字段别名,仅需要获取某个字段别名时可以直接通过对"fields/字段名.json"资源执行get请求获取。例如获取示例服务的China数据源四川省_R_1 数据集中的name字段:对http://localhost:8090/iserver/services/data-BieMing-2/rest/data/datasources/China/datasets/四川省_R_1/fields/name.json执行get请求,获取结果如下:

    {
        "childUriList": [
            "http://localhost:8090/iserver/services/data-BieMing-2/rest/data/datasources/China/datasets/四川省_R_1/fields/name/MAX",
            "http://localhost:8090/iserver/services/data-BieMing-2/rest/data/datasources/China/datasets/四川省_R_1/fields/name/MIN",
            "http://localhost:8090/iserver/services/data-BieMing-2/rest/data/datasources/China/datasets/四川省_R_1/fields/name/AVERAGE",
            "http://localhost:8090/iserver/services/data-BieMing-2/rest/data/datasources/China/datasets/四川省_R_1/fields/name/STDDEVIATION",
            "http://localhost:8090/iserver/services/data-BieMing-2/rest/data/datasources/China/datasets/四川省_R_1/fields/name/SUM",
            "http://localhost:8090/iserver/services/data-BieMing-2/rest/data/datasources/China/datasets/四川省_R_1/fields/name/VARIANCE"
        ],
        "fieldInfo": {
            "isRequired": false,
            "defaultValue": "",
            "name": "name",
            "caption": "市名",
            "type": "WTEXT",
            "maxLength": 255,
            "isZeroLengthAllowed": true,
            "isSystemField": false
        }
    }
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
    • 18
    • 19
    • 20

    2.如需获取较多字段或全部字段的别名时,可以直接对示例 fields 资源http://localhost:8090/iserver/services/data-BieMing-2/rest/data/datasources/China/datasets/%E5%9B%9B%E5%B7%9D%E7%9C%81_R_1/fields.rjson?returnAll=true 执行 GET 请求,获取China数据源 四川省_R_1 数据集中的字段的详细描述信息,rjson 格式的资源表述如下:

    [
        {
            "isRequired": true,
            "defaultValue": "",
            "name": "SmID",
            "caption": "SmID",
            "type": "INT32",
            "maxLength": 4,
            "isZeroLengthAllowed": true,
            "isSystemField": true
        },
        {
            "isRequired": true,
            "defaultValue": "0",
            "name": "SmUserID",
            "caption": "SmUserID",
            "type": "INT32",
            "maxLength": 4,
            "isZeroLengthAllowed": true,
            "isSystemField": false
        },
        {
            "isRequired": true,
            "defaultValue": "0",
            "name": "SmArea",
            "caption": "SmArea",
            "type": "DOUBLE",
            "maxLength": 8,
            "isZeroLengthAllowed": true,
            "isSystemField": true
        },
        {
            "isRequired": true,
            "defaultValue": "0",
            "name": "SmPerimeter",
            "caption": "SmPerimeter",
            "type": "DOUBLE",
            "maxLength": 8,
            "isZeroLengthAllowed": true,
            "isSystemField": true
        },
        {
            "isRequired": true,
            "defaultValue": "",
            "name": "SmGeometry",
            "caption": "SmGeometry",
            "type": "LONGBINARY",
            "maxLength": 0,
            "isZeroLengthAllowed": true,
            "isSystemField": true
        },
        {
            "isRequired": false,
            "defaultValue": "",
            "name": "name",
            "caption": "市名",
            "type": "WTEXT",
            "maxLength": 255,
            "isZeroLengthAllowed": true,
            "isSystemField": false
        },
        {
            "isRequired": false,
            "defaultValue": "",
            "name": "level_User",
            "caption": "级别",
            "type": "WTEXT",
            "maxLength": 255,
            "isZeroLengthAllowed": true,
            "isSystemField": false
        },
        {
            "isRequired": false,
            "defaultValue": "",
            "name": "province",
            "caption": "省份",
            "type": "WTEXT",
            "maxLength": 255,
            "isZeroLengthAllowed": true,
            "isSystemField": false
        }
    ]
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
    • 18
    • 19
    • 20
    • 21
    • 22
    • 23
    • 24
    • 25
    • 26
    • 27
    • 28
    • 29
    • 30
    • 31
    • 32
    • 33
    • 34
    • 35
    • 36
    • 37
    • 38
    • 39
    • 40
    • 41
    • 42
    • 43
    • 44
    • 45
    • 46
    • 47
    • 48
    • 49
    • 50
    • 51
    • 52
    • 53
    • 54
    • 55
    • 56
    • 57
    • 58
    • 59
    • 60
    • 61
    • 62
    • 63
    • 64
    • 65
    • 66
    • 67
    • 68
    • 69
    • 70
    • 71
    • 72
    • 73
    • 74
    • 75
    • 76
    • 77
    • 78
    • 79
    • 80
    • 81
    • 82
  • 相关阅读:
    微信公众号菜单栏规划怎么设置?
    “Can‘t open workbook - unsupported file type: XML“
    GEO生信数据挖掘(九)肺结核数据-差异分析-WGCNA分析(900行代码整理注释更新版本)
    Linux下安装两个版本python
    leetcode每天5题-Day34
    尚医通 (一) --------- 项目介绍
    【路径规划】A*算法 Java实现
    C++套接字库sockpp介绍
    【Bug】Unable to make field private final int java.time.LocalDate.year accessible
    [附源码]计算机毕业设计springboot校园招聘微信小程序
  • 原文地址:https://blog.csdn.net/supermapsupport/article/details/125477572