一、基于坐标的查询
1-1 步骤
1、加载地图
2、创建点查询(地图文档点查询)
3、显示查询结果
1-2 示例
核心api
new Zondy.Service.QueryFeatureStruct
new Zondy.Service.QueryFeatureRule
new Zondy.Service.QueryParameter
new Zondy.Service.QueryDocFeature
<!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>
<button onclick="queryByPoint()">查询</button>
<div id="map_container"></div>
<script>
var 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
})
})
function queryByPoint(){
//1、创建一个用于查询的点形状
var pointObj = new Zondy.Object.Point2D(114.47,31);
//设置查询点的搜索半径
pointObj.nearDis = 0.1
//2、初始化查询结构对象,告诉服务端查询结果中应该包含哪些信息
var queryStruct = new Zondy.Service.QueryFeatureStruct()
//是否包含几何图形信息
queryStruct.IncludeGeometry = true;
//是否包含属性信息
queryStruct.IncludeAttribute = true;
//是否包含图形显示参数
queryStruct.IncludeWebGraphic = true;
//3、创建查询规则
var rule = new Zondy.Service.QueryFeatureRule({
//是否将要素的可见性计算在内
EnableDisplayCondition:false,
//是否完全包含
MustInside:false,
//是否仅比较要素的外包矩形
CompareRectOnly:false,
//是否相交
Intersect:true
})
//4、实例化查询参数对象
var queryParam = new Zondy.Service.QueryParameter({
geometry:pointObj,
resultFormat:'json',
struct:queryStruct,
rule:rule
})
//5、实例化地图文档查询服务对象
var queryService = new Zondy.Service.QueryDocFeature(
queryParam,
'p1_city',
'2',{
ip:'localhost',
port:'6163'
}
)
queryService.query(querySuccess,queryError)
}
function queryError(e){
console.log(e)
}
function querySuccess(result){
console.log(result)
//初始化Zondy.Format.PolygonJSON类
var format = new Zondy.Format.PolygonJSON()
//将MapGIS要素JSON反序列化 ol.Feature类型数组
var features = format.read(result)
console.log(features)
}
</script>
</body>
</html>