dataSearch.js 1.0 KB

1234567891011121314151617181920212223242526272829303132
  1. import {WFS,GeoJSON} from 'ol/format';
  2. export default class searchWfs{
  3. constructor(filter){
  4. this.filter = filter//传入要增删改的图层数据
  5. }
  6. requestData(callback){
  7. var features = null;
  8. var featureRequest = new WFS().writeGetFeature({
  9. srsName: 'EPSG:3857',
  10. featureNS: 'Http://localhost:8084/geoserver/test',
  11. featurePrefix: 'build',
  12. featureTypes: ['shop'],
  13. outputFormat: 'application/json',
  14. filter: this.filter
  15. });
  16. console.time('aaa')
  17. fetch('http://localhost:8084/geoserver/test/ows?', {
  18. method: 'POST',
  19. body: new XMLSerializer().serializeToString(featureRequest)
  20. }).then(function (response) {
  21. return response.json();
  22. }).then(function (json) {
  23. features = new GeoJSON().readFeatures(json);
  24. callback(features);
  25. console.log(features);
  26. }).catch(console.log('查询失败'))
  27. console.timeEnd('aaa')
  28. }
  29. }