地图经常会用到查询功能,比如用户可能需要在地图上使用类似框选之类的的操作,显示该区域范围内的目标。
首先说说查询的思路:
1:对图层A上的点先全部隐藏;
var graphicLayer = map.getLayer("A");
map.addLayer(graphicLayer);
//做循环添加点,并且添加到全局变量graphics数组中
graphicLayer.add(graphic);
graphics.push(gra);
for(var i=0;i<graphics.length;i++){
graphics[i].hide();
}
2:使用绘图工具esri.toolbars.Draw,以便用户框选;
var tb = new esri.toolbars.Draw(map);
tb.activate(esri.toolbars.Draw.EXTENT);
dojo.connect(tb, "onDrawEnd", findPointsInExtent);
3:在绘图的结束事件onDrawEnd中遍历所有点
function findPointsInExtent(extent) {
dojo.forEach(graphics,function(graphic){ //graphics作为全局变量,表示图层上所有点的数组
if (extent.contains(graphic.geometry)) {
graphic.show();
}
});
}
以上便可以实现简单的空间查询功能。