评估ArcGIS JavaScript弹出模板中的动态变量和特征层
我正在使用Arcgis JavaScript在地图上创建弹出模板。进展很棒。但是,我正在努力评估我在popuptemplate或featurelayer呼叫之外设置的变量。例如,这效果很好。一切都是静态的。
const layerOne = new FeatureLayer({
id: "feature_layer_id",
url: "https://services3.arcgis.com/myFeatureServer/0",
popupTemplate: {
title: `A Title Goes Here`,
content: `<table>
<tr>
<td><img class="esri-popup__custom-image imageTrim" width="75" src="{expression/logo_url}" /></td>
</tr>
</table>`,
expressionInfos: [
{
name: "logo_url",
title: "Logo URL",
expression: `return "http://some.fully.qualified.url/path/image.png";`
}
],
},
renderer: someRendererObj,
visible: false
});
当我尝试使其动态时,问题就会发生。例如,如何制作徽标URL动态,例如:
expression: `return "http://some.fully.qualified.url/path/image-" + randomJSVariable + ".png";`
变量RandomJsvariable
在我的JS中的其他位置设置,并且可以被引用为window.randomjsvariable
。
在这种情况下,未评估表达式,IMG呈现为断裂。有人可以建议我如何解决这个问题吗?
I'm using ArcGIS JavaScript to create popup templates on my map. It's going great. However, I'm struggling to evaluate variables that I set outside the popupTemplate or FeatureLayer calls. For example, this works quite well. Everything is static.
const layerOne = new FeatureLayer({
id: "feature_layer_id",
url: "https://services3.arcgis.com/myFeatureServer/0",
popupTemplate: {
title: `A Title Goes Here`,
content: `<table>
<tr>
<td><img class="esri-popup__custom-image imageTrim" width="75" src="{expression/logo_url}" /></td>
</tr>
</table>`,
expressionInfos: [
{
name: "logo_url",
title: "Logo URL",
expression: `return "http://some.fully.qualified.url/path/image.png";`
}
],
},
renderer: someRendererObj,
visible: false
});
The problem happens when I try to make it dynamic. For example, how about making the logo URL dynamic, such as:
expression: `return "http://some.fully.qualified.url/path/image-" + randomJSVariable + ".png";`
Variable randomJSVariable
is set elsewhere in my JS, and could be referenced as window.randomJSVariable
.
In this case the expression is not evaluated, and the img renders as broken. Can someone make a suggestion as to how I can fix this?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
如果要使用JS变量,请将函数传递到
content
属性,而不是使用expressionInfos
:请参阅文档有关更多信息:
If you want to use JS variables, pass a function to the
content
property instead of usingexpressionInfos
:See the documentation for more information: