1.多边形查询:在地图中绘制某一范围后,对某一图层进行空间查询并高亮显示查询的要素。
2.主要使用的方法:
- IFeauterLayer.ExecuteSpatialQuery();此方法对图层进行空间查询,缺点:大面积查询的时候会很慢,
- IFeature65.Tint 属性设置要素的表面颜色
3.绘制函数的代码见前面的章节,下面是绘制后查询的主要代码:
function QueryByPolygon() {
Draw.onDrawCompleted = onDrawCompleted;
ClearBuffer();
Draw.Polygon();
}
function onDrawCompleted(geo) {
var sSuccess = "返回地物成功";
if (geo == undefined || geo == null) {
sSuccess = "返回地物失败";
alert("绘制完成," + sSuccess);
}
else {
//var area=geo.Area;
//alert("绘制完成,面积为:" + area+" 平方米");
//获取查询的图层
var selectLayer = $('selectLayer');
var slectedIndex = selectLayer.selectedIndex;
var selLyrName = selectLayer.options[slectedIndex].text;
var selLayer = ProjectTree.playersInfo[selLyrName];
//ExecuteSpatialQuery( pIGeometry,IntersectionType)
//IntersectionType=0:none;=1:intersect;=2:within
var features = selLayer.ExecuteSpatialQuery(geo, 1);
lastQueryFeatures = features;
var containerRestult = document.getElementById("result");
showReslts(features, containerRestult);
}
function showReslts(features,container) {
if (features == null) return;
var fcolor = NewColor(255, 0, 0, 100);
var restStr = "<table>";
for (var i = 0; i < features.Count; i++) {
restStr += "<tr>";
var feature = features.Item(i);
feature.Tint = fcolor;
for (var j = 0; j < feature.FeatureAttributes.Count; j++) {
var featureAttribute = feature.FeatureAttributes.Item(j);
restStr += "<td>" + featureAttribute.Name + "*" + featureAttribute.Value + "</td>";
}
restStr += "</tr>";
}
restStr += "</table>";
if (container != null) {
container.innerHTML = restStr;
}
}
}
function NewColor(r, g, b, a) {
var sgworld = document.getElementById('sgworld');
return sgworld.Creator.CreateColor(r, g, b, a);
}
var lastQueryFeatures = null;
function ClearBuffer() {
Draw.Clear();
if (lastQueryFeatures!=null) {
for (var i = 0; i < lastQueryFeatures.Count; i++) {
var feature = lastQueryFeatures.Item(i);
feature.Tint = NewColor(0, 0, 0, 0);
}
}
}
4.效果展示