0

I'm working on an app using OpenLayers 3 with PostgreSQL/PostGIS tables and views, and an Esri basemap.

The web app loads a set of features using an array of attributes from PostGres table (a view) and a cql filter. then zooms to the extent of the collected features. All this works as expected. The problem happens when I zoom out after the features are loaded...if I zoom out more than a few levels, the extent suddenly jumps back to the initial extent of the features when loaded.

Here is (what I think is) the relevant code below... I am not getting any errors in console; the fetching and loading of the features looks ok from what I can see.

var map = new ol.Map({
  layers: [
  new ol.layer.Tile({
    source: new ol.source.TileArcGISRest({
      url: 'http://server:6080/arcgis/rest/services/basemap/MapServer',
  })
})
],
  overlays: [overlay],
  target: document.getElementById('map'),
  view: new ol.View({
    center: ol.proj.fromLonLat([lon, lat]),
    minZoom: 11,
    zoom: 15,
    maxZoom: 20
  })
});

...

var locExtent = ol.extent.createEmpty();
layerWFS = new ol.layer.Vector({
      source: new ol.source.Vector({
          loader: function (extent) {
              $.ajax('http://geoserver:8080/geoserver/wfs', {
                  type: 'GET',
                  data: {
                      service: 'WFS',
                      version: '1.1.0',
                      request: 'GetFeature',
                      typename: 'all_features_search',
                      srsname: 'EPSG:3857',
                      outputFormat: 'application/json',
                      CQL_FILTER: "attribute IN " + tostring
                  }
              }).done(function (response) {
                  layerWFS
                  .getSource()
                  .addFeatures(new ol.format.GeoJSON()
                  .readFeatures(response));
                  layerWFS.set('name', 'search_layer');
                  //
                  var radius = 100;
                  var  locExtent = layerWFS.getSource().getExtent();
                  locExtent = ol.extent.buffer(locExtent, radius);
                  ol.proj.get('EPSG:4326'), ol.proj.get('EPSG:3857'));
                  map.getView().fit(locExtent, map.getSize());
                  var theseFeatures = layerWFS.getSource().getFeatures();
                  for (var i = 0; i < theseFeatures.length; i++) {
                    var featureWKT = theseFeatures[i].get('wkt');
                    var featureType = 
                    featureWKT.substr(0,featureWKT.indexOf('('));
                    // there are both point and line features in view
                    if (featureType == "POINT"){
                      theseFeatures[i].setStyle(pointStyle);
                    } else { // MULTILINESTRING
                      theseFeatures[i].setStyle(lineStyle);
                    }

                  }
              });
          },
          strategy: ol.loadingstrategy.bbox,
          projection: 'EPSG:3857',
          crossOrigin: 'anonymous',

      })
    });

  map.addLayer(layerWFS);
0

the good people at Boundless helped me find the solution:

I changed strategy: ol.loadingstrategy.bbox

to strategy: ol.loadingstrategy.all

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.