From b4fa7ad9c8e0051e9851c3bfbe398d5ff4cbfafe Mon Sep 17 00:00:00 2001 From: 陈泽平 <chenzeping> Date: 星期三, 19 五月 2021 16:05:39 +0800 Subject: [PATCH] Merge branch 'develop' of http://xearth.cn:6600/r/wuyushui/SewerAndRainNetwork into develop --- src/components/helpers/WfsHelper.js | 100 ++++++++++++++++++++++++++++++++++++++++++++++---- 1 files changed, 92 insertions(+), 8 deletions(-) diff --git a/src/components/helpers/WfsHelper.js b/src/components/helpers/WfsHelper.js index 64a6dd3..d590b0a 100644 --- a/src/components/helpers/WfsHelper.js +++ b/src/components/helpers/WfsHelper.js @@ -1,37 +1,106 @@ /** * 鍔犺浇WMS,鎷兼帴FILTER,LAYERS鍙傛暟绛� */ +import { WFS_URL } from '../../conf/Constants' +import { lrtrim } from '../../utils/utils' 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, + OUTPUTFORMAT: 'application/json', + maxFeatures: 10, version: '1.0.0' + } + + this.setTypeName = (typeName) => { + if (typeof typeName === 'string' || typeName instanceof String) { + const comma = typeName.indexOf(',') + if (comma >= 0) { + const typeNameArr = typeName.split(',') + for (let i = 0; i < typeNameArr.length; i++) { + this.addTypeName(lrtrim(typeNameArr[i])) + } + } + } else if (Array.isArray(typeName)) { + this.typeNames = typeName + } + } + + this.setFilter = (filter) => { + console.log(filter) + if (typeof filter === 'string' || filter instanceof String) { + const eq = filter.indexOf('=') + const lk = filter.indexOf('like') + if (eq >= 0) { + const filterArr = filter.split('=') + this.addEquals(lrtrim(filterArr[0]), lrtrim(filterArr[1])) + } + if (lk >= 0) { + const filterArr = filter.split('like') + this.addLike(lrtrim(filterArr[0]), lrtrim(filterArr[1])) + } + } else if (Array.isArray(filter)) { + this.filters = filter + } + } + + 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 +115,8 @@ if (filterParam) { params += '&' + filterParam } - return encodeURI(params) + // return encodeURI(params) + return params } this.getUrl = () => { @@ -58,6 +128,20 @@ } return url + this.getUrlParams() } + + this.setPage = (page) => { + const startIndex = page * this.pageSize + this.params.startIndex = startIndex + this.page = page + } + + this.setPageSize = (pageSize) => { + this.pageSize = pageSize + } + + this.setMaxFeatures = (maxFeatures) => { + this.params.maxFeatures = maxFeatures + } } export default WfsHelper -- Gitblit v1.8.0