# new MapServer(options)
地图服务
参数:
名称 | 类型 | 默认值 | 描述 |
---|---|---|---|
options |
Object | 构造参数 |
|
url |
String | null | 服务基地址 |
示例
//初始化MapServer服务对象
// ES5引入方式
const { MapServer } = zondy.service
// ES6引入方式
import { MapServer } from "@mapgis/webclient-common"
const mapServer = new MapServer({
//从igs详情里面获取的服务地址
url: 'http://localhost:8089/igs/rest/services/动态裁图/MapServer'
});
继承关系
成员变量
# enableGlobeFetch
是否使用确据唯一的fetch对象,默认为true,当设为false时,会使用自己私有的fetch对象,所有的请求设置不会影响全局
- Inherited From:
示例
//设置请求基地址
// ES5引入方式
const { BaseServer } = zondy.service
// ES6引入方式
import { BaseServer } from "@mapgis/webclient-common"
let BaseServer = new BaseServer({
//请求基地址
url: '你的URL',
//使用私有的fetch对象
enableGlobeFetch: false,
//此时设置token等属性,不会影响全局的fetch对象
tokenValue: '你的token'
});
//继续使用全局fetch
BaseServer.enableGlobeFetch = true;
# headers
请求头参数
- Inherited From:
示例
//设置请求头参数
// ES5引入方式
const { BaseServer } = zondy.service
// ES6引入方式
import { BaseServer } from "@mapgis/webclient-common"
let BaseServer = new BaseServer({
//请求头
headers: {
//设置Content-Type为multipart/form-data
'Content-Type': 'multipart/form-data',
//设置token
'token': '你的token'
}
});
//动态修改
BaseServer.headers.token = '新token';
# requestInterceptor
请求发送拦截器
- Inherited From:
示例
//设置拦截器,任何一个继承自BaseServer的对象都可以设置,全局唯一
// ES5引入方式
const { BaseServer,RequestInterceptor } = zondy.service
// ES6引入方式
import { BaseServer,RequestInterceptor } from "@mapgis/webclient-common"
let BaseServer = new BaseServer({
//设置请求发送拦截器
requestInterceptor: new RequestInterceptor({
//请求发送前进行统一处理
before: function(config) {
//执行你的业务逻辑
//注意必须显示返回config对象,如果返回为空,则不发送请求
return config;
},
//请求发送失败时进行统一处理
failure: function(error) {
//执行你的业务逻辑
}
})
});
//动态修改
BaseServer.requestInterceptor.before = function() {};
# requestTimeout
请求超时时间,默认45000ms,即45s
- Inherited From:
示例
//设置超时时间
//初始化AddressServer服务对象
// ES5引入方式
const { BaseServer } = zondy.service
// ES6引入方式
import { BaseServer } from "@mapgis/webclient-common"
let BaseServer = new BaseServer({
//超时时间
requestTimeout: 2000
});
//动态修改
BaseServer.requestTimeout = 3000;
# responseInterceptor
请求响应拦截器
- Inherited From:
示例
//设置拦截器,任何一个继承自BaseServer的对象都可以设置,全局唯一
// ES5引入方式
const { BaseServer,ResponseInterceptor } = zondy.service
// ES6引入方式
import { BaseServer,ResponseInterceptor } from "@mapgis/webclient-common"
let BaseServer = new BaseServer({
//设置请求响应拦截器
responseInterceptor: new ResponseInterceptor({
//执行请求响应,接口调用成功时会执行的回调
success: function(result) {
//执行你的业务逻辑
//注意必须显示返回result对象,如果返回为空,则不执行请求响应成功回调
return result;
},
//请求响应成功,接口调用失败时会执行的函数
failure: function(result) {
//执行你的业务逻辑
//注意必须显示返回result对象,如果返回为空,则不执行回调韩式
return result;
}
})
});
//动态修改
BaseServer.responseInterceptor.success = function() {};
# tokenAttachType
指定token附加到何处
- Inherited From:
示例
//设置token值
// ES5引入方式
const { BaseServer } = zondy.service
const { TokenAttachType } = zondy.enum
// ES6引入方式
import { BaseServer,TokenAttachType } from "@mapgis/webclient-common"
let BaseServer = new BaseServer({
//token名
tokenValue: '你的token值',
//token值
tokenValue: '你的token值',
//指定token附加到url后面
tokenAttachType: TokenAttachType.url
});
//动态修改
BaseServer.tokenAttachType = TokenAttachType.header;
# tokenKey
token名
- Inherited From:
示例
//设置token名
// ES5引入方式
const { BaseServer } = zondy.service
// ES6引入方式
import { BaseServer } from "@mapgis/webclient-common"
let BaseServer = new BaseServer({
//token名
tokenKey: '你的tokenKey'
});
//动态修改
BaseServer.tokenKey = '新tokenKey';
# tokenValue
token值
- Inherited From:
示例
//设置token值
// ES5引入方式
const { BaseServer } = zondy.service
// ES6引入方式
import { BaseServer } from "@mapgis/webclient-common"
let BaseServer = new BaseServer({
//token值
tokenValue: '你的token值'
});
//动态修改
BaseServer.tokenValue = '新token值';
# url
服务基地址
- Inherited From:
示例
//设置请求基地址
// ES5引入方式
const { BaseServer } = zondy.service
// ES6引入方式
import { BaseServer } from "@mapgis/webclient-common"
let BaseServer = new BaseServer({
//请求基地址
url: '你的URL'
});
//动态修改
BaseServer.url = '新URL';
方法
# addLayer(options)
添加临时文档图层
参数:
名称 | 类型 | 描述 |
---|---|---|
options |
Object | 构造参数 |
addInfo |
Array | 图层添加信息,必填 |
success |
function | 请求成功时的回调 |
failure |
queryFailure | 请求失败时的回调 |
clientId |
String | 客户端Id |
# deleteLayer(options)
删除临时文档图层
参数:
名称 | 类型 | 描述 |
---|---|---|
options |
Object | 构造参数 |
layerId |
String | 图层id,必传 |
success |
function | 请求成功时的回调 |
failure |
function | 请求失败时的回调 |
clientId |
String | 客户端Id |
# exportImage(options)
根据参数出图,详细说明请参考IGS的API文档
参数:
名称 | 类型 | 默认值 | 描述 |
---|---|---|---|
options |
参数 |
||
bbox |
Extent | null | 出图范围 |
layers |
String | null | 要显示的子图层,格式:show|hide|include|exclude:layerid1,layerid2 |
size |
String | '256,256' | 图片宽高 |
format |
String | 'png' | 图片格式,支持png/jpg/gif |
dynamicLayers |
String | null | 专题图出图参数 |
isAntialiasing |
Boolean | null | 返回的图片是否抗锯齿 |
layerFilters |
String | null | 出图过滤信息 |
layerStyles |
String | null | 样式信息 |
clipping |
String | null | 空间裁剪参数 |
transparent |
Boolean | true | 返回图片背景是否透明 |
projectionSrs |
SpatialReference | null | 返回图片背景是否透明 |
f |
String | 'image' | 请求返回格式,html或image,IGS2.0参数 |
clientId |
String | getGUID() | 客户端Id |
dpi |
Number | 96 | 图片的设备分辨率(每英寸点数),IGS2.0参数 |
mode |
String | null | 取图模式,IGS1.0参数,如果是快显取图(取值为hiRender或fast_display),这时文档为只读,只有bbox,w,h参数有效 |
style |
String | null | 图层样式设置,IGS1.0参数,已过时,不建议使用 |
出图请求对象
示例
// 构造出图参数
const exportOptions = {}
server.exportImage(exportOptions).then((result) => {
// 构造文件读取对象
const fileReader = new FileReader()
// 读取数据
if (result instanceof Blob) {
fileReader.readAsDataURL(result)
}
fileReader.onerror = () => {}
// 数据读取完毕,e.target.result就是base64字符串
fileReader.onload = (e) => {}
})
# getImage(options)
根据参数获取图片的url
参数:
名称 | 类型 | 默认值 | 描述 |
---|---|---|---|
options |
参数 |
||
bbox |
Extent | null | 出图范围,IGS1.0和2.0以及IGS1.0的GDBP出图通用参数 |
layers |
String | null | 要显示的子图层,格式:show|hide|include|exclude:layerid1,layerid2,IGS1.0和2.0出图参数 |
size |
String | '256,256' | 图片宽高,IGS1.0和2.0以及IGS1.0的GDBP出图通用参数 |
format |
String | 'png' | 图片格式,IGS1.0和2.0以及IGS1.0的GDBP出图通用参数,格式都为png/jpg/gif |
dynamicLayers |
String | null | 专题图出图参数,IGS2.0出图参数 |
isAntialiasing |
Boolean | null | 返回的图片是否抗锯齿,IGS1.0和2.0以及IGS1.0的GDBP出图通用参数 |
layerFilters |
String | null | 出图过滤信息,IGS1.0和2.0以及IGS1.0的GDBP出图通用参数 |
layerStyles |
String | null | 样式信息,IGS2.0参数 |
clipping |
String | null | 空间裁剪参数,IGS2.0参数 |
transparent |
Boolean | true | 返回图片背景是否透明,IGS2.0参数 |
projectionSrs |
SpatialReference | null | 出图动态投影参数,IGS1.0和2.0以及IGS1.0的GDBP出图通用参数 |
f |
String | 'image' | 请求返回格式,html或image,IGS2.0参数 |
clientId |
String | getGUID() | 客户端Id,IGS1.0和2.0以及IGS1.0的GDBP出图通用参数 |
dpi |
Number | 96 | 图片的设备分辨率(每英寸点数),IGS2.0参数 |
mode |
String | null | 取图模式,IGS1.0参数,如果是快显取图(取值为hiRender或fast_display),这时文档为只读,只有bbox,w,h参数有效 |
style |
String | null | 图层样式设置,IGS1.0以及以及IGS1.0的GDBP参数,已过时,不建议使用 |
gdbps |
String | null | 需要出图的地址,多个用英文逗号分隔,IGS1.0的GDBP出图参数 |
mapUri |
String | null | 地图资源路径,比如mapx的路径,如果该参数不为空,则gdbps无效,IGS1.0的GDBP出图参数 |
formatMode |
String | 'normal' | 生成参数格式,normal: 按照默认逻辑设置参数,replace: 将部分参数设置为可替换的模版字符串 |
String 图片的url
# getLegend(options)
获取图例
参数:
名称 | 类型 | 描述 |
---|---|---|
options |
Object | 构造参数 |
success |
getLegendSuccess | 请求成功时的回调 |
failure |
queryFailure | 请求失败时的回调 |
layers |
String | 图层索引列表,多个用英文逗号隔开 |
size |
String | 图例图片的大小,格式:width,height |
where |
String | 属性条件,类SQL语句 |
bbox |
Extent | 矩形范围过滤条件 |
page |
Number | 图例结果分页页数 |
pageSize |
Number | 图例结果分页大小 |
maxQueryFeatureCount |
Number | 查询要素的最大条数 |
示例
//回调方式
mapServer.getLegend({
layers: "0",
size: '45,45',
success: function (result) {
console.log('请求成功:', result);
},
failure: function (result) {
console.log('请求失败:', result);
}
});
//promise方式
mapServer.getLegend({
layers: "1"
}).then(function (result) {
console.log('请求成功:', result);
}).catch(function (result) {
console.log('请求失败:', result);
});
# getTile(options)
根据IGS版本获取出图地址,会根据IGS版本挑选出图参数
参数:
名称 | 类型 | 默认值 | 描述 |
---|---|---|---|
options |
Object | 出图参数 |
|
lvl |
String | Number | '{z}' | 瓦片级数 |
row |
String | Number | '{y}' | 瓦片行号 |
col |
String | Number | '{x}' | 瓦片列号 |
f |
String | 'image' | 请求返回格式,支持html和image,IGS2.0参数 |
blankTile |
Boolean | true | 当没有瓦片数据时,是否返回空白图,IGS2.0参数 |
出图地址,格式为: IGS1.0: http://{ip}:{port}/igs/rest/mrms/tile/{服务名称}/{z}/{y}/{x} IGS2.0: http://{ip}:{port}/igs/rest/services/{服务名称}/MapServer/tileImage/{z}/{y}/{x}?f=image&blankTile=true
# queryFeatures(options)
指定图层的要素查询
参数:
名称 | 类型 | 默认值 | 描述 |
---|---|---|---|
options |
Object | 构造参数 |
|
layerId |
String | 图层id,必传 |
|
success |
queryFeaturesSuccess | 请求成功时的回调 |
|
failure |
queryFailure | 请求失败时的回调 |
|
method |
FetchMethod | FetchMethod.get | 请求方式,包括FetchMethod.get,FetchMethod.post |
where |
String | 要素查询where条件,类似sql语句 |
|
geometry |
Geometry | 要素查询几何条件 |
|
distance |
Number | 0 | 几何缓冲的距离,geometry为point、line时有效(若数据源为大数据PG数据,且geometryType为line或者point时为必填数据) |
geometryPrecision |
Number | 指定返回要素中几何坐标的小数点位数,例如2,则返回两位小数 |
|
spatialRel |
SpatialRelation | 几何条件的空间判定规则,Intersects(相交)、EnvelopeIntersects(外包矩形相交)、Contains(包含)、Disjoint(相离) |
|
outFields |
String | 指定要输出的属性字段,可为*表示所有,多个用英文逗号分隔 |
|
objectIds |
String | 过滤id,多个用英文逗号分隔(参数优先级很高,可能导致其它筛选条件失效) |
|
orderByFields |
String | 排序字段,格式: fieldName [ASC|DESC] |
|
groupByFieldsForStatistics |
String | 分组统计的字段信息,格式为field1,field2 |
|
resultRecordCount |
Number | 20 | 分页参数:结果返回条数,默认20 |
resultOffset |
Number | 分页参数:跳过条数,例如resultOffset为4,则跳过前4条,从第5条开始返回resultRecordCount的数量 |
|
outStatistics |
Array.<OutStatistic> | 字段统计参数数组 |
|
returnGeometry |
Boolean | true | 是否返回要素几何信息,默认为true |
returnAttribute |
Boolean | true | 是否返回要素属性,默认为true |
returnStyle |
Boolean | false | 是否返回要素样式,默认为false |
returnIdsOnly |
Boolean | false | 是否只返回要素id,默认为false |
returnCountOnly |
Boolean | false | 是否只返回要素条数,默认为false |
returnExtentOnly |
Boolean | false | 是否只返回范围,默认为false |
returnZ |
Boolean | false | 是否返回Z轴,默认为false |
示例
//通过where语句进行查询
//回调方式
// ES5引入方式
const { Point } = zondy.geometry
// ES6引入方式
import { Point } from "@mapgis/webclient-common"
mapServer.queryFeatures({
//图层id
layerId: '1',
//where查询条件,类似sql语句,这里查询2011年GDP大于20的城市
where: "GDP2011>20",
//以GDP2011字段进行升序排序
orderByFields: "GDP2011 ASC",
//指定输出的属性字段为NAME,GDP2011
outFields: "NAME,GDP2011",
//指定返回要素中几何坐标的小数点位数为2
geometryPrecision: 2,
//成功返回结果
success: function(result) {
console.log('请求成功:',result);
},
failure: function(result) {
console.log('请求失败:',result);
}
});
//promise方式
//通过geometry语句进行查询
let point = new Point({
coordinates: [113.8178, 30.172834]
});
mapServer.queryFeatures({
//图层id
layerId: 1,
//几何条件
geometry: point,
//设置缓冲距离,仅当几何类型为point、line时有效
distance: 100
}).then(function (result) {
console.log('请求成功:', result);
}).catch(function (result) {
console.log(' n请求失败:', result);
});
# queryFeaturesInLayers(options)
多图层的要素查询
参数:
名称 | 类型 | 默认值 | 描述 |
---|---|---|---|
options |
要素查询参数 |
||
success |
queryFeaturesInLayersSuccess | 查询成功回调函数,若使用Promise方式则不必填写 |
|
failure |
queryFailure | 查询失败回调函数,若使用Promise方式则不必填写 |
|
layerDefs |
Array | 多图层的属性条件,包括layerId、where、outFields;当值为空时,查询所有图层,示例:"[{ "layerId":"0-0","where": "name='中国'", "outfields": "field1,field2"}]" |
|
geometry |
Geometry | 要素查询几何条件 |
|
distance |
Number | 0 | 几何缓冲的距离,geometry为point、line时有效(若数据源为大数据PG数据,且geometryType为line或者point时为必填数据) |
geometryPrecision |
Number | 返回要素几何信息中坐标xy的精度 |
|
spatialRel |
SpatialRelation | 几何条件的空间判定规则,Intersects(相交)、EnvelopeIntersects(外包矩形相交)、Contains(包含)、Disjoint(相离) |
|
resultRecordCount |
Number | 20 | 分页参数:结果返回条数,默认20 |
returnGeometry |
Boolean | true | 是否返回几何,默认为true |
returnAttribute |
Boolean | true | 是否返回属性,默认为true |
returnStyle |
Boolean | false | 是否返回图形参数信息,默认为false |
returnIdsOnly |
Boolean | false | 是否只返回id,默认为false |
returnCountOnly |
Boolean | false | 是否只返回条数,默认为false |
returnZ |
Boolean | false | 是否返回Z轴,默认为false |
f |
String | 'json' | 查询返回的数据格式。支持"html" "json" "geojson" "csv"返回格式 //回调方式 // ES5引入方式 const { Extent } = zondy.geometry const { FetchMethod } = zondy.enum // ES6引入方式 import { Extent,FetchMethod } from "@mapgis/webclient-common" mapServer.queryFeaturesInLayers({ geometry: new Extent({ xmin: 110.66, ymin: 29.61, xmax: 114.05, ymax: 32.43 }), method: FetchMethod.post, success: function (result) { console.log('请求成功:', result); }, failure: function (result) { console.log('请求击败:', result); } }); //promise方式 mapServer.queryFeaturesInLayers({ layerDefs: [{ layerId: "0", outfields: "mpLayer,mpPerimeter" },{ layerId: "1", where: "mpLayer=1", outfields: "mpLayer" }] }).then(function (result) { console.log('请求成功:', result); }).catch(function (result) { console.log(' n请求失败:', result); }); |
# queryLayerInfo(options)
查询指定图层信息
参数:
名称 | 类型 | 描述 |
---|---|---|
options |
Object | 构造参数 |
layerId |
String | 图层id,必填 |
success |
queryLayerInfoSuccess | 请求成功时的回调 |
failure |
queryFailure | 请求失败时的回调 |
clientId |
String | 客户端Id |
mapIndex |
String | 地图索引,igs1.0参数 |
returnFullStyle |
Boolean | 是否返回全部信息的标志位 |
guid |
String | 用户会话id |
示例
//查询指定图层信息
//回调方式
mapServer.queryLayerInfo({
//图层id
layerId: 0,
//成功回调
success: function(result) {
console.log('请求成功:',result);
},
failure: function (result) {
console.log('请求失败:', result);
}
});
//promise方式
mapServer.queryLayerInfo({
//图层id
layerId: '0'
}).then(function (result) {
console.log('请求成功:', result);
}).catch(function (result) {
console.log(' n请求失败:', result);
});
# queryLayerList(options)
获取图层列表信息
参数:
名称 | 类型 | 描述 |
---|---|---|
options |
Object | 构造参数 |
success |
queryLayerListSuccess | 请求成功时的回调 |
failure |
queryFailure | 请求失败时的回调 |
clientId |
String | 临时图层ID |
mapIndex |
String | 地图索引,IGS1.0参数 |
guid |
String | 用户会话id,IGS1.0参数 |
示例
//获取图层列表信息
//回调方式
mapServer.queryLayerList({
success: function(result) {
console.log('请求成功:',result);
},
failure: function(result) {
console.log('请求失败:',result);
}
});
//promise方式
mapServer.queryLayerList({
}).then(function (result) {
console.log('请求成功:', result);
}).catch(function (result) {
console.log(' n请求失败:', result);
});
# queryServerInfo(options)
获取服务信息,IGS2.0新增服务
参数:
名称 | 类型 | 默认值 | 描述 |
---|---|---|---|
options |
查询参数 |
||
success |
function | 无 | 查询成功回调函数,若使用Promise方式则不必填写 |
failure |
function | 无 | 查询失败回调函数,若使用Promise方式则不必填写 |
- Inherited From:
示例
获取服务信息-回调方式
server.queryServerInfo({
success: function (result) {
console.log('请求成功:', result);
},
failure: function (result) {
console.log('请求失败:', result);
}
});
获取服务信息-promise方式
server.queryServerInfo({
})
.then(function (result) {
console.log('请求成功:', result);
}).catch(function (result) {
console.log('请求失败:', result);
});
# setSystemLib(options)
设置图层的系统库
参数:
名称 | 类型 | 描述 |
---|---|---|
options |
Object | 构造参数 |
layerId |
String | 图层id,必填 |
systemLibId |
String | 系统库id,必填 |
systemLibName |
String | 系统库名,当systemLibId为空时有效,必填 |
success |
function | 请求成功时的回调 |
failure |
function | 请求失败时的回调 |