javascriptnode.jsopenlayerswfs

Is it possible to use WFS.writeTransaction on the server side of a node application


I have a node application that traces a route on a road network and is returned in a JSON format. I have created on OpenLayers feature from the JSON object and I want to save this feature into an OpenLayers v9 layer using WFS-T. This processing is all occurring on the server side. There is no map interface. When I call the WFS.writeTransaction() function I get TypeError: Cannot read properties of undefined (reading 'createElementNS')

I have done this successfully previously, but It has always been on the client side and with a map interface.

The code below is from the ol/xml.js file and seems to indicate there should be a document available

export function createElementNS(namespaceURI, qualifiedName) {
   return getDocument().createElementNS(namespaceURI, qualifiedName);
}

My question is is it possible to create a document on the server side so this writeTransaction method will succeed?


Solution

  • Obviously the code that you call makes use of the DOM:

    https://developer.mozilla.org/en-US/docs/Web/API/Document/createElementNS

    Document.createElementNS()
    

    Running parts of OpenLayers on the server-side is a daunting task and although it is possible in some cases - by using jsdom to provide a mock interface to the DOM - I definitely recommend you to avoid it.