评估ArcGIS JavaScript弹出模板中的动态变量和特征层

发布于 2025-01-28 07:00:44 字数 1147 浏览 5 评论 0原文

我正在使用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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

九局 2025-02-04 07:00:44

如果要使用JS变量,请将函数传递到content属性,而不是使用expressionInfos

content: (evt) => {
    // the variable "evt" contains info on the clicked feature, possibly useful below
    return `<table>
      <tr>
        <td><img class="esri-popup__custom-image imageTrim" width="75" src="http://some.fully.qualified.url/path/image-${randomJSVariable}.png" /></td>
      </tr>             
    </table>`;
}, 

请参阅文档有关更多信息:

函数 - 内容可以使用JavaScript函数定义,该函数返回上述任何元素。 当您的弹出窗口需要其他处理或功能时,这与上述四种内容类型所提供的功能很有用。

If you want to use JS variables, pass a function to the content property instead of using expressionInfos:

content: (evt) => {
    // the variable "evt" contains info on the clicked feature, possibly useful below
    return `<table>
      <tr>
        <td><img class="esri-popup__custom-image imageTrim" width="75" src="http://some.fully.qualified.url/path/image-${randomJSVariable}.png" /></td>
      </tr>             
    </table>`;
}, 

See the documentation for more information:

function - Content may be defined with a JavaScript function that returns any of the above-mentioned elements. This is useful when your popup requires additional processing or functionality than what is provided with the four content types listed above.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文