dojo 图层查询成功后立即显示信息窗口

nukf8bse  于 2022-12-16  发布在  Dojo
关注(0)|答案(1)|浏览(146)

我有一个Web应用程序,用户可以在160层之间切换,其中大部分是特征层,但也有一些是ArcGISDynamicMapServiceLayer类型。
我需要能够像查询FeatureLayers一样查询这些图层:通过点击Map上的任意点并显示信息窗口。
这是我到目前为止的代码(为清晰起见删除了一些代码):

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回调的内部。如果我取消注解并使用graphic.setInfoTemplate(infoTemplate);,结果是彩色的,第二次单击时会弹出一个信息窗口。这种方法有两个问题:
1.需要2次点击
1.我无法单击折线和点两次,因此此处未弹出信息窗口。
这就是为什么我添加了一个圆圈来获得一个半径为100米的缓冲区。现在我想立即返回一个信息窗口。在这一点上,我正在努力成功地创建一个信息窗口,它是立即显示。
当前,行scope.map.infoWindow.setContent(graphic.attributes);抛出错误Failed to execute 'appendChild' on 'Node': parameter 1 is not of type 'Node'.
如何创建该信息窗口?

lmvvr0a8

lmvvr0a81#

我找到了一种合适的方法,这为改进留下了空间。但这是另一次迭代。

//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对象。
第二个值得注意的变化是,我们不再设置infoWindow的内容,而是使用infoWindow.setFeatures(selectedFeatures)设置所选要素。设置infoWindow的内容,但不选择要素,会隐藏信息窗口的操作列表,这会妨碍您缩放到对象或执行其他自定义操作。此外,这还使您能够(或我)在infoWindow中查看多个结果,而不是只查看一个。

相关问题