1

This question is an exact duplicate of:

I have features in drop down list.when I select feature in drop down it is zooming to that layer.Now I wanted to highlight that zoomed feature.how can I style the zoomed feature?

can any one help me to achieve it?

here is my zooming function:

    var owsURL = "http://192.168.1.137:8080/geoserver/school/ows";
var SearchResultsLayer = new ol.layer.Vector({
    id: 'SearchResultsLayer',
    style: function (feature, resolution) {
        style.getText().setText(resolution < 5000 ? feature.get('') : '');
        return styles;
    }
});

function Zoomto(filter, SearchResultsLayer) {
    var schoolname = $('#ddlschool').val();
    alert(schoolname);
    var filter = "talukname='" + schoolname + "'";
    alert(filter);
    $.ajax({
        url: owsURL,
        type: 'GET',
        contentType: 'application/json',
        dataType: 'jsonp',
        jsonpCallback: "parseResponse",
        data: {
            typeName: "school:taluk",
            outputFormat: "text/javascript",
            service: "WFS",
            version: "1.1.0",
            request: "GetFeature",
            CQL_FILTER: filter

        },
        success: function (response) {

            var SearchResultsLayer = new ol.layer.Vector({});

            SearchResultsLayer.setSource(null);

            var searchresultssource = new ol.source.Vector({
                features: (new ol.format.GeoJSON()).readFeatures(response, {
                    featureProjection: "EPSG:3857"
                })
            });

            SearchResultsLayer.setSource(searchresultssource);
            map.getView().fit(SearchResultsLayer.getSource().getExtent(), map.getSize());

        }
    });
}

marked as duplicate by PolyGeo Jan 13 '16 at 7:32

This question was marked as an exact duplicate of an existing question.

2

You can use feature.set("key", value) to set a property on a feature. F.e. in the zoom function, do feature.set("zoomed", true) on all features.

And in your style you can of course get that key to adapt your style. So if (feature.get("zoomed")) { // add some style highlight }

It's possible the icons don't get refreshed automatically, then you need to mark them as dirty with a feature.changed() call.

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