2017-10-18 20 views
2

私は、ユーザーがいくつかの160-ishレイヤーを切り替えることができるWebアプリケーションを持っています。それらのほとんどはフィーチャーレイヤーですが、一部のタイプはArcGISDynamicMapServiceLayerです。レイヤクエリーが成功した直後にインフォウィンドウを表示

フィーチャレイヤーと同じようにこれらのレイヤーをクエリできるようにする必要があります。マップ上の任意のポイントをクリックし、インフォウィンドウを表示する必要があります。

これは(明確にするためにいくつかのビットを削除し)、これまで自分のコードである:

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); 
     }); 
    }); 
}, 

キーポイントはqueryTask.executeコールバックinsiseあります。コメントを外してgraphic.setInfoTemplate(infoTemplate);を使用した場合、結果は着色され、2回目のクリックでインフォウインドウがポップアップします。 このアプローチには2つの問題があります。

  1. 2回のクリックが
  2. を必要としているが、私は二回ポリラインとポイントをクリックすることができませんので、何の情報ウィンドウがここにポップアップしません。

この理由から、半径を100mにするために円を追加しました。今すぐ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を使用していること、ありませんが、目に見える層のURLとIDを使用して、選択モードで新しいFeatureLayerオブジェクトを作成します。

2番目の注目すべき変更点は、infoWindowのコンテンツを設定しなくても、代わりにinfoWindow.setFeatures(selectedFeatures)を使用して選択した機能を設定したことです。 infoWindowのコンテンツを設定しますが、機能を選択しないと、情報ウィンドウのアクションリストが非表示になり、オブジェクトのズームや他のカスタム操作の実行が妨げられます。 さらに、これにより、infoWindow内で複数の結果を表示することができます。

+0

お役に立ちましたか? –

関連する問題