Select to view content in your preferred language

Improved support for arcgis.apps.storymap module: Block.add_content() - "fit" parameter

29
0
9 hours ago
Status: Open
Labels (2)
ATFerguson
Occasional Contributor

Adding an image to a StoryMap Briefing using the GUI automatically fits the image to the size of the Block. After adding the Image, I can inspect the items JSON with the following code:

from arcgis.apps.storymap.briefing import Briefing
briefing = Briefing('<my_briefing_id>')
briefingItem = smBriefing.save()
briefJson = briefingItem.get_data(try_json=True)

 

If I inspect the node for the Image that I added via GUI in briefJson, the 'config' property is as follows:

"config": {
  "placement": {
    "type": "fit",
    "fill": {
      "x": 0.5,
      "y": 0.5
    },
    "fit": {
      "color": "backgroundColor"
    }
  }
}

 

When adding an image to the StoryMap Briefing via the Python API, the arcgis.apps.storymap.story_content.Block.add_content() method does not offer a "fit" parameter, and the image is added to the Block at it's default size. When adding an image to a block via Python API, the config property in the image node is:

"config": {
  {
    "size":''
  }
}

 

It is cumbersome to resize images based on the block size, especially when the block size isn't immediately clear.

My idea is to add more flexibility to adding media content to blocks by offering a "fit" parameter.

 

EDIT: Upon looking into the API documentation further, I realized that I'd missed the Image.display property. Unfortunately, the size of the image that I added via API does not change, no matter what display value I set.

from arcgis.apps.storymap.briefing import Briefing
from arcgis.apps.storymap.story_content import Image, SlideLayout

myImage = Image(imagePath)
slide = briefing.add(layout=SlideLayout.SINGLE, title='Slide Title')
contentBlock = slide.blocks[0] #only 1 content block in SINGLE layout slides
contentBlock.add_content(myImage)
imageContent = contentBlock.content[0]

# Edit image after adding it to the briefing per API standard:
# "Once you create an Image instance you must add it to the story to be able to edit it further."

imageContent.display='small' #or 'float', 'wide', 'full' -> it doesn't matter, the size of the image in the output briefing slide doesen't change.
brief.save()

After saving the Brief, I am able to change the size of the image to fit in the content block via GUI by clicking image options, and selecting the radio button for Fit (do not crop). Unfortunately, I still can't find a way to do this via API.