一、步骤
1、设置查询结构
2、设置查询条件
3、调用查询服务
二、例子
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
<script src="../lib/include-openlayers-local.js"></script>
<script src="../js/Gaode.js"></script>
</head>
<body>
<input type="text" id="sql" />
<button onclick="queryBySQL()">属性查询</button>
<div id="map_container"></div>
<script>
const docLayer = new Zondy.Map.Doc('', 'p1_city', {
ip: 'localhost',
port: '6163'
})
const map = new ol.Map({
target: "map_container",
layers: [gaode, docLayer],
view: new ol.View({
center: [114, 30],
projection: 'EPSG:4326',
zoom: 4
})
})
/*
1、创建属性查询
- 1-1、设置查询结构
- 1-2、设置查询参数where条件
- 1-3、调用查询接口
- 1-4、设置回调
*/
function queryBySQL(){
//1-1设置查询结构
const queryStruct = new Zondy.Service.QueryFeatureStruct();
queryStruct.IncludeGeometry = true;
queryStruct.IncludeWebGraphic = true
//1-2 设置查询参数where条件
//实例化查询参数对象
const queryParam = new Zondy.Service.QueryParameter({
struct: queryStruct
});
const name = document.getElementById("sql").value;
queryParam.where = name;
//1-3 调用查询服务器
const queryService = new Zondy.Service.QueryDocFeature(
queryParam,
'city',
0,
{
ip:'localhost',
port:6163
}
)
queryService.query(querySuccess)
}
function querySuccess(result){
console.log(result)
}
</script>
</body>
</html>
输入框中输入 name=”武汉” 进行查询
:::success
// queryParam.where = name like '%${name}%'
:::
三、查询到的要素高亮显示
var source = new ol.source.Vector({
wrapX: false
});
var highLightLayer = new ol.layer.Vector({
source,
style: new ol.style.Style({
image: new ol.style.Circle({
radius: 17,
/* 填充色 */
fill: new ol.style.Fill({
color: '#ffcc33'
}),
/* 描边 */
stroke: new ol.style.Stroke({
color: '#ff2d51',
width: 2
})
})
})
})
map.addLayer(highLightLayer);
function querySuccess(result) {
source.clear();
//初始化Zondy.Format.PolygonJSON类
var format = new Zondy.Format.PolygonJSON()
//将MapGIS要素JSON反序列化 ol.Feature类型数组
var features = format.read(result)
console.log(features)
if (features) {
source.addFeatures(features);
}
}