派生自 wuyushui/SewerAndRainNetwork

徐旺旺
2021-05-13 0a36d001d1be497d50e30b43abb9e02d36037f6e
src/components/helpers/WfsHelper.js
@@ -1,29 +1,44 @@
/**
 * 加载WMS,拼接FILTER,LAYERS参数等
 */
import MapConfig from '../../conf/MapConfig'
import { WFS_URL } from '../../conf/Constants'
function WfsHelper () {
  this.filters = []
  this.typeNames = []
  this.url = MapConfig.BLUEMAP_HOST + '/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) => {
    this.typeNames = typeName
  }
  this.clearFilter = () => {
    this.filters = []
  }
  this.addTypeName = (typeName) => {
    this.typeNames.push(typeName)
  }
  this.addEquals = (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) => {
    var filter = '<PropertyIsLike><PropertyName>' + property + '</PropertyName><Literal>*' + literal + '*</Literal></PropertyIsLike>'
    // 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)
  }
@@ -32,7 +47,7 @@
   * @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) {
@@ -44,8 +59,19 @@
        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 = () => {
@@ -60,7 +86,8 @@
    if (filterParam) {
      params += '&' + filterParam
    }
    return encodeURI(params)
    // return encodeURI(params)
    return params
  }
  this.getUrl = () => {
@@ -72,6 +99,16 @@
    }
    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
  }
}
export default WfsHelper