official page →
Elevation profile control for MapTiler SDK, with elevation data fueled by MapTiler Cloud.
Elevation Profile Control
The elevation profile control is a super easy way to show the elevation profile of any GeoJSON trace, whether it's a LineString, a MultiLineString, whether or not it's encapsulated in a Feature or FeatureCollection. In case multiple features are eligible in the provided dataset, they will be concatenated and displayed together as a unique route.
It can be customized in many ways and is compatible with both metric and imperial units. Yet, it comes with many built-in defaults, and does not need a lot to look nice! Here is how the most minimalist setup looks like, featuring zooming and panning of the profile:

Usage
Install it:
npm install @maptiler/elevation-profile-control
Import it:
import { ElevationProfileControl } from "@maptiler/elevation-profile-control";
Instanciate it and add it to a Map instance, most likely inside a map "load" event callback:
const epc = new ElevationProfileControl();
map.addControl(epc);
epc.setData("my-route.geojson");
Main Features
Styling
As many MapTiler SDK (or MapLibre) controls, it is made available with a button on top of the map. By default, the elevation profile chart will also be displayed on top of the map. Yet, you can customize how you want to achieve that.
The following configuration makes the chart sticking to the left, partially transparent to reveal the map underneath:
const epc = new maptilerelevationprofilecontrol.ElevationProfileControl({
visible: true,
position: "left",
backgroundColor: "#0005",
labelColor: "#FFF6",
size: "50%",
elevationGridColor: "#FFF1",
tooltipTextColor: "#000b",
tooltipBackgroundColor: "#eeea",
profileLineColor: "#a103fc",
profileBackgroundColor: "#a103fc11",
});
Here is the result:

A second options to achieve even more custom styling is to use the option containerClass. This way, almost all the styling is achieved at application level (rather than internally by the control itself), yet the container is still created by the control. Here is an example:
const epc = new maptilerelevationprofilecontrol.ElevationProfileControl({
visible: true,
fontSize: 9,
containerClass: "profileContainer",
});
Here is the profileContainer style definition in CSS:
@keyframes fadeIn {
from { opacity: 0; }
to { opacity: 1; }
}
.profileContainer {
background-color: #fff;
height: 200px;
width: 60%;
position: absolute;
bottom: 0;
left: 0;
right: 0;
border-radius: 3px;
margin: 20px auto;
filter: drop-shadow(0px 0px 15px #00000066);
animation: fadeIn 0.5s ease forwards;
}
Here is the result:

A third way to achieve customization with an even higher level of freedom, is to use the container options. Instead of creating the container, the Control will use an existing one, and not alter its styling of the container at all. Here is an example of how to achieve that:
const epc = new maptilerelevationprofilecontrol.ElevationProfileControl({
unit: "imperial",
container: "profileContainer",
showButton: false,
labelColor: "#FFF6",
elevationGridColor: "#FFF1",
tooltipTextColor: "#000b",
tooltipBackgroundColor: "#eeea",
profileLineColor: "#a103fc",
profileBackgroundColor: "#a103fc11",
crosshairColor: "#66f5",
displayTooltip: true,
});
For the sake of a better-looking example, the example also comes with some custom colors. Here is how it looks like:

As you can see, the option showButton is false and as a result, the control button is not showing on top of the map. This can be convenient in such case because we can imagine the container being fully managed at application level.
Computing Elevation
In some cases, the route data passed to the method .setData() will contain only longitude and latitude information, but no elevation. In that case, the control will automatically fetch and compute the elevation data prior to display the profile. Under the hood, this operation is performed by the MapTiler Client library.
Events
There are three events available that can be defined in the constructor options:
onMove when moving the pointer on top of the profile
onClick when clicking on the profile
onChangeView when zooming or panning the profile
With the event onMove we can easily display a marker moving on top of the map. With the event onChangeView, we have access to a GeoJSON LineString corresponding to the zoomed section, that we can then display on top of the full-length route:

(Note: this can easily be achieved with the Polyline Helper available in the MapTiler SDK)
All the options
Know more about ElevationProfileControl constructor options
The constructor ElevationProfileControl can have many options, for instance, displaying the elevation line in red:
const epc = new ElevationProfileControl({ profileLineColor: "red" });
Below is the complete list of options:
{
visible?: boolean;
size?: string;
position?: "top" | "left" | "right" | "bottom";
showButton?: boolean;
containerClass?: string;
container?: string | HTMLDivElement;
backgroundColor?: string | null;
unit?: "metric" | "imperial";
fontSize?: number;
forceComputeElevation?: boolean;
displayElevationLabels?: boolean;
displayDistanceLabels?: boolean;
displayUnits?: boolean;
labelColor?: string;
profileLineColor?: string | null;
profileLineWidth?: number;
profileBackgroundColor?: string | null;
displayTooltip?: boolean;
tooltipTextColor?: string;
tooltipBackgroundColor?: string;
tooltipDisplayDistance?: boolean;
tooltipDisplayElevation?: boolean;
tooltipDisplayDPlus?: boolean;
tooltipDisplayGrade?: boolean;
displayDistanceGrid?: boolean;
displayElevationGrid?: boolean;
distanceGridColor?: string;
elevationGridColor?: string;
paddingTop?: number;
paddingBottom?: number;
paddingLeft?: number;
paddingRight?: number;
displayCrosshair?: boolean;
crosshairColor?: string;
onChangeView?: ((windowedLineString: LineString) => void) | null;
onClick?: ((data: CallbackData) => void) | null;
onMove?: ((data: CallbackData) => void) | null;
}
With CallbackData being:
{
position: Position;
distance: number;
dPlus: number;
gradePercent: number;
};
Find more usage examples in the documentation.