派生自 wuyushui/SewerAndRainNetwork

徐旺旺
2021-05-10 cb85033879c74f34925a303402c1ad3e4a8646f2
src/components/helpers/WfsHelper.js
@@ -1,14 +1,14 @@
/**
 * 加载WMS,拼接FILTER,LAYERS参数等
 */
import { PIPELINE_WFS } from '../../conf/Constants'
import { WFS_URL } from '../../conf/Constants'
function WfsHelper () {
  this.filters = []
  this.typeNames = []
  this.url = PIPELINE_WFS
  this.url = WFS_URL
  this.params = {
    REQUEST: 'getfeature',
    OUTPUTFORMAT: 'JSON',
    OUTPUTFORMAT: 'application/json',
    maxFeatures: 20000,
    version: '1.0.0'
  }
@@ -17,16 +17,19 @@
    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) => {
    if (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)
    }
  }
  /**
@@ -34,7 +37,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) {
@@ -46,8 +49,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 null
      }
      return filter
    }
    return filter
  }
  this.getUrlParams = () => {
@@ -62,7 +76,8 @@
    if (filterParam) {
      params += '&' + filterParam
    }
    return encodeURI(params)
    // return encodeURI(params)
    return params
  }
  this.getUrl = () => {