SharePoint Column Formatting – Show Map in Rich Text Field
If you haven’t taken a look at the new Column Formatting capabilities in modern SharePoint you are missing out. I wrote a blog post awhile back on how to use Column Formatting to manually execute a Flow. There are a lot of other similar examples out on Github which you can find here: https://github.com/SharePoint/sp-dev-list-formatting.
Use Case
I had a particular use case that I didn’t see an example for on GitHub. I have a SharePoint List which contains a list of Office Locations. In the list is a field called Address which is a multi-line of text field that contains the full address for the location. I want to display the address text and a map of the location above it in my SharePoint view.
While there were some examples of transforming your entire list view and showing a map using Longitude and Latitude points, there were no examples showing how to only apply the formatting to a column with an address. So if you have a similar need then this blog post is for you.
Column Formatting Basics
If you’ve used column formatting before you know that to apply it you can click the dropdown next to the column you want to format and select the “Format Column” option as seen in the screenshot below:
You might have noticed, however, that this option is missing for your Multi-line of Text fields as you see here:
This doesn’t mean that you can’t apply column formatting to Multi-line of Text fields, you just have to take some extra steps to apply it.
Getting the Map Set Up
Before we show how to apply Column Formatting to your multi-line of text field, we need to do some set up so that we can display the map on our list.
For the map functionality, I’m going to be utilizing the Bing Maps API. I like Bing because it’s easy to setup and configure and it’s free to start using. To use the API, you’ll need to create a Bing Maps account and get your API key. You can do that by going to the Bing Maps site: https://docs.microsoft.com/en-us/bingmaps
Applying the Column Formatting
To get into the screen to apply Column Formatting, click the Gear and List Settings to get into the settings screen:
Next, find your multi-line of text field in the list of columns and select it:
Take a look at the column settings and make sure that your column is set to PLAIN TEXT. Column Formatting will only work correctly on multi-line of text fields if they are set to plain text!
At the bottom of the screen you’ll see a text box for Column Formatting. Paste the following block of code into the text box.
{ "$schema": "https://developer.microsoft.com/json-schemas/sp/column-formatting.schema.json", "elmType": "img", "attributes": { "class": " ms-borderColor-neutralLighter", "src": "='https://dev.virtualearth.net/REST/v1/Imagery/Map/Road/'+[$Address]+'?mapSize=280,215&key=[Insert Your Bing Map API Key Here]' " }, "txtContent": "[$Address]" }
Make sure to input your Bing Maps API key where it says “insert here”. If your column name is different than Address, replace the references of that to your column name.
Your screen should look like this after you’ve pasted in the code:
Click OK on this screen and navigate back to your list view to see the results!
Recent Comments