一、Query.js
/**
* @param {object} service {name,layerId}
*/
class Query {
/* 属性查询 */
static queryBySQL({
where,
service,
querySuccess
}) {
//1-1设置查询结构
const queryStruct = new Zondy.Service.QueryFeatureStruct();
queryStruct.IncludeGeometry = true;
queryStruct.IncludeWebGraphic = true
const queryParam = new Zondy.Service.QueryParameter({
struct: queryStruct
})
queryParam.where = where
/* 1-3、调用查询服务 */
const queryService = new Zondy.Service.QueryDocFeature(
queryParam,
service.name,
service.layerId, {
ip: 'localhost',
port: 6163
}
)
queryService.query(querySuccess)
}
}
二、例子
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
<script src="./dist/include-openlayers-local.js"></script>
<script src="./js/TIAN.js"></script>
<script src="./edit/Query.js"></script>
</head>
<body>
<input type="text" id="sql">
<button onclick="query()">属性查询</button>
<div id="map_container">
</div>
<script>
var docLayer = new Zondy.Map.Doc('','city',{
ip:'localhost',
port:6163
})
var map = new ol.Map({
target:"map_container",
layers:[gaodeMapLayer,docLayer],
view:new ol.View({
projection:'EPSG:4326',
center:[114.30,30.50],
zoom:4
})
})
function query(){
var name = document.getElementById("sql").value;
Query.queryBySQL({
where:name,
service:{
name:"city",
layerId:0
},
querySuccess
})
}
function querySuccess(result){
var format = new Zondy.Format.PolygonJSON();
var features = format.read(result);
console.log(features)
}
</script>
</body>
</html>