I have some problems with OpenLayers and a WFS vector source. It is a clustered source and it works so to speak that it adds features as it should the first time. But when I pan the map it keeps adding the same features again and again. The WFS request seems to return what it's suposed but it is like it's just adding the same features again.

The result is that if a clusterd point says that it contains 5 features, then I pan the map and the WFS correctly returns these previous 5 points and then another 2 that comes inside the extent, then the map shows 10 + 2. I would expect that it should show 5 + 2 since the 5 old features are the same as the last fetched. Any suggestion what I do wrong?

this.userMapFeatureSource = new olVectorSource({
            format: new olGeoJSON(),
            url: (extent) => {
                return this.geoserverURL + '/wfs?service=WFS&' +
                    'version=1.1.0&request=GetFeature&typename=cite:usermapsGeom&' +
                    'outputFormat=application/json&srsname=' + this.projstring + '&' +
                    'bbox=' + extent.join(',') + ',' + this.projstring;
            strategy: olBboxStrategy

    this.userMapFeatureClusterSource = new olCluster({
        distance: 36,
        source: this.userMapFeatureSource

    this.userMapFeatureLayer = new olVectorLayer({
        visible: false,
        source: this.userMapFeatureClusterSource,
        style: (feature) => {
            const size = feature.get('features').length;
            const style = new olStyle({
                image: new olIcon({
                    src: '/assets/sysimg/btn_map.png',
                    scale: 0.9
                text: new olText({
                    font: '11px sans-serif',
                    text: size + ' st',
                    textAlign: 'center',
                    fill: new olFill({ color: 'black' }),
                    backgroundFill: new olFill({ color: '#efeee9' }),
                    offsetX: 0,
                    offsetY: 20
            return style;
  • The features need an id to be used with bbox strategy, to prevent them being added repeatedly.
    – Mike
    Dec 9, 2020 at 16:48
  • Hi Yes I read something about that. But the data has a field called "id" with a unique number. But when I looked a bit closer on the result from Geoservers WFS there is a id field on the object as well. This seems to be automated generated. And if that chages for every request that would explain it.. So this might be a Geoserver question I guess.. This is the Id set by Geoserver.. "id":"usermapsGeom.fid-6ffb85cf_176438bd523_-5d89" The unique (never changing) Id from the database is in properties object Dec 9, 2020 at 17:58

1 Answer 1


I figured out what the problem was. The store in Geoserver for this layer was not a table but a view, and then the id was not recognized as a proper id. I had to create a primary key metadata table in PostGis that pointed out the id for the view, and that solved the problem.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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