Skip to content

Commit

Permalink
Merge pull request #279 from fschmenger/replace_fetch_by_axios
Browse files Browse the repository at this point in the history
Replace fetch by axios
  • Loading branch information
JakobMiksch authored Feb 2, 2022
2 parents 0dd897c + f1c132f commit f21496b
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 13 deletions.
19 changes: 13 additions & 6 deletions src/factory/Layer.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import { bbox as bboxStrategy } from 'ol/loadingstrategy';
import { OlStyleFactory } from './OlStyle'
import { applyTransform } from 'ol/extent';
import { getTransform } from 'ol/proj';
import axios from 'axios';

/**
* Factory, which creates OpenLayers layer instances according to a given config
Expand Down Expand Up @@ -181,12 +182,18 @@ export const LayerFactory = {
}

// load data from WFS, parse and add to vector source
fetch(wfsRequest).then((response) => {
return response.text();
}).then((responseText) => {
const feats = vectorSource.getFormat().readFeatures(responseText);
vectorSource.addFeatures(feats);
});
const request = {
method: 'GET',
url: wfsRequest
};
axios(request)
.then(response => {
const feats = vectorSource.getFormat().readFeatures(response.data);
vectorSource.addFeatures(feats);
})
.catch(() => {
vectorSource.removeLoadedExtent(extent);
});
},
strategy: lConf.loadOnlyVisible !== false ? bboxStrategy : undefined
});
Expand Down
17 changes: 10 additions & 7 deletions src/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import LocaleUtil from './util/Locale';
import ObjectUtil from './util/Object';
import ColorThemeUtil from './util/ColorTheme'
import 'vuetify/dist/vuetify.min.css';
import axios from 'axios';

Vue.use(Vuetify);
Vue.use(PortalVue);
Expand Down Expand Up @@ -190,11 +191,13 @@ const createApp = function (appConfig) {

// Look in the static dir for an app-specific config file.
const configFile = 'static/app-conf' + appCtxFile + '.json';
fetch(configFile)
.then(function (response) {
return response.json().then(function (appConfig) {
createApp(appConfig);
})
}).catch(function () {
console.error('Cannot load config file: ' + configFile)
const request = {
method: 'GET',
url: configFile
};
axios(request)
.then(response => {
createApp(response.data);
}).catch(function (error) {
console.error(`Cannot load config file ${configFile}, ${error}`)
});

0 comments on commit f21496b

Please sign in to comment.