Class: GeometryServer

GeometryServer

new GeometryServer(options)

service/igs/GeometryServer.js, line 5

地理几何服务。

GeometryServer 提供面积、长度、缓冲区、投影转换等几何计算能力, 适用于服务端统一计算并返回结构化结果。

Name Type Default Description
options Object {} 可选

构造参数。

Name Type Default Description
url String null 可选

服务基地址。 IGS1.0: http://{ip}:{port}/igs/rest/mrgs/geomservice。 IGS2.0: http://{ip}:{port}/igs/rest/services/system/GeometryServer

Example
// ES5引入方式
const { GeometryServer } = zondy.service

// ES6引入方式
import { GeometryServer } from '@mapgis/webclient-common'

const geometryServer = new GeometryServer({
  url: 'http://localhost:8089/igs/rest/services/system/GeometryServer',
  requestInterceptor: {
    before: function (config) {
      return config;
    },
    failure: function (error) {
      console.log("请求发送失败(拦截器):", error)
    }
  },
  responseInterceptor: {
    success: function (result) {
      console.log("请求成功拦截响应")
      return result;
    },
    failure: function (result) {
      console.log("请求失败拦截响应")
      return result;
    }
  }
});

Extends

Members

clientIdString undefined

客户端标识

enableGlobeFetchBoolean

是否使用确据唯一的fetch对象,默认为true,当设为false时,会使用自己私有的fetch对象,所有的请求设置不会影响全局

Example
//设置请求基地址
// 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;

headersString

请求头参数

Example
//设置请求头参数
// 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';

requestInterceptorfunction

请求发送拦截器

Example
//设置拦截器,任何一个继承自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() {};

requestTimeoutString

请求超时时间,默认45000ms,即45s

Example
//设置超时时间
//初始化AddressServer服务对象
// ES5引入方式
const { BaseServer } = zondy.service

// ES6引入方式
import { BaseServer } from "@mapgis/webclient-common"
let BaseServer = new BaseServer({
  //超时时间
  requestTimeout: 2000
});
//动态修改
BaseServer.requestTimeout = 3000;

responseInterceptorfunction

请求响应拦截器

Example
//设置拦截器,任何一个继承自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() {};

tokenAttachTypeTokenAttachType

指定token附加到何处

Example
//设置token值
// ES5引入方式
const { BaseServer } = zondy.service
const { TokenAttachType } = zondy.enum

// ES6引入方式
import { BaseServer,TokenAttachType } from "@mapgis/webclient-common"
let BaseServer = new BaseServer({
  //token名
  tokenKey: '你的token key',
  //token值
  tokenValue: '你的token值',
  //指定token附加到url后面
  tokenAttachType: TokenAttachType.url
});
//动态修改
BaseServer.tokenAttachType = TokenAttachType.header;

tokenKeyString

token名

Example
//设置token名
// ES5引入方式
const { BaseServer } = zondy.service

// ES6引入方式
import { BaseServer } from "@mapgis/webclient-common"
let BaseServer = new BaseServer({
  //token名
  tokenKey: '你的tokenKey'
});
//动态修改
BaseServer.tokenKey = '新tokenKey';

tokenValueString

token值

Example
//设置token值
// ES5引入方式
const { BaseServer } = zondy.service

// ES6引入方式
import { BaseServer } from "@mapgis/webclient-common"
let BaseServer = new BaseServer({
  //token值
  tokenValue: '你的token值'
});
//动态修改
BaseServer.tokenValue = '新token值';

urlString

服务基地址

Example
//设置请求基地址
// ES5引入方式
const { BaseServer } = zondy.service

// ES6引入方式
import { BaseServer } from "@mapgis/webclient-common"
let BaseServer = new BaseServer({
  //请求基地址
  url: '你的URL'
});
//动态修改
BaseServer.url = '新URL';

Methods

bufferAnalyse(options){Promise.<Object>}

service/igs/GeometryServer.js, line 321

缓冲分析。

