I need to put some map markers on an OpenLayer map. The map is populated from Geoserver. I have more layers, this is one of it:

case "cite:geo_poli_intabulareNouFiltered":
            var userId = $("#loggedInUserId").val();
            layers.push(
                new ol.layer.Tile({
                    title: overlays[i].Item2,
                    type: 'overlay',
                    preload: Infinity,
                    visible: false,
                    layer: overlays[i].Item1,
                    source: new ol.source.TileWMS({
                        crossOrigin: 'anonymous',
                        url: GeoServer + "/geoserver/gwc/service/",
                        params: { 'LAYERS': overlays[i].Item1, 'VERSION': '1.1.1', 'service': 'wms', 'tiled': true, viewparams: 'UserId:' + userId },
                        serverType: 'geoserver'
                    })
                })
            );
            break;

It looks like this: enter image description here

I can filter this layer with some values from database,and the result should contain a map marker. This is how it looks after the filter: enter image description here

The result should contain a map marker, too.

This is the code that it is used for filtering, and at the end of this code I should put the map marker for the result.

  filterCondition: function () {
    var myConditions = this.composeConditions(),
        _layers,
        i,
        layer,
        source,
        layerParams,
        cql_filter,
        opacity,
        j,
        element,
        conditionSeparator,
        conditions;

    _layers = map.getLayers().getArray();
    conditionSeparator = '';

    myConditions.forEach(function (element, index, array) {
        conditions = element;
        for (i = 0; i < _layers.length; i++) {
            if ((_layers[i].get('type') == 'overlay') && _layers[i].getVisible()) {
                layer = _layers[i].get('layer');
                console.log("Layer " + layer);
                source = _layers[i].getSource();
                console.log(source);
                layerParams = source.getParams();
                console.log(layerParams);
                cql_filter = [];
                console.log(layer);
                for (j = 0 ; j < conditions.length; j++) {
                    element = conditions[j];
                    if (element['layer'] == layer) {
                        var value = $.trim(element['val'].toLowerCase());

                        console.log(value);
                        if (value == "null") {                               
                            cql_filter.push("strToLowerCase(" + element['prop'] + ") " + "is null");
                        }
                        else {
                            if (value.length > 0) {
                                if (element['cond'] === "like") {
                                    cql_filter.push("strToLowerCase(" + element['prop'] + ") " + element['cond'] + " '%" + value + "%'");
                                } else {
                                    if ($.isNumeric(value)) {
                                        cql_filter.push(element['prop'] + " " + element['cond'] + " " + value);
                                    } else {
                                        cql_filter.push(element['prop'] + " " + element['cond'] + " '" + value + "'");
                                    }
                                }
                            } else {
                                if (element['cond'] === "like") {
                                    cql_filter.push("strToLowerCase(" + element['prop'] + ") " + element['cond'] + " ''");
                                } else {
                                    cql_filter.push(element['prop'] + " " + element['cond'] + " ''");
                                }
                            }
                        }
                        conditionSeparator = element['match_condition'];
                    }
                }

                if (conditionSeparator != '') {
                    if (conditionSeparator !== 'NOT') {
                        cql_filter = cql_filter.join(" " + conditionSeparator + " ");
                    } else {
                        cql_filter = 'NOT ' + cql_filter.join(" AND ");
                    }
                } else {
                    cql_filter = cql_filter.join(" AND ");
                }
                if (cql_filter != "") {
                    console.log("The generated condition for the group #" + element['groupId'] + ": " + cql_filter);

                    /*var firstIndex = cql_filter.indexOf("'") + 1;
                    var lastIndex = cql_filter.lastIndexOf("'");
                    var initialDate = cql_filter.substring(firstIndex, lastIndex);

                    var arr = initialDate.split('/');
                    var aux = arr[0];
                    arr[0] = arr[1];
                    arr[1] = aux;
                    var newDate = arr[2] + "-" + arr[0] + "-" + arr[1];
                    cql_filter = cql_filter.replace(initialDate, newDate)*/


                    layerParams.cql_filter = cql_filter;
                    layerParams.opacity = 0.1;
                    source.updateParams(layerParams);
                    alert("filter");
                    console.log(source);

                }
            }
        }
    });

Can you advise in this case?

I have Tiled layers. I have no experience with Openlayers and Geoserver. I've tried some methods that I have founded on the net, but with no luck.

Your Answer

 

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Browse other questions tagged or ask your own question.