From 8d9c17cd5166ad31e3357070e95ee73002f34de5 Mon Sep 17 00:00:00 2001 From: 徐旺旺 <11530253@qq.com> Date: 星期二, 11 五月 2021 10:44:10 +0800 Subject: [PATCH] 查询分页 --- src/components/helpers/WfsHelper.js | 66 ++++++++++++++++++++++++++++---- 1 files changed, 57 insertions(+), 9 deletions(-) diff --git a/src/components/helpers/WfsHelper.js b/src/components/helpers/WfsHelper.js index 64a6dd3..2ea5c7e 100644 --- a/src/components/helpers/WfsHelper.js +++ b/src/components/helpers/WfsHelper.js @@ -1,37 +1,78 @@ /** * 鍔犺浇WMS,鎷兼帴FILTER,LAYERS鍙傛暟绛� */ +import { WFS_URL } from '../../conf/Constants' function WfsHelper () { this.filters = [] this.typeNames = [] - this.url = 'http://xearth.cn:6289/server/ogcserver/PipeLine/wfs' + this.url = WFS_URL + this.page = 1 + this.pageSize = 10 this.params = { REQUEST: 'getfeature', - OUTPUTFORMAT: 'JSON', - maxFeatures: 20000, - version: '1.0.0' + OUTPUTFORMAT: 'application/json', + maxFeatures: 10, + version: '1.0.0', + startIndex: 0 + } + + this.setTypeName = (typeName) => { + this.typeNames = typeName + } + + this.clearFilter = () => { + this.filters = [] } this.addTypeName = (typeName) => { this.typeNames.push(typeName) } - this.appendEquals = (property, literal) => { - var filter = '<PropertyIsEqualTo><PropertyName>' + property + '</PropertyName><Literal>' + literal + '</Literal></PropertyIsEqualTo>' + this.addEquals = (property, equals) => { + // var filter = '<PropertyIsEqualTo><PropertyName>' + property + '</PropertyName><Literal>' + literal + '</Literal></PropertyIsEqualTo>' + var filter = property + '=' + equals this.filters.push(filter) } + this.addLike = (property, literal) => { + // if (property && literal) { + // var filter = '<PropertyIsLike><PropertyName>' + property + '</PropertyName><Literal>*' + literal + '*</Literal></PropertyIsLike>' + // this.filters.push(filter) + // } + var filter = property + ' like \'%' + literal + '%\'' + this.filters.push(filter) + } + + /** + * 寰楀埌filter鍙傛暟鍊� + * @returns {string|null} + */ this.getFilterParams = () => { - var head = '<Filter xmlns="http://www.opengis.net/ogc">' + /* var head = '<Filter xmlns="http://www.opengis.net/ogc">' var end = '</Filter>' var filter = '' if (this.filters.length > 0) { for (var i = 0; i < this.filters.length; i++) { filter += this.filters[i] } + // 褰撴潯浠舵暟 > 1鏃讹紝闇�瑕佺敤and鏍囩鍖呰9 + if (this.filters.length > 1) { + return ('FILTER=' + head + '<And>' + filter + '</And>' + end) + } return ('FILTER=' + head + filter + end) + } */ + var filter = '' + if (this.filters.length > 0) { + filter = 'CQL_FILTER=' + for (var i = 0; i < this.filters.length; i++) { + filter += this.filters[i] + if (i !== this.filters.length - 1) { + filter += ' AND ' + } + } + return filter } - return null + return filter } this.getUrlParams = () => { @@ -46,7 +87,8 @@ if (filterParam) { params += '&' + filterParam } - return encodeURI(params) + // return encodeURI(params) + return params } this.getUrl = () => { @@ -58,6 +100,12 @@ } return url + this.getUrlParams() } + + this.setPage = (page) => { + const startIndex = page * this.pageSize + this.params.startIndex = startIndex + this.page = page + } } export default WfsHelper -- Gitblit v1.8.0