Openlayers .getGeometry 未定义(多线串对象)

Openlayers .getGeometry undefined (multilinestring object)

我想 select 并使用多个下拉菜单放大地图。我想我在第二次更新时遇到了 .getgeometry 错误,因为 CQL_FILTER 到我的 URL。 当我制作第一个 selection 时,selected 功能放大。无论我勾选第二个选项中的哪个,我都会收到错误消息。

const extentyol = yollar.getFeatures().getArray()[selectyol] .getGeometry().getExtent();

我在这部分遇到错误,但在第一部分工作正常..

我不明白我哪里做错了。我的错误在哪里?

   var url = 'http://localhost:8080/geoserver/kbs/ows? service=WFS&version=1.0.0&request=GetFeature&typeName=kbs:mahalle&outputFormat=application/json&SRS=EPSG:3857';
    $.getJSON(
        url,
        function (data) {
            loadFeatures(data);
        }
    );
       function loadFeatures(data) {
        // load vector source
        mahalle.getSource().addFeatures(new ol.format.GeoJSON().readFeatures(data));

        const featuresmah = mahalle.getSource().getFeatures();
        // add select options
        $.each(featuresmah, function (key, value) {
            $('#mahalleId').append('<option value=' + value.get('objectid') + '>' + value.get('yazi') + '</option>');
        });
        $('#mahalleId').on('change', function () {
            var selected = $('#mahalleId').val();
            const extentmah = mahalle.getSource().getFeatures()[selected]
                .getGeometry().getExtent();
            map.getView().fit(extentmah, map.getSize());
           
            $.ajax({
                method: 'GET',
                url: 'http://localhost:8080/geoserver/kbs/wfs',
                data: {
                    service: 'WFS',
                    request: 'GetFeature',
                    typename: 'kbs:yollar',
                    outputFormat: 'application/json',
                    cql_filter: "mahalle_id='" + mahalleId.value + "'",
                    srsname: 'EPSG:3857'
                },
                success: function (response) {
                    yollar.getSource().addFeatures(new ol.format.GeoJSON().readFeatures(response));
                    
                    map.getView().fit(yollar.getSource().getExtent());
             

                    const featuresyol = yollar.getSource().getFeatures();

                    $.each(featuresyol, function (key, value) {
                        $('#yolId').append('<option value=' + value.get('objectid') + '>' + value.get('sokak_adi') + '</option>');
                    });

                    $('#yolId').on('change', function (e) {
                        const selectyol = $('#yolId').val();
                       
                        const extentyol = yollar.getFeatures().getArray()[selectyol]
                            .getGeometry().getExtent();
                        map.getView().fit(extentyol, map.getSize());
                        console.log(selectyol.val());
                    });
                },
                fail: function (jqXHR, textStatus) {
                    console.log("Request failed: " + textStatus);
                }
            }); 
        })
    }[enter image description here][1]

我找到了解决办法,不知道为什么,但是在使用cql_filter的时候,需要定义对象的索引到运行'.getGeometry()'函数.带有 Objectid 的 '.getGeometry' 函数不起作用。 我也没有将选中对象的索引识别为变量,我的问题解决了。