popup - 向弹出模板添加 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。关于如何为这个绝望的人进行的任何指示?:)
解决方案
推荐阅读
- python - 如何使用 Python 从一行文本中提取所需的文本?
- java - 在不导致消息排队的情况下降低 Kafka 消费者的吞吐量?
- c# - 后台服务中的 Task.Run 意外停止工作
- flutter - Firebase数据不会在flutter中没有热重载的情况下加载
- c++ - 我们可以在菱形继承模式中只使用一种虚拟继承吗?
- php - 如何在 Laravel 7.x 中从控制器返回视图时传递 cookie?
- swift - 时间来错了,但日期很快就正确了
- javascript - 更改 NavLink 文本颜色 onClick
- azure - 与美国西部的服务总线通信时,英国南部的 Azure 功能超时
- java - 无法执行休眠查询语句?