1

I would like to refresh the WFS source of my Vector layer in OpenLayers 4 automatically. I have linestrings is stored in PostGIS 2.3 (it has 2 field: ID(pk) and geom(geometry)). The data is updated in real time. New inserts and sometimes updates (ST_AddPoint) in about every half seconds or more often. The data is published with Geoserver 2.12. I'm using OpenLayers 4 to show the data on map.

Now, the problem is that the OL reloads the data continuously when the WFSrefresh function is called, so the lines are "flashing".

The goal is to not refresh the whole layer, just add the newest inserted objects to the map after the SQL insert (or update). How can I do this feature in OpenLayers?

The code:

        var vectorSource = new ol.source.Vector({
            loader: function (extent) {
                $.ajax('http://localhost:8082/geoserver/test/ows', {
                    type: 'GET',
                    data: {
                        service: 'WFS',
                        version: '1.1.0',
                        request: 'GetFeature',
                        typename: 'wfs_geom',
                        srsname: 'EPSG:3857',
                        bbox: extent.join(',') + ',EPSG:3857'
                    }
                }).done(function (response) {
                                        vectorSource2.addFeatures(formatWFS.readFeatures(response))
                });
            },
            strategy: ol.loadingstrategy.bbox,
            extractStyles: true,
            projection: 'EPSG:3857'
        });
            function WFSrefresh() { vectorSource.clear(); vectorSource.addFeatures(vectorSource.readFeatures()) }

Your Answer

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

Browse other questions tagged or ask your own question.