基于输入几何和缓冲半径生成缓冲区结果,默认使用 POST 请求。

Name Type Default Description
options Object {} 可选

查询参数。

Name Type Description
geometries Geometry

待缓冲的几何对象。

distance Number

缓冲半径。

success function 可选

请求成功回调。

failure function 可选

请求失败回调。

Returns:
Type Description
Promise.<Object> 缓冲分析结果。

calculateArea(options){Promise.<Object>}

service/igs/GeometryServer.js, line 139

计算多边形面积。

projectInfoprojectInfoBySrsID 二选一,用于指定投影参考信息。

Name Type Default Description
options Object {} 可选

查询参数。

Name Type Description
polygon Polygon

待计算面积的多边形对象。

success function 可选

请求成功回调。

failure function 可选

请求失败回调。

projectInfo ProjectInfo 可选

投影参考信息。

projectInfoBySrsID ProjectInfoBySrsID 可选

源投影参考系 ID。

Returns:
Type Description
Promise.<Object> 面积计算结果。

calculateAreasAndLengths(options){Promise.<Object>}

service/igs/GeometryServer.js, line 52

计算多边形面积与周长。

支持批量多边形输入,返回每个输入几何对应的面积与长度统计结果。

Name Type Default Description
options Object {} 可选

查询参数。

Name Type Description
polygons Polygon

待计算的多边形对象。

success function 可选

请求成功回调。

failure function 可选

请求失败回调。

Returns:
Type Description
Promise.<Object> 面积与周长计算结果。
Example
// 回调方式
// ES5引入方式
const { Polygon } = zondy.geometry

// ES6引入方式
import { Polygon } from "@mapgis/webclient-common"
geometryServer.calculateAreasAndLengths({
  polygons: new Polygon({
    spatialReference: "EPSG:4326",
    coordinates: [
      [
        [108.9587, 34.2206],
        [112.9607, 31.2196],
        [110.9598, 30.2181],
        [110.9587, 32.2191],
        [108.9587, 34.2206]
      ]
    ]
  }),
  success: function (result) {
    console.log('请求成功:', result);
  },
  failure: function (result) {
    console.log('请求失败:', result);
  }
});
// promise方式
geometryServer.calculateAreasAndLengths({
  polygons: new Polygon({
    spatialReference: "EPSG:4326",
    coordinates: [
      [
        [108.9587, 34.2206],
        [112.9607, 31.2196],
        [110.9598, 30.2181],
        [110.9587, 32.2191],
        [108.9587, 34.2206]
      ]
    ]
  })
}).then(function (result) {
  console.log('请求成功:', result);
}).catch(function (result) {
  console.log('请求失败:', result);
})

calculateDifference(options){Promise.<Object>}

service/igs/GeometryServer.js, line 367

求差计算。

计算 geometry1 相对 geometry2 的差集结果,默认使用 POST 请求。

Name Type Default Description
options Object {} 可选

查询参数。

Name Type Description
geometry1 Geometry

差集计算输入几何 1。

geometry2 Geometry

差集计算输入几何 2。

tolerance Number

计算容差。

success function 可选

请求成功回调。

failure function 可选

请求失败回调。

Returns:
Type Description
Promise.<Object> 差集计算结果。

calculateDistance(options){Promise.<Object>}

service/igs/GeometryServer.js, line 419

计算两个几何对象的距离。

需要显式传入 srs 指定距离计算参考系,默认使用 POST 请求。

Name Type Default Description
options Object {} 可选

查询参数。

Name Type Description
geometry1 Geometry

距离计算输入几何 1。

geometry2 Geometry

距离计算输入几何 2。

srs String

距离计算参考系。

success function 可选

请求成功回调。

failure function 可选

请求失败回调。

Returns:
Type Description
Promise.<Object> 距离计算结果。

calculateIntersect(options)

service/igs/GeometryServer.js, line 517

求交计算

Name Type Description
options

查询参数

Name Type Description
geometry1 Geometry 可选

