2017-10-18 75 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

這是有幫助的太好了! –