// And标签相当于&& 满足标签内的所有条件才查询
// Or相当于|| 满足过滤条件中的任何一个就可查询
var filter = `
<Filter>
<And>
<PropertyIsEqualTo>
<PropertyName>NAME</PropertyName>
<Literal>${roadname}</Literal>
</PropertyIsEqualTo>
</And>
</Filter>
`
$.ajax({
type: "post",
url:"http://xxxx/geoserver/xxx/ows?service=WFS&version=1.0.0&request=GetFeature&typeName=xxx&maxFeatures=10000&outputFormat=application%2Fjson",
dataType: "json",
contentType: "application/x-www-form-urlencoded;charset=utf-8",
async: true,
data: {
filter: filter
},
success: function (data) {
if(data.features.length == 0){
alert("暂无查询结果")
}else{
var features = new ol.format.GeoJSON().readFeatures(JSON.stringify(data));
searchRoad.getSource().addFeatures(features);
}
}
});