Select to view content in your preferred language

img src in FeatureLayer popupTemplate

257
3
Jump to solution
03-04-2025 09:10 AM
JohnDMorgan
Occasional Contributor

Hello, 

I am trying to point to an img src that is a string/path on a FeatureLayer, but it always comes through as a broken image. Can anyone point me to how to get this to work? I think I must bypass the popup template class or something to this effect. Here is my code snippet:

 

 

 

const featureLayer = new FeatureLayer({
url: "https://services.arcgis.com/eoP5lsTDzcIUyaQZ/arcgis/rest/services/.../FeatureServer",
popupTemplate: {
title: "{Name}", // Field from the feature attributes
content: `
<b>Image Path:</b> {ImagePath}<br>
<a href="{ImagePath}" target="_blank">URL</a>
<img src="{ImagePath}">
`
}
})

 

 

 

 

Tags (2)
0 Kudos
1 Solution

Accepted Solutions
JohnDMorgan
Occasional Contributor
0 Kudos
3 Replies
JohnDMorgan
Occasional Contributor

This is the result I get:

JohnDMorgan_0-1741110166651.png

 

0 Kudos
JohnDMorgan
Occasional Contributor
0 Kudos
LaurenBoyd
Esri Contributor

Hi @JohnDMorgan -

In case you haven't gotten this working yet, you can use a function to format the popup content and that should get links working for you. You'll just need to pass the feature into the function so that you can access the attribute that contains the image src path.

Check out this example: https://codepen.io/laurenb14/pen/zYJqzYp 

Hope this helps!

Lauren
0 Kudos