cql_fiter

2023-07-31  本文已影响0人  xueyueshuai
<template>
  <div>
  </div>
</template>

<script>

export default {
  name: 'xys-study-cql_filter',
  data() {
    return {}
  },
  mounted() {
    let str2Unicode = (str) => {
      let unicodeStr = '';
      for (let i = 0; i < str.length; i++) {
        const char = str.charAt(i);
        const codePoint = char.charCodeAt(0);
        if (codePoint >= 0x4e00 && codePoint <= 0x9fa5) {
          // 仅处理中文字符,其他字符保持不变
          unicodeStr += `\\u${codePoint.toString(16).toUpperCase().padStart(4, '0')}`;
        } else {
          // 非中文字符保持不变
          unicodeStr += char;
        }
      }
      return unicodeStr;
    }

    let test = (str) => {
      // 处理str
      str = encodeURIComponent(str2Unicode(str))

      // 发起请求
      let url = 'http://localhost:8899/geoserver/one/ows?service=WFS&version=1.0.0&request=GetFeature&typeName=one:province&maxFeatures=1000000&outputFormat=application%2Fjson&cql_filter=' + str
      fetch(url).then(res => res.json()).then(jsonData => {
        jsonData.features.forEach(v => {
          console.log(v.properties)
        })
      })
    }

    test(`"CODE"='110000000'`)
    test(`"NAME" like '%河北%'`)
    test(`"省份名" like '%新疆%'`)
  }
}
</script>

<style lang="scss" scoped>
</style>
上一篇 下一篇

猜你喜欢

热点阅读