ArcGIS API for JavaScript 学习之 identifyTask

//Identify查询
function initIdentify() {
    require(
       [
"esri/map",
"esri/InfoTemplate",
"esri/layers/ArcGISDynamicMapServiceLayer",
"esri/symbols/SimpleFillSymbol",
"esri/symbols/SimpleLineSymbol",
"esri/tasks/IdentifyTask",
"esri/tasks/IdentifyParameters",
"esri/dijit/Popup",
"dojo/_base/array",
"esri/Color",
"dojo/dom-construct",
"dojo/domReady!"
       ],
   function (
Map, InfoTemplate, ArcGISDynamicMapServiceLayer, SimpleFillSymbol,
SimpleLineSymbol, IdentifyTask, IdentifyParameters, Popup,
arrayUtils, Color, domConstruct
) {
       var identifyURL = "http://119.163.121.32:6080/arcgis/rest/services/kjgk/MapServer";
        
       identifyTask = new IdentifyTask(identifyURL);
       identifyParams = new IdentifyParameters();
       identifyParams.tolerance = 3;
       identifyParams.returnGeometry = true;
       identifyParams.layerIds = [0, 1, 2, 3];
       identifyParams.layerOption = IdentifyParameters.LAYER_OPTION_ALL;
       identifyParams.width = map.width;
       identifyParams.height = map.height;
       map.on("click", doIdentify);

       function doIdentify(event) {
           //Identify的geometry
           identifyParams.geometry = event.mapPoint;
           // Identify范围
           identifyParams.mapExtent = map.extent;
           var deferred = identifyTask.execute(identifyParams).addCallback(function (response) {
               return arrayUtils.map(response, function (result) {
                   var feature = result.feature;
                   var layerName = result.layerName;
                   feature.attributes.layerName = layerName;
                   if (layerName === 'SDE.heat') {
                       var heatTemplate = new InfoTemplate("属性信息",
                           "矿井编号:${KJBH}</br>矿井名称:${KJMC}</br>矿井类型:${KJLX}");
                       feature.setInfoTemplate(heatTemplate);
                   } else if (layerName === 'SDE.geo') {
                       var geoTemplate = new InfoTemplate("属性信息", "编号:${BH}");
                       feature.setInfoTemplate(geoTemplate);
                   } else if (layerName === 'SDE.dh') {
                       var dhTemplate = new InfoTemplate("属性信息", "编号:${ID}");
                       feature.setInfoTemplate(dhTemplate);
                   } else if (layerName === 'SDE.ckq') {
                       var ckqTemplate = new InfoTemplate("属性信息", "编号:${KJBH}");
                       feature.setInfoTemplate(ckqTemplate);
                   }
                   return feature;
               });
           });
           map.infoWindow.setFeatures([deferred]);
           map.infoWindow.show(event.mapPoint);
       }
   });
}    

事件触发调用即可。

posted @ 2015-12-25 16:31  蓝汐  阅读(1233)  评论(0编辑  收藏  举报