在项目中有这样的需求。
就是 给出一个点的坐标,要求 渲染 出在某个 多边形图层中 包含这个点的 多边形
普通的做法,就是把所有的记录query出来,然后 进行如下判断
if ( polygon.contains(checkPoint))
{
console.debug(polygon);
graphic.setSymbol(sfs);
_infoGraphicsLayer.add(graphic);
}
如果使用 query的 geometry其实更有效和方便。
query.returnGeometry = true;
query.outFields = [ "*" ];
var where_string = "1=1";
console.debug(where_string);
//判断查询点是否落在这个区域内
query.geometry = checkPoint;
query.where = where_string;
queryTask = new esri.tasks.QueryTask(search_layer);
var sfs = new esri.symbol.SimpleFillSymbol(esri.symbol.SimpleFillSymbol.STYLE_SOLID,
new esri.symbol.SimpleLineSymbol(esri.symbol.SimpleLineSymbol.STYLE_SOLID,lineColor, lineWidth),
fillColor
);
queryTask.execute(query, function(result)
{
if (result.features == null || result.features.length <= 0) {
// 没有发现记录!
alert("空间数据库中没有发现数据,无法做查询");
} else {
// 发现记录
console.debug("found "+result.features.length+" records");
for ( var i = 0; i < result.features.length; i++) {
var graphic = result.features[i];
// graphic.attributes.iframe_url = params.data[i].url;
graphic.setSymbol(sfs);
_infoGraphicsLayer.add(graphic);
}
}
});