直接上代码
map.on("load", initFunctionality);
function initFunctionality() {
map.on("click", doIdentify);
identifyTask = new IdentifyTask(dynamicLayerUrl);//查询
identifyParams = new IdentifyParameters();//查询参数
identifyParams.tolerance = 10;//容差范围
identifyParams.returnGeometry = true;//是否返回图形
identifyParams.layerIds = [ 0 ];//查询图层
identifyParams.layerOption = IdentifyParameters.LAYER_OPTION_VISIBLE;//设置查询的图层
//查询范围
identifyParams.width = map.width;
identifyParams.height = map.height;
}
function doIdentify(event) {
map.graphics.clear();
identifyParams.geometry = event.mapPoint;
identifyParams.mapExtent = map.extent;
identifyTask
.execute(
identifyParams,
function(results) {
var feature;
var sGeometry;
if (results.length > 0) {
for ( var i = 0; i < results.length; i++) {
feature = results[i].feature;
map.infoWindow.setTitle("标注信息");
map.infoWindow
.setContent("<span>地区:</span>"
+ feature.attributes.NAME_
+ "<br>"
+ "<span>机构:</span>"
+ feature.attributes.TYPENAME_
+ "<br>"
+ "<span>站点:</span>"
+ feature.attributes.NOTES_
+ "<br>"
+ "<span>地址:</span>"
+ feature.attributes.LOCATION_);
attachmentEditor
.showAttachments(
feature,
dynamicLayer);
map.infoWindow
.show(
feature.geometry,
map
.getInfoWindowAnchor(feature.geometry));
map.infoWindow.show();
}
}
});
}
一点点积累怕忘了都是官网的例子其实