要素本身不具有范围,但是其几何图形具有一个范围:
const extent = feature.getGeometry().getExtent()map.getView().fit(extent);
但是,到目前为止,您似乎还没有在ajax响应中获得的OpenLayers功能对象,只是一个普通的json对象。让我们对其进行转换:
var source = new ol.source.Vector({features: (new ol.format.GeoJSON({ featureProjection: "EPSG:3765" // probably not required in your case})).readFeatures(featureCollection);您无需将矢量添加到地图即可确定特定要素及其范围:
onAutocomplete: function(txt) { var feature = source.getFeatures().find(function(f) { return f.get('JLS_IME') === txt; }); if (feature) { const extent = feature.getGeometry().getExtent() map.getView().fit(extent); }};


