2017-10-18 74 views
2

我有一个Web应用程序时,用户可以在其中某些160肥胖型层之间进行切换。其中大多数是功能层,但有些是ArcGISDynamicMapServiceLayer类型。一第二层的查询后立即显示信息窗口成功

我需要能够查询这些层一样我FeatureLayers做:通过点击地图上的任意点和显示信息窗口。

这是到目前为止我的代码(去掉了一些位为清楚起见):

executeQueryTask: function(evt, scope) { 
    //"this" is the map object in this context, so we pass in the scope from the caller, 
    //which will enable us to call the layer and map object and all the other precious widget properties 
    scope.map.graphics.clear(); 
    scope.map.infoWindow.hide(); 
    //we create a new Circle and set its center at the mappoint. The radius will be 20 meters 
    //default unit is meters. 
    var circle = new Circle({ 
     /*...*/ 
    }); 
    // draw the circle to the map: 
    var circleGraphic = new Graphic(circle, /*...*/)); 

    scope.map.graphics.add(circleGraphic); 

    var queryTask = new QueryTask(scope.layer.layer.url + "/" + scope.layer.layer.visibleLayers[0]); 
    var query = new Query(); 
    query.returnGeometry = true; 
    query.outFields = ["*"]; 
    query.geometry = circle.getExtent(); 
    var infoTemplate = new InfoTemplate().setTitle(""); 
    queryTask.execute(query, function(resultSet) { 
     array.forEach(resultSet.features, function(feature) { 
      var graphic = feature; 
      graphic.setSymbol(/*...*/)); 
      //Set the infoTemplate. 
      // graphic.setInfoTemplate(infoTemplate); 
      //Add graphic to the map graphics layer. 
      scope.map.infoWindow.setContent(graphic.attributes); 
      scope.map.infoWindow.show(evt.mapPoint, scope.map.getInfoWindowAnchor(evt.screenPoint)); 
      scope.map.graphics.add(graphic); 
     }); 
    }); 
}, 

的关键点是insise的queryTask.execute回调。如果我取消注释并使用graphic.setInfoTemplate(infoTemplate);,则结果会变为彩色,并在第二次单击时弹出一个infoWindow。 有2个问题,这种方法:

  1. 2点击需要
  2. 我无法对折线和点单击两次,所以没有在这里信息窗口弹出。

这就是为什么我添加了一个圆来获得半径为100米的缓冲区来点击我。现在我想立即返回一个infoWindow。 在这一点上,我努力成功地创建了一个立即显示的信息窗口。

目前该行scope.map.infoWindow.setContent(graphic.attributes);引发错误Failed to execute 'appendChild' on 'Node': parameter 1 is not of type 'Node'.

我怎样才能创建一个信息窗口?

回答

1

我找到了一个合适的方法,这让改进的空间。但这是另一个迭代。

//create a new FeatureLayer object 
var featureLayer = new FeatureLayer(scope.layer.layer.url + "/" + scope.layer.layer.visibleLayers[0], { 
    mode: FeatureLayer.MODE_SELECTION, 
    infoTemplate: new InfoTemplate("Attributes", "${*}"), 
    outFields: ["*"] 
}); 
//we create a new Circle and set its center at the mappoint. The radius will be 20 meters 
//default unit is meters. 
var circle = new Circle({/*...*/}); 

// draw the circle to the map: 
var circleGraphic = new Graphic(circle, /*...*/)); 
scope.map.graphics.add(circleGraphic); 

var lQuery = new Query(); 
lQuery.returnGeometry = true; 
lQuery.geometry = circle.getExtent(); 
featureLayer.queryFeatures(lQuery, function(results) { 
    array.forEach(results.features, function(feature) { 
     var graphic = feature; 
     graphic.setSymbol(/*...*/)); 

     //now that we have the feature, we need to select it 
     var selectionQuery = new Query(); 
     selectionQuery.geometry = feature.geometry; 
     featureLayer.selectFeatures(selectionQuery, FeatureLayer.SELECTION_NEW) 
      .then(function(selectedFeatures) { 
       console.info("selection complete", selectedFeatures); 
       if (!selectedFeatures.length) { 
        return; 
       } 
       scope.map.infoWindow.setFeatures(selectedFeatures); 
       scope.map.infoWindow.show(evt.mapPoint, "upperright"); 
      }); 
    }); 
}); 

这里的变化是,我们不再使用QueryTask,但在创建模式选择一个新的FeatureLayer对象,使用可见光层的地址和ID。

第二个值得关注的变化是,我们不再设置信息窗口的内容,而是设置使用infoWindow.setFeatures(selectedFeatures)选择功能。设置infoWindow的内容但不选择要素,会隐藏信息窗口的动作列表,这会阻碍您放大对象或执行其他自定义操作。 此外,这使你(或我)在信息窗口查看,而不只是一个多个结果。

+0

这是有帮助的太好了! –