Viglino / ol-ext

Cool extensions for Openlayers (ol) - animated clusters, CSS popup, Font Awesome symbol renderer, charts for statistical map (pie/bar), layer switcher, wikipedia layer, animations, canvas filters.
https://viglino.github.io/ol-ext/
Other
1.25k stars 462 forks source link

Search feature control only searches visible layers #986

Open Diasito opened 1 year ago

Diasito commented 1 year ago

I have a map with several layers of the same type (towns with titles), some of which appear only on a large zoom. The Search feature control works well, but it does not see objects from the layer that is not yet visible. But if you zoom in to this layer and zoom out again, these same objects will be available in the search. How to make the Search initially see all objects from all layers? My code is:

var search = new SearchFeature({
    //target: $(".options").get(0),
    source: searchSource, // I brought together several layers through searchSource.addFeature
    getTitle: function (feature) {
        var searchedTxt = feature.get('title');
        return(searchedTxt);
    },
    getSearchString : function (feature) {
        return feature.get('title')
    },
});
map.addControl (search);

search.on('select', function(e) {
    select.getFeatures().clear();
    select.getFeatures().push (e.search);
    var p = e.search.getGeometry().getFirstCoordinate();
    map.getView().animate({ 
        center: p,
        zoom: 8,
        duration: 2000,
        easing: ol.easing.easeOut,
    });
  });
mike-000 commented 1 year ago

Layers which are not visible do not load their sources. If you use the same source in a layer which is permanently visible but has opacity: 0 it should load - but beware if you are using bbox or tile strategy to load from WFS, etc. - the query may have a limit on how may features it returns and once a load attempt has been made for a region OpenLayers does not load there again even if you zoom in.