要计算的多边形1,必填

geometry2 Geometry 可选

要计算的多边形2,必填

tolerance Number 可选

容差,必填

success function 可选

查询成功回调函数,若使用Promise方式则不必填写

failure function 可选

查询失败回调函数,若使用Promise方式则不必填写

Example
// ES5引入方式
const { Polygon } = zondy.geometry
const { Polygon,FetchMethod } = zondy.enum

// ES6引入方式
import { Polygon,FetchMethod } from "@mapgis/webclient-common"
geometryServer.calculateIntersect({
  geometry1: new Polygon({
    coordinates: [[ [105.0, 0.0],[164.0, 0.0],[164.0, 10.0],[105.0, 10.0],[105.0, 0.0] ]]
  }),
  geometry2: new Polygon({
    coordinates: [[ [110.0, 5.0],[170.0, 5.0],[170.0, 20.0],[110.0, 20.0],[110.0, 5.0] ]]
  }),
  tolerance: 1,
  method: FetchMethod.post,
  success: function (result) {
    console.log('请求成功:', result);
  },
  failure: function (result) {
    console.log('请求失败:', result);
  }
});
// promise方式
geometryServer.calculateIntersect({
  geometry1: new Polygon({
    coordinates: [[ [105.0, 0.0],[164.0, 0.0],[164.0, 10.0],[105.0, 10.0],[105.0, 0.0] ]]
  }),
  geometry2: new Polygon({
    coordinates: [[ [110.0, 5.0],[170.0, 5.0],[170.0, 20.0],[110.0, 20.0],[110.0, 5.0] ]]
  }),
  tolerance: 1
}).then(function (result) {
  console.log('请求成功:', result);
}).catch(function (result) {
  console.log('请求失败:', result);
})

calculateLabelPoints(options)

service/igs/GeometryServer.js, line 592

求label点

Name Type Description
options

查询参数

Name Type Description
polygons Polygon 可选

要计算的多边形,单区或多区几何,必填

success function 可选

查询成功回调函数,若使用Promise方式则不必填写

failure function 可选

查询失败回调函数,若使用Promise方式则不必填写

Example
// 回调方式
// ES5引入方式
const { Polygon } = zondy.geometry
const { Polygon,FetchMethod } = zondy.enum

// ES6引入方式
import { Polygon,FetchMethod } from "@mapgis/webclient-common"
geometryServer.calculateLabelPoints({
  polygons: new Polygon({
    coordinates: [[ [100.0, 0.0],[101.0, 0.0],[101.0, 1.0],[100.0, 1.0],[100.0, 0.0] ]]
  }),
  method: FetchMethod.post,
  success: function (result) {
    console.log('请求成功:', result);
  },
  failure: function (result) {
    console.log('请求失败:', result);
  }
});
// promise方式
geometryServer.calculateLabelPoints({
  polygons: new Polygon({
    coordinates: [[ [100.0, 0.0],[101.0, 0.0],[101.0, 1.0],[100.0, 1.0],[100.0, 0.0] ]]
  })
}).then(function (result) {
  console.log('请求成功:', result);
}).catch(function (result) {
  console.log('请求失败:', result);
})

calculateLength(options){Promise.<Object>}

service/igs/GeometryServer.js, line 199

计算线长度。

projectInfoprojectInfoBySrsID 二选一,用于指定投影参考信息。

Name Type Default Description
options Object {} 可选

查询参数。

Name Type Description
lineString LineString

待计算长度的线对象。

success function 可选

请求成功回调。

failure function 可选

请求失败回调。

projectInfo ProjectInfo 可选

投影参考信息。

projectInfoBySrsID ProjectInfoBySrsID 可选

源投影参考系 ID。

Returns:
Type Description
Promise.<Object> 长度计算结果。

calculateLengths(options)

service/igs/GeometryServer.js, line 660

求长度

Name Type Description
options

查询参数

Name Type Description
lineString LineString | MultiLineString 可选

