首页 > 解决方案 > 向弹出模板添加 div

问题描述

我正在尝试添加一个 div 作为仅包含一张照片的 arcgis 弹出模板的内容。我过去一直在使用这种方法,但现在由于某种原因我无法让它工作。

var photoContentHtml = "";
photoContentHtml = "<img onerror='this.onerror=null;this.src=\'/layerimages/noimage.jpg\'' src='http://app.org/layerimages/{photo}' width='200px' height='150px'>";

这总是产生结果。我能够创建 div 并将其作为字符串分配给变量,然后将该变量用作弹出模板的内容。由于某种原因,它在这种情况下不起作用,所以现在我正在这样做,稍作修改。

var disLayer;
var photoContent = "";
var photoContentHtml = "";
var photoId;
var photo;


    // Get the screen point from the view's click event
    view.on("click", function (event) {

        view.hitTest(event).then(function (response) {

            if (response.results.length) {
                let graphic = response.results.filter(function (result) {
                // check if the graphic belongs to the layer of interest
                return result.graphic.layer === disLayer;
                })[0].graphic;

                                                
                photoId = graphic.attributes.objectid;
                                                
                $.get(getBaseUrl() + "enterprises/GetEnterprisePhoto?id=" + photoId, function (data, status) {
              
                if (data == null) {
                                                        
                    photoContent = "<img src='http://app.org/layerimages/noimage.jpg' width='200px' height='150px'>";
                    photoContentHtml = photoContent;

                    }
                    else {
                    photo = data;
                    photoContent = "<img src='http://app.org/layerimages/" + photo + "' width='200px' height='150px'>";
                    photoContentHtml = photoContent;

                    }

                });
            }
        });
    });



        //Check is the layer is queryable
        if (restService.label.includes("*")) {
            disLayer = new FeatureLayer({
            title: restService.label,
            url: restService.restServiceLink,
            outFields: ["*"], // Return all fields so it can be queried client-side
            popupTemplate: {  // Enable a popup
                title: "<b>" + restService.label + ": {" + restService.searchAndPopupFieldName + "} </b>",
                content: photoContentHtml
                }
            });
        }

但这甚至没有显示弹出模板内的 div。关于如何为这个绝望的人进行的任何指示?:)

标签: popuparcgisesri

解决方案


推荐阅读