Closed adam-sal closed 2 years ago
Hello, thanks for the notice. I will check this
I'm improving this method and will upload a new version today, but i can't find where could be the error. I cannot find a 'forEach' anywhere close the line 1456 in any version (dist, lib, src). If you can, send me all the code you have, or at least the wfst initialization and a image of the code line throwing the error.
And why are you editing the ol-wfst.js directly? Can't you add that extra code without changing the library?
Thanks for your response.
In the meantime, there have been changes to my code. Currently i add extra code without changing the library. The new part of the code after wfst initialization:
map.addControl(wfst);
const copyButton = document.createElement('button');
copyButton.className = 'ol-wfst--tools-control-btn ol-wfst--tools-control-btn-copy';
copyButton.type = 'button';
copyButton.innerHTML = `<img src="./ol-wfst-main/ol-wfst-main/src/assets/images/copy-svgrepo-com.svg"/>`;
copyButton.title = 'Skopiuj geometrię działki';
copyButton.disabled = "disabled";
copyButton.onclick = () => {
wfst._transactWFS('insert', [feature_to_copy], wfst._layerToInsertElements);
copyButton.disabled = "disabled";
feature_to_copy = null;
map.getLayers().forEach(function (layer) {
console.log(layer.get('title'));
if (layer.get('title') != undefined && layer.get('title').includes('Warstwa terenowcy')) {
setTimeout(function(){ layer.getSource().refresh(); }, 500);
}
});
};
When i click the button i receive this error: ol-wfst.ts:1702 Cannot read properties of undefined (reading 'forEach') ` * @param feature
feature_to_copy is the ol.Feature created basis on WKT Polygon with no properties
Despite the error, the WFS transaction executes and the feature is added to WFS-T.
I made some changes in library to avoid showing up the modal with this error, but maybe you will recognize the source of the problem.
Send me the new Wfst({...})
section of your code
const wfst = new Wfst({
geoServerUrl: 'http://10.0.10.10:8080/geoserver/openlayers/wms',
geoServerAdvanced: {
getCapabilitiesVersion: '1.3.0',
getFeatureVersion: '1.0.0',
describeFeatureTypeVersion: '1.1.0',
lockFeatureVersion: '1.1.0',
projection: 'EPSG:3857',
},
layers: [
{
name: 'warstwaTerenowcy', // Name of the layer on the GeoServer
label: 'Warstwa terenowcy', // Optional Label to be displayed in the controller
mode: 'wfs',
wfsStrategy: 'all',
zIndex: 99,
style: style_warstwa_terenowcy_0,
namespace: "openlayers",
}
],
language: 'en',
minZoom: 1,
showUpload: true,
showControl: true,
uploadFormats: '.kml',
beforeInsertFeature: function (feature) {
return feature;
}
});
The code should be wfst.insertFeaturesTo('warstwaTerenowcy', [feature_to_copy]);
. Try that, but still i have no idea which forEach
is throwing the error (lines 1456 and 1702 do not have it).
Keep in mind that if you call private attributes and methods outside the library, these could break in next updates...
Hi,
I want to create the new button called copyButton (i'm editing ol-wfst.js) to copy feature geometry from other source. My code is:
How to add feature to WFS-T manually (using feature generated by other function, not by drawing)?
When i'm using
wfst.insertFeaturesTo(this._layerToInsertElements, [feature_to_copy]);
i receive several errors e.g.Error: Cannot read properties of undefined (reading 'forEach')
ol-wfst.ts:1456 TypeError: Cannot read properties of undefined (reading 'forEach')Despite of the received error transaction is done and feature is add.
How to avoid this error in popup?