要计算的线,必填

success function 可选

查询成功回调函数,若使用Promise方式则不必填写

failure function 可选

查询失败回调函数,若使用Promise方式则不必填写

Example
// 回调方式
// ES5引入方式
const { LineString } = zondy.geometry
const { FetchMethod } = zondy.enum

// ES6引入方式
import { LineString,FetchMethod } from "@mapgis/webclient-common"
geometryServer.calculateLengths({
  polylines: new LineString({
    spatialReference: 'EPSG:4326',
    coordinates: [[-117,34],[-116,34],[-117,33]]
  }),
  method: FetchMethod.post,
  success: function (result) {
    console.log('请求成功:', result);
  },
  failure: function (result) {
    console.log('请求失败:', result);
  }
});
// promise方式
geometryServer.calculateLengths({
  polylines: new LineString({
    spatialReference: 'EPSG:4326',
    coordinates: [[-117,34],[-116,34],[-117,33]]
  }),
}).then(function (result) {
  console.log('请求成功:', result);
}).catch(function (result) {
  console.log('请求失败:', result);
})

calculateTopologyRelation(options)

service/igs/GeometryServer.js, line 816

计算拓扑关系

Name Type Description
options

查询参数

Name Type Description
geometry1 Geometry 可选

要计算的多边形1,必填

geometry2 Geometry 可选

要计算的多边形2,必填

tolerance Number 可选

容差,必填

success function 可选

查询成功回调函数,若使用Promise方式则不必填写

failure function 可选

查询失败回调函数,若使用Promise方式则不必填写

Example
// 回调方式
// ES5引入方式
const { LineString,Polygon } = zondy.geometry
const { FetchMethod } = zondy.enum

// ES6引入方式
import { LineString,Polygon,FetchMethod } from "@mapgis/webclient-common"
geometryServer.calculateTopologyRelation({
  geometry1: new LineString({
    coordinates:  [ [117,0],[117,44] ]
  }),
  geometry2: new Polygon({
    coordinates: [[ [110.0, 5.0],[170.0, 5.0],[170.0, 20.0],[110.0, 20.0],[110.0, 5.0] ]]
  }),
  tolerance: 1,
  method: FetchMethod.post,
  success: function (result) {
    console.log('请求成功:', result);
  },
  failure: function (result) {
    console.log('请求失败:', result);
  }
});
//promise方式
geometryServer.calculateTopologyRelation({
  geometry1: new LineString({
    coordinates:  [ [117,0],[117,44] ]
  }),
  geometry2: new Polygon({
    coordinates: [[ [110.0, 5.0],[170.0, 5.0],[170.0, 20.0],[110.0, 20.0],[110.0, 5.0] ]]
  }),
  tolerance: 1
}).then(function (result) {
  console.log('请求成功:', result);
}).catch(function (result) {
  console.log('请求失败:', result);
})

calculateUnion(options)

service/igs/GeometryServer.js, line 985

求并

Name Type Description
options

查询参数

Name Type Description
geometry1 Geometry 可选

要计算的多边形1,必填

geometry2 Geometry 可选

要计算的多边形2,必填

tolerance Number 可选

容差,必填

success function 可选

查询成功回调函数,若使用Promise方式则不必填写

failure function 可选

查询失败回调函数,若使用Promise方式则不必填写

Example
// 回调方式
// ES5引入方式
const { Polygon } = zondy.geometry
const { FetchMethod } = zondy.enum

