Terminal49 Map Embed Guide
The Terminal49 Map allows you to embed real-time visualized container tracking on your website with just a few lines of code.
Prerequisites
- A Terminal49 account.
- A Publishable API key, you can get one by reaching out to us at support@terminal49.com.
- Familiarity with our Shipments API and Containers API.
In the following examples we’ll be passing a
containerId
andshipmentId
variables to the embedded map. They relate toid
attributes of the container and shipment objects that are returned by the API.
How do I embed the map on my website?
Once you have the API Key, you can embed the map on your website.
- Copy and paste the code below and insert it on your website.
Once loaded, this will make the map code available through the global
window
object.
- Define a container where you want the map to be displayed.
- After the code is loaded, you can use the
window.TntMap
class to create a map instance.
Notice that the authToken
option is required. This is where you pass your Publishable API key.
- Start the map. This tells the map to initialize and hook into the element designated during initialization.
- Final step: load a container. You can pass shipment and container ids to the map where it’ll fetch the data and display it.
- Putting it all together, here is the javascript code that you need to embed the map on your website.
Additionally, the map element doesn’t have to be an element id but can be a DOM element reference instead. Consider this example where we use a query selector to select the map element.
Styling the map
All of the map styles are written as human-readable CSS classes and variables.
You can used those to customize the map to your liking.
The styles are written in BEM style as well as they’re scoped under a .tntm
class to avoid style conflicts with your website.
Sizing
By default the map will take the full width of its container and some height. The map is expandable by clicking on the expand button on the bottom left corner of the map. You can also override the default styles to customize the map to your liking.
Let’s say you want to tell the map to take 60% of the total viewport size when expanded, we’d do this as follows:
Colors
We expose a number of CSS variables that you can use to customize the map colors.
All of the variables are bound to the .tntm
class to avoid style conflicts with your website.
By default their values are set to the Terminal49 brand colors, which we don’t recommend changing and only focus on the --marker
variants instead.
Additionally the variables might require adjusting for different states of the map markers.
What does that mean? Let’s say we want to display markers ‘visited’ by a vessel as orange and the others - that we call are in ‘on-the-way’ state as blue.
First let’s define the default, blue color:
Result:
It’s also possible to change the marker colors based on wheter they’re hovered over or not.
This is what we do on the Terminal49 website to style the map markers to our needs:
You might want to copy this code and adjust it to your needs.
Was this page helpful?