Skip to content

Commit

Permalink
Add methods parameter
Browse files Browse the repository at this point in the history
  • Loading branch information
volterra79 committed Nov 8, 2023
1 parent 24b8e48 commit 1beb3d3
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 25 deletions.
34 changes: 25 additions & 9 deletions src/app/gui/wms/service.js
Original file line number Diff line number Diff line change
Expand Up @@ -189,15 +189,18 @@ proto.checkIfWMSAlreadyAdded = function({
layers=[]
}={}) {
let added = false;
//get data stored on local storage
const data = this.getLocalWMSData();
//check if url id find
if (data.wms[url]) {
//check if url and layers area aready added
added = undefined !== data.wms[url]
.find(({layers:addedLayers}) => {
const layersLength = layers.length;
if (addedLayers.length === layersLength) {
return layers.reduce((accumulator, layerName) => {
return accumulator + addedLayers.indexOf(layerName) !== -1 ? 1 : 0;
},0) === layersLength;
}, 0) === layersLength;
}
})
}
Expand Down Expand Up @@ -255,15 +258,25 @@ proto.showWmsLayersPanel = function(config={}) {
/**
* Get data of wms url from server
* @param url
* @returns {Promise<{result: boolean, info_formats: [], layers: [], map_formats: [], abstract: null, title: null}>}
* @returns {Promise<{
* result: boolean,
* info_formats: [],
* layers: [],
* map_formats: [],
* methods: [],
* abstract: null,
* title: null
* }>}
*/
proto.getWMSLayers = async function(url) {
//set base schema of response
let response = {
result: false,
layers: [],
info_formats:[],
info_formats:[], //@deprecate since v3.9 (inside methods)
abstract: null,
map_formats: [],
methods: [], //@since v3.9
map_formats: [], //@deprecate since v3.9 (inside methods)
title: null
};
try {
Expand All @@ -273,10 +286,9 @@ proto.getWMSLayers = async function(url) {
},
outputs: false
});
} catch(err){
} catch(err) {
console.log(err)
}
if (response.result) return response;
return response;
};

Expand Down Expand Up @@ -318,6 +330,7 @@ proto.loadWMSLayerToMap = function({
* @param name
* @param epsg
* @param position
* @param methods
* @param layers
* @returns {Promise<void>}
*/
Expand All @@ -339,16 +352,19 @@ proto.addWMSlayer = async function({
visible,
opacity
};
if (data.wms[url] === undefined) data.wms[url] = [wmsLayerConfig];
else data.wms[url].push(wmsLayerConfig);
if (data.wms[url] === undefined) {
data.wms[url] = [wmsLayerConfig];
} else {
data.wms[url].push(wmsLayerConfig);
}
this.updateLocalWMSData(data);
try {
await this.loadWMSLayerToMap(wmsLayerConfig);
} catch(err) {
const mapService = GUI.getService('map');
mapService.removeExternalLayer(name);
this.deleteWms(name);
setTimeout(()=>{
setTimeout(() => {
GUI.showUserMessage({
type: 'warning',
message: 'sidebar.wms.layer_add_error'
Expand Down
42 changes: 26 additions & 16 deletions src/components/WMSLayersPanel.vue
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
v-if="abstract"
:message="abstract" />

<!-- LAYERS NAME -->
<label
for="g3w-wms-layers"
v-t="'sidebar.wms.panel.label.layers'">
Expand All @@ -33,6 +34,8 @@
</option>
</select>

<!-- EPSG PROJECTIONS -->

<label
for="g3w-wms-projections"
v-t="'sidebar.wms.panel.label.projections'">
Expand All @@ -49,6 +52,7 @@
</option>
</select>

<!-- NAME OF LAYER TO SAVE -->
<label
for="g3w-wms-layer-name"
v-t="'sidebar.wms.panel.label.name'">
Expand All @@ -66,6 +70,7 @@
v-t="'sidebar.wms.layer_id_already_added'">
</div>

<!-- CHOOSE LAYER POSITION ON TOP ON BOTTOM-->
<layerspositions
@layer-position-change="position=$event"
:position="position" />
Expand All @@ -91,18 +96,19 @@ export default {
name: "wmpspanel",
data() {
return {
loading: false,
position: undefined,
name: undefined,
title: null,
abstract: null,
map_formats: [],
info_formats: [],
layers: [],
selectedlayers: [],
projections: [],
epsg: null,
added: false
loading: false, //loading reactive status
position: undefined, //layer position on map
name: undefined, //name of saved layer
title: null, //title of layer
abstract: null, //abstract
map_formats: [], //map formats
info_formats: [], // info formats
methods: [], //@since v3.9
layers: [], //Array of layers
selectedlayers: [], //Selected layers
projections: [], //projections
epsg: null, //choose epsg project
added: false, //added layer (Boolean)
}
},
methods: {
Expand All @@ -116,7 +122,7 @@ export default {
name: this.name && this.name.trim() || undefined,
layers: this.selectedlayers,
epsg: this.epsg,
position: this.position
position: this.position,
};
this.added = this.$options.service.checkIfWMSAlreadyAdded(config);
if (this.added) {
Expand Down Expand Up @@ -195,14 +201,18 @@ export default {
layers,
title,
abstract,
methods, //@since v3.9
wmsurl,
} = this.$options.config;
/**
* URL of wms
*/
this.url = wmsurl;
try {
this.url = methods.GetMap.urls.find(u => 'Get' === u.type).url;
} catch(err) {
console.warn(err);
this.url = wmsurl;
}
/**
* Title of wms
*/
Expand Down

0 comments on commit 1beb3d3

Please sign in to comment.