将html项添加到infoWindow - ArcGIS Javascript API 3.18

时间:2016-12-22 01:21:36

标签: javascript arcgis arcgis-js-api arcgis-server

关于使用ArcGIS Javascript API 3.18构建的Web应用程序的问题。我试图将dojo选择添加到infoWindow的标题。选择框旨在填充已识别结果的列表。我正在尝试两种不同的方式:

1)使用html:

以声明方式添加组合框
var template = new esri.InfoTemplate(layerName + "<br/><select id="id_select" data-dojo-type="dijit/form/Select"</select>,"<br/> FID : ${FID}");

组合框就在那里,但我不知道如何访问组合框以动态添加选项(通过addOptions)。我通常会做dijit.byId(“id_select”),但是考虑到它在创建之前不存在......我不知道该如何去做。

2)以编程方式 使用下面的代码,标题显示有关dijit / form / select小部件的信息(显示:[object HTML TableElement]),但不显示小部件本身。想知道是否可以使用dijitStartup()来解决这个问题,但我不知道如何使用它(目前正在尝试myTemplate.startupDijits(mySelectBox)的某些内容 - 而不是使用这些变量名称)。我尝试使用像example

这样的domConstruct
var identifyTask, identifyParams, idPoint;
var identifyResults;

require([
  "esri/dijit/Popup",
  "esri/tasks/IdentifyTask",
  "esri/tasks/IdentifyParameters",
  "dijit/form/Select",
  "dojo/dom-construct",
  "dojo/promise/all",
  "dojo/domReady!"
], function (
  Popup, IdentifyTask, IdentifyParameters, Select, domConstruct, All
) {
  var identifySelect;

  //dojo.connect(window.myMap, "onLoad", mapReady);
  mapReady(window.myMap);

  function mapReady(map) {
    dojo.connect(window.myMap, "onClick", runIdentifies);
  }

  function runIdentifies(evt) {
    identifyResults = [];
    idPoint = evt.mapPoint;
    var layers = dojo.map(window.myMap.layerIds, function (layerId) {
      return window.myMap.getLayer(layerId);
    });
    layers = dojo.filter(layers, function (layer) {
      if (layer.visibleLayers[0] !== -1) {
        return layer.getImageUrl && layer.visible
      }
    }); //Only dynamic layers have the getImageUrl function. Filter so you only query visible dynamic layers
    var tasks = dojo.map(layers, function (layer) {
      return new IdentifyTask(layer.url);
    }); //map each visible dynamic layer to a new identify task, using the layer url
    var defTasks = dojo.map(tasks, function (task) {
      return new dojo.Deferred();
    }); //map each identify task to a new dojo.Deferred
    var params = createIdentifyParams(layers, evt);

    var promises = [];

    for (i = 0; i < tasks.length; i++) {
      promises.push(tasks[i].execute(params[i])); //Execute each task
    }

    var allPromises = new All(promises);
    allPromises.then(function (r) { showIdentifyResults(r, tasks); });
  }

  function showIdentifyResults(r, tasks) {
    var results = [];
    var taskUrls = [];
    var resultNames = [];


    r = dojo.filter(r, function (result) {
      return r[0];
    });
    for (i = 0; i < r.length; i++) {
      results = results.concat(r[i]);
      for (j = 0; j < r[i].length; j++) {
        taskUrls = taskUrls.concat(tasks[i].url);
      }
    }
    results = dojo.map(results, function (result, index) {
      var feature = result.feature;
      var layerName = result.layerName;
      var serviceUrl = taskUrls[index];

      resultNames.push({
        value: result.layerName,
        label: result.layerName
      });
      feature.attributes.layerName = result.layerName;

      var identifiedList = getIdentifiedList(resultNames);
      console.log(identifiedList);

      var template = new esri.InfoTemplate();
      template.setTitle(identifiedList);
      feature.setInfoTemplate(template);

      var resultGeometry = feature.geometry;
      var resultType = resultGeometry.type;
      return feature;
    });


    if (results.length === 0) {
      window.myMap.infoWindow.clearFeatures();
    } else {
      window.myMap.infoWindow.setFeatures(results);
    }


    window.myMap.infoWindow.show(idPoint);

    identifySelect.on('change', function(evt) {
      var identIndex = identifySelect.get("value");
      console.log(identIndex);
      window.myMap.infoWindow.select(identIndex);
    });

    return results;
  }

  function getIdentifiedList(options) {
    identifySelect = new Select({
      name: "identifySelect",
      id: "id_select",
      options: options
    }, domConstruct.create("select"));
    return identifySelect.domNode;
  }

  function createIdentifyParams(layers, evt) {
    var identifyParamsList = [];
    identifyParamsList.length = 0;
    dojo.forEach(layers, function (layer) {
      var idParams = new esri.tasks.IdentifyParameters();
      idParams.width = window.myMap.width;
      idParams.height = window.myMap.height;
      idParams.geometry = evt.mapPoint;
      idParams.mapExtent = window.myMap.extent;
      idParams.layerOption = esri.tasks.IdentifyParameters.LAYER_OPTION_VISIBLE;
      var visLayers = layer.visibleLayers;
      if (visLayers !== -1) {
        var subLayers = [];
        for (var i = 0; i < layer.layerInfos.length; i++) {
          if (layer.layerInfos[i].subLayerIds == null)
          subLayers.push(layer.layerInfos[i].id);
        }
        idParams.layerIds = subLayers;
      } else {
        idParams.layerIds = [];
      }
      idParams.tolerance = 5;
      idParams.returnGeometry = true;
      identifyParamsList.push(idParams);
    });
    return identifyParamsList;
  }

});

1 个答案:

答案 0 :(得分:0)

嗨,这有点旧,但我会试一试。我希望这能回答你的问题。

因此,如果问题是访问infoWindow,您需要做的是为其创建时设置一个侦听器。

CREATE PROCEDURE
AS 
BEGIN
    DECLARE @executor 
    SET @executor = {query to find out}
END

我有一个小提琴,展示了如何在创建时访问infoWindow: https://jsfiddle.net/kreza/jpLj5y4h/