Select to view content in your preferred language

Popup media group from Arcade Array

584
1
Jump to solution
11-02-2022 12:45 PM
Labels (1)
ADClark
Occasional Contributor

I am trying to determine how to create a popup Media Group of images from an Arcade array of image URLs. The images are not stored as attachments, but as a list of URLs in a field. I have been able to successfully parse the list and display the images using rich text with HTML tags, but I would prefer to have the look of a media group (i.e. with forward/backward arrows).

I know that JSON for a media group is generally of the following format:

{
    "type": "media",
    "description": "",
    "mediaInfos": [
        {
            "altText": "",
            "caption": "",
            "title": "",
            "type": "",
            "value": {
                "linkURL": "",
                "sourceURL": ""
            }
        },
        {
            "altText": "",
            "caption": "",
            "title": "",
            "type": "",
            "value": {
                "linkURL": "",
                "sourceURL": ""
            }
        }.......]
}

 

Would the best approach be to simply build a JSON representation for the media group and then return the results of calling "FromJSON" on it? (https://developers.arcgis.com/arcade/function-reference/data_functions/#fromjson) Would that actually work to display a media group in the popup?  Thanks in advance for any input or ideas.

Andrew

 

0 Kudos
1 Solution

Accepted Solutions
ADClark
Occasional Contributor

I ended up coming up with the following solution, posting in case it might help anyone else:

var contents = Split($feature.photourls, ',', -1, TRUE)
var imageArray = []
if (Count(contents) > 0) {
    for (var i in contents) {
        var value = Dictionary("sourceURL", contents[i])
        var image = Dictionary("type", "image","value", value)
        Push(imageArray, image)
    }
    var imageDict = Dictionary("type","media","description", "Media Group Photos", "mediaInfos",imageArray)
    return imageDict
} else {
    return Dictionary("type","text","text","No Photos to Display")
}

View solution in original post

1 Reply
ADClark
Occasional Contributor

I ended up coming up with the following solution, posting in case it might help anyone else:

var contents = Split($feature.photourls, ',', -1, TRUE)
var imageArray = []
if (Count(contents) > 0) {
    for (var i in contents) {
        var value = Dictionary("sourceURL", contents[i])
        var image = Dictionary("type", "image","value", value)
        Push(imageArray, image)
    }
    var imageDict = Dictionary("type","media","description", "Media Group Photos", "mediaInfos",imageArray)
    return imageDict
} else {
    return Dictionary("type","text","text","No Photos to Display")
}