2

I am trying to load vector with the following code:

 var sourceWFS = new ol.source.Vector({
      loader: function(extent) {
       $.ajax('http://************/geoserver/Viva/ows', {
            type: 'GET',
            data: {
            service: 'WFS',
            version: '1.1.0',
            request: 'GetFeature',
            typename: 'Viva:building',
            srsname: 'EPSG:4326',
            bbox: extent.join(',') + ',EPSG:4326'

          }
        }).done(function(response) {
          sourceWFS.addFeatures(formatWFS.readFeatures(response));
        });
       },

I don`t seem to be able to get any features. I have a suspicion that I am not setting the typename right. The data is points of buildings.

The url in the geoserver preview layer is the following:

http://************/geoserver/Viva/ows?service=WFS&version=1.0.0&request=GetFeature&typeName=Viva:building&maxFeatures=50&outputFormat=text.

I have tested loading a GeoJson layer and it works without fail from the same server and data by using the url-method.

The end goal is to add a new point with WFS-t.

I got most of my code from this example:

http://jsfiddle.net/goldrydigital/h7mk0jpt/?utm_source=website&utm_medium=embed&utm_campaign=h7mk0jpt

Update:

I have changed the ol.format.WFS like follow:

var formatWFS = ol.format.WFS({
featureNS: "http://serverURL:8080/geoserver/vivadata",
featureType: "Viva:buildingType"
                                    });

and I get the following error in the console:

Uncaught TypeError: Cannot read property 'writeTransaction' of undefined at transactWFS

This is the block of code for transactWFS:

var transactWFS = function(mode, a) {
      var node;
      switch (mode) {
        case 'insert':
          node = formatWFS.writeTransaction([a], null, null, formatGML);
          break;
        case 'update':
          node = formatWFS.writeTransaction(null, [a], null, formatGML);
          break;
        case 'delete':
          node = formatWFS.writeTransaction(null, null, [a], formatGML);
          break;
      }

and this is my draw function:

var DrawControl = function(opt_options) {
        var options = opt_options || {};
        this.active = options.active || false;
        var draw = new ol.interaction.Draw({
            source: options.source,
            type: 'Point',
            geometryName: 'geom'

        });
        draw.on('drawstart', function(t) {
        buildingLayer.set('selectable',false);
      });

        //Sets building properties when addBuilding-button isclicked
        draw.on('drawend', function(t) {
        var a = t.feature;
        a.setProperties({

            prim_add: document.getElementById('inpPriAddress').value,
            sec_add: document.getElementById('inpSecAddress').value,
            tert_add: document.getElementById('inpTerAddress').value,
            build_type:document.getElementById('inpBuildingType').value,
            build_mat:document.getElementById('inpBuildingMaterial').value,
            build_own: document.getElementById('inpHouseOwner').value,
        })
        transactWFS('insert', a);
        buildingLayer.set('selectable',true);
      });
  • Check the order of coordinates in bbox, it should be latitude-longitude for EPSG:4326 if you use WFS 1.1.0. – user30184 Nov 9 '16 at 21:20
  • also your BBOX will be in the map's SRS not necessarily 4326 – Ian Turton Nov 10 '16 at 9:25
  • I am also facing same issue sir – user28536 Jul 19 '17 at 9:13
1

After long struggle and reimplementation of my Geoserver, I found the settings that allow WFS-t on the server's side.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.