作者:kxj
别名为属性表中属性字段的别名称,别名称主要作为属性表中属性字段的显示名称。前端对查询结果进行展示时可能需要用字段别名进行展示而不是字段名称,下面介绍一下地图服务和数据服务前端获取数据别名的方法。
地图服务在前端做查询时可以直接通过设置查询参数返回字段别名:
QueryByBoundsParameters、QueryByDistanceParameters、QueryByGeometryParameters、QueryBySQLParameters均可以设置returnFeatureWithFieldCaption参数来控制返回字段名称还是字段别名
参考代码(以SQL查询为例):
var param = new SuperMap.QueryBySQLParameters({
queryParams: {
name: "四川省_R_1@China",
attributeFilter: "SMID < 10",
returnFeatureWithFieldCaption:true,
}
});
查询结果:

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"
]
}
返回的字段信息(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
}
}
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
}
]