效果图
![](https://img-blog.csdnimg.cn/20200411095858922.png?x-oss-process=image/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L0RhbkJvX0M=,size_16,color_FFFFFF,t_70)
1. 空间查询触发事件
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28
| query("button").on("click", function (event) { map.graphics.clear(); var value = this.innerHTML; switch (value) { case "点": { toolbar.activate(Draw.POINT, { showTooltips: true }) break; } case "线": { toolbar.activate(Draw.POLYLINE, { showTooltips: true }) break; } case "面": { toolbar.activate(Draw.POLYGON, { showTooltips: true }) break; } case "X": { toolbar.deactivate(); break; } } })
|
2. 绘图事件
1 2 3 4 5 6
| on(toolbar, "draw-complete", function (result) { toolbar.deactivate(); var params = new IdentifyParameters(); params.geometry = result.geometry; identifytask.execute(setParams(params), showIdentifyResult) });
|
3. 设置参数
1 2 3 4 5 6 7 8
| function setParams(params) { params.returnGeometry = true; params.tolerance = 3; params.layerIds = [0, 1]; params.mapExtent = map.extent; params.layerOption = IdentifyParameters.LAYER_OPTION_ALL; return params; }
|
4. 显示
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
| function showIdentifyResult(res) { console.log(res) if (res.length <= 0) { alert("未检测到") } else { var features = []; for (var i = 0; i < res.length; i++) { features[i] = res[i].feature; features[i].setInfoTemplate(new InfoTemplate({ "title": "", "content": "${*}" })); } map.infoWindow.setFeatures(features); map.infoWindow.show(enevt.mapPoint); } }
|
原文链接: http://enofeng.github.io/2021/07/22/IdentifyTask查询(附样例源码)/
版权声明: 转载请注明出处.