// ES6引入方式
import { Polygon,FetchMethod } from "@mapgis/webclient-common"
geometryServer.calculateUnion({
  geometry1: new Polygon({
    coordinates:  [[ [105.0, 0.0],[164.0, 0.0],[164.0, 10.0],[105.0, 10.0],[105.0, 0.0] ]]
  }),
  geometry2: new Polygon({
    coordinates: [[ [110.0, 5.0],[170.0, 5.0],[170.0, 20.0],[110.0, 20.0],[110.0, 5.0] ]]
  }),
  tolerance: 1,
  method: FetchMethod.post,
  success: function (result) {
    console.log('请求成功:', result);
  },
  failure: function (result) {
    console.log('请求失败:', result);
  }
});
// promise方式
geometryServer.calculateUnion({
  geometry1: new Polygon({
    coordinates:  [[ [105.0, 0.0],[164.0, 0.0],[164.0, 10.0],[105.0, 10.0],[105.0, 0.0] ]]
  }),
  geometry2: new Polygon({
    coordinates: [[ [110.0, 5.0],[170.0, 5.0],[170.0, 20.0],[110.0, 20.0],[110.0, 5.0] ]]
  }),
  tolerance: 1,
}).then(function (result) {
  console.log('请求成功:', result);
}).catch(function (result) {
  console.log('请求失败:', result);
})

geometryProject(options)

service/igs/GeometryServer.js, line 732

几何投影

Name Type Description
options

查询参数

Name Type Description
geometries Geometry 可选

要计算的投影几何对象,必填

inSrs String 可选

原始参考系,必填

outSrs String 可选

目标参考系,必填

success function 可选

查询成功回调函数,若使用Promise方式则不必填写

failure function 可选

查询失败回调函数,若使用Promise方式则不必填写

Example
// 回调方式
// ES5引入方式
const { LineString } = zondy.geometry
const { FetchMethod } = zondy.enum

// ES6引入方式
import { Polygon,FetchMethod } from "@mapgis/webclient-common"
geometryServer.geometryProject({
  geometries: new LineString({
    coordinates: [[-117,34],[-116,34],[-117,33]]
  }),
  inSrs: 'EPSG:4326',
  outSrs: 'EPSG:3857',
  method: FetchMethod.post,
  success: function (result) {
    console.log('请求成功:', result);
  },
  failure: function (result) {
    console.log('请求失败:', result);
  }
});
// promise方式
geometryServer.geometryProject({
  geometries: new LineString({
    coordinates: [[-117,34],[-116,34],[-117,33]]
  }),
  inSrs: 'EPSG:4326',
  outSrs: 'EPSG:3857'
}).then(function (result) {
  console.log('请求成功:', result);
}).catch(function (result) {
  console.log('请求失败:', result);
})

projectInExtent(options){Promise.<Object>}

service/igs/GeometryServer.js, line 259

对矩形范围进行投影转换。

该方法通过路径参数指定数据源与目标坐标系,并将 extent 作为请求体参数参与计算。

Name Type Description
options Object

查询参数。

Name Type Description
gdbsvrName String

数据源名称。

gdbName String

地理数据库名称。

srefID String

源投影参考系 ID。

desfID String

目标投影参考系 ID。

extent Extent

待转换的矩形范围。

userName String 可选

地理数据源/地理数据库账户名。

password String 可选

地理数据源/地理数据库密码。

failure function 可选

请求失败回调。

Returns:
Type Description
Promise.<Object> 投影转换结果。

inherited queryServerInfo(options){Promise.<Object>}

service/BaseServer.js, line 140

获取服务信息,IGS2.0新增服务

Name Type Default Description
options Object {} 可选

查询参数

Name Type Default Description
success function 可选

查询成功回调函数,若使用Promise方式则不必填写

failure function 可选

查询失败回调函数,若使用Promise方式则不必填写

Returns:
Type Description
Promise.<Object> 服务信息查询结果
Examples

获取服务信息-回调方式

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);
});

smoothLineString(options)

service/igs/GeometryServer.js, line 918

计算光滑曲线,igs1.0服务

Name Type Description
options

查询参数

Name Type Description
type Number 可选

插值方式,0为二次样条、1为三次样条、2为三次Beizer样条、3为三次B样条,必填

lineString LineString 可选

要计算的线几何,必填

success function 可选

查询成功回调函数,若使用Promise方式则不必填写

failure function 可选

查询失败回调函数,若使用Promise方式则不必填写

tolerance Number 可选

step