[qgis-qwc2] Filtering features, client side

Guglielmo Raimondi guglielmo.raimondi at gmail.com
Thu Apr 28 01:16:46 PDT 2022


Hi everyone,
I would like to filter the features of a layer based on a filter decided by
the user, on the client side, which produces a list of primary key
identifiers corresponding to the features to be displayed.

In my code, I build the list with a database query written in *php *and I
would like to pass the filter to qwc2 with a procedure written in
*javascript*.

At the moment I was only able to calculate the bounding box of the
selection of filtered objects and to command the zoom to the same extent on
qwc2, using the *window.qwc2.zoomToExtent ()* function.
Is there a procedure to also control the features filter?

Assuming that:

   - *$filter* variable contains the filter decided by the user;
   - the frame containing qwc2 is "*gfx*";
   - *s_bene_tutelato* is the layer to be filtered, offered by a Qgis
   Server and based on the homonymous table of a PostgreSQL + PostGIS database

, this is my code:

    $str_sql =
"SELECT '[' || replace(replace(substring(ST_Expand(ST_Extent(ST_Transform(geom,
32632)), 10000)::text from 5 for 100), ' ', ','), ')', ']')  FROM
public.s_bene_tutelato"
;
    if (strlen($filter) > 0) {
        $str_sql = $str_sql . " where " . $filter;
    }
    $filter_extent = ExecuteScalar($str_sql);

    ?> <script type="text/javascript">
        var layer = {
            id: "myselectionlayer",
            role: top.gfx.window.qwc2.LayerRole.SELECTION
        };
        top.gfx.window.qwc2.removeLayer("myselectionlayer");
        top.gfx.window.qwc2.zoomToExtent(<?=$filter_extent;?>, "EPSG:32632"
);
    </script> <?php


Thanks for the attention,
Guglielmo
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.osgeo.org/pipermail/qgis-qwc2/attachments/20220428/22fc47e0/attachment.html>


More information about the qgis-qwc2 mailing list