{"id":28576926,"url":"https://github.com/maptiler/maptiler-elevation-profile-control","last_synced_at":"2025-06-11T00:08:15.108Z","repository":{"id":213712691,"uuid":"722621446","full_name":"maptiler/maptiler-elevation-profile-control","owner":"maptiler","description":"Elevation profile control for MapTiler SDK, with elevation data fueled by MapTiler Cloud.","archived":false,"fork":false,"pushed_at":"2025-02-28T16:32:09.000Z","size":13554,"stargazers_count":5,"open_issues_count":1,"forks_count":2,"subscribers_count":7,"default_branch":"main","last_synced_at":"2025-06-05T11:47:23.568Z","etag":null,"topics":["maptiler-sdk-plugin"],"latest_commit_sha":null,"homepage":"","language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/maptiler.png","metadata":{"files":{"readme":"readme.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2023-11-23T14:41:44.000Z","updated_at":"2025-01-08T10:26:41.000Z","dependencies_parsed_at":"2023-12-22T16:05:28.032Z","dependency_job_id":"316dfca8-6a2d-4b22-83f2-c4239efdab5b","html_url":"https://github.com/maptiler/maptiler-elevation-profile-control","commit_stats":null,"previous_names":["maptiler/maptiler-elevation-profile-control"],"tags_count":3,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/maptiler%2Fmaptiler-elevation-profile-control","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/maptiler%2Fmaptiler-elevation-profile-control/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/maptiler%2Fmaptiler-elevation-profile-control/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/maptiler%2Fmaptiler-elevation-profile-control/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/maptiler","download_url":"https://codeload.github.com/maptiler/maptiler-elevation-profile-control/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/maptiler%2Fmaptiler-elevation-profile-control/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":259172987,"owners_count":22816560,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["maptiler-sdk-plugin"],"created_at":"2025-06-11T00:08:13.921Z","updated_at":"2025-06-11T00:08:15.080Z","avatar_url":"https://github.com/maptiler.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"\u003cp align=\"center\"\u003e\n\u003ca href=\"https://docs.maptiler.com/sdk-js/\"\u003eofficial page →\u003c/a\u003e\u003cbr\u003e\n  \u003cimg src=\"images/maptiler-epc-logo.svg\" width=\"400px\"\u003e\n\u003c/p\u003e\n\n\u003cp align=\"center\" style=\"color: #AAA\"\u003e\n  Elevation profile control for MapTiler SDK, with elevation data fueled by \u003ca href=\"https://www.maptiler.com/cloud/\"\u003eMapTiler Cloud\u003c/a\u003e.\u003cbr\u003e\n\u003c/p\u003e\n\n\u003cp align=\"center\"\u003e\n  \u003cimg src=\"images/JS-logo.svg\" width=\"20px\"\u003e\n  \u003cimg src=\"images/TS-logo.svg\" width=\"20px\"\u003e\n  \u003cimg src=\"https://img.shields.io/npm/v/@maptiler/elevation-profile-control\"\u003e\u003c/img\u003e\n  \u003cimg src=\"https://img.shields.io/twitter/follow/maptiler?style=social\"\u003e\u003c/img\u003e\n\u003c/p\u003e\n\n# Elevation Profile Control\nThe 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.\n\nIt 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:\n\n![](images/basic.png)\n\n## Usage\nInstall it:\n```bash\nnpm install @maptiler/elevation-profile-control\n```\n\nImport it:\n```ts\nimport { ElevationProfileControl } from \"@maptiler/elevation-profile-control\";\n```\n\nInstanciate it and add it to a `Map` instance, most likely inside a *map* `\"load\"` event callback:\n```ts\n// Create an instance (with no options)\nconst epc = new ElevationProfileControl();\n\n// Add it to your map\nmap.addControl(epc);\n\n// Add some data (from a URL or a MapTiler Data UUID)\nepc.setData(\"my-route.geojson\");\n```\n\n## Main Features\n### Styling\nAs 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.\n\nThe following configuration makes the chart sticking to the left, partially transparent to reveal the map underneath:\n\n```ts\nconst epc = new maptilerelevationprofilecontrol.ElevationProfileControl({\n  visible: true, // no need to click, it's there by default\n  position: \"left\",\n  backgroundColor: \"#0005\",\n  labelColor: \"#FFF6\",\n  size: \"50%\", // Take half of the room available (default is 30%)\n  elevationGridColor: \"#FFF1\",\n  tooltipTextColor: \"#000b\",\n  tooltipBackgroundColor: \"#eeea\",\n  profileLineColor: \"#a103fc\",\n  profileBackgroundColor: \"#a103fc11\",\n});\n```\nHere is the result:\n![](images/custom-style.png)\n\nA 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:\n\n```ts\nconst epc = new maptilerelevationprofilecontrol.ElevationProfileControl({\n  visible: true,\n  // since the text is drawn in the canvas, \n  // it still has to be tuned here:\n  fontSize: 9,\n  containerClass: \"profileContainer\",\n});\n```\n\nHere is the `profileContainer` style definition in CSS:\n```css\n@keyframes fadeIn {\n  from { opacity: 0; }\n  to { opacity: 1; }\n}\n\n.profileContainer {\n  background-color: #fff;\n  height: 200px;\n  width: 60%;\n  position: absolute;\n  bottom: 0;\n  left: 0;\n  right: 0;\n  border-radius: 3px;\n  margin: 20px auto;\n  filter: drop-shadow(0px 0px 15px #00000066);\n  animation: fadeIn 0.5s ease forwards;\n}\n```\nHere is the result:\n![](images/custom-class.png)\n\nA 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:\n```ts\nconst epc = new maptilerelevationprofilecontrol.ElevationProfileControl({\n  unit: \"imperial\",\n  container: \"profileContainer\",\n  showButton: false,\n  labelColor: \"#FFF6\",\n  elevationGridColor: \"#FFF1\",\n  tooltipTextColor: \"#000b\",\n  tooltipBackgroundColor: \"#eeea\",\n  profileLineColor: \"#a103fc\",\n  profileBackgroundColor: \"#a103fc11\",\n  crosshairColor: \"#66f5\",\n  displayTooltip: true,\n});\n```\nFor the sake of a better-looking example, the example also comes with some custom colors. Here is how it looks like:\n![](images/custom-div.png)\n\nAs 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.\n\n## Computing Elevation\nIn 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](https://docs.maptiler.com/client-js/).\n\n## Events\nThere are three events available that can be defined in the constructor options:\n- `onMove` when moving the pointer on top of the profile\n- `onClick` when clicking on the profile\n- `onChangeView` when zooming or panning the profile\n\nWith 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:\n![](images/section.png)\n\n(Note: this can easily be achieved with the *Polyline Helper* available in the MapTiler SDK)\n\n## All the options\n\u003cdetails\u003e\n  \u003csummary\u003eKnow more about ElevationProfileControl constructor options\u003c/summary\u003e\n\nThe constructor `ElevationProfileControl` can have many options, for instance, displaying the elevation line in red:\n\n```ts\nconst epc = new ElevationProfileControl({ profileLineColor: \"red\" });\n```\n\nBelow is the complete list of options:\n```ts\n{\n  /**\n   * If `true`, the elevation profile control will be visible as soon as it's ready.\n   * If `false`, a click on the control button (or a programmatic call to `.showProfile()`)\n   * will be neccesary to show the profile.\n   *\n   * Default: `false`\n   */\n  visible?: boolean;\n  /**\n   * Size of the profile as a CSS rule.\n   * This `size` will be the `width` if the `.position` is \"left\" or \"right\",\n   * and will be the `height` if the `.position` is \"top\" or \"bottom\".\n   *\n   * Default: `\"30%\"`\n   */\n  size?: string;\n  /**\n   * Position of the elevation profile chart when shown.\n   *\n   * Default: `\"botton\"`\n   */\n  position?: \"top\" | \"left\" | \"right\" | \"bottom\";\n  /**\n   * Show the control button. If can be handy to hide it, especially if the profile is displayed\n   * in a custom container and that its visiblity is managed by logic external to this control.\n   *\n   * Default: `true`\n   */\n  showButton?: boolean;\n  /**\n   * A CSS class to add to the container. This is especially relevant when the options `.container` is not provided.\n   * Important: if provided, no styling is added by this control and even placement will have to be managed by external CSS.\n   *\n   * Default: `\"\"`\n   */\n  containerClass?: string;\n  /**\n   * DIV element to contain the control.\n   * Important: if provided, no styling is added by this control.\n   * Default: automatically created inside the map container\n   */\n  container?: string | HTMLDivElement;\n  /**\n   * Color of the background of the chart\n   */\n  backgroundColor?: string | null;\n  /**\n   * Unit system to use.\n   * If \"metric\", elevation and D+ will be in meters, distances will be in km.\n   * If \"imperial\", elevation and D+ will be in feet, distances will be in miles.\n   *\n   * Default: \"metric\"\n   */\n  unit?: \"metric\" | \"imperial\";\n  /**\n   * Font size applied to axes labels and tooltip.\n   *\n   * Default: `12`\n   */\n  fontSize?: number;\n  /**\n   * If `true`, will force the computation of the elevation of the GeoJSON data provided to the `.setData()` method,\n   * even if they already contain elevation (possibly from GPS while recording). If `false`, the elevation will only\n   * be computed if missing from the positions.\n   *\n   * Default: `false`\n   */\n  forceComputeElevation?: boolean;\n  /**\n   * Display the elevation label along the vertical axis.\n   *\n   * Default: `true`\n   */\n  displayElevationLabels?: boolean;\n  /**\n   * Display the distance labels alon the horizontal axis.\n   *\n   * Default: `true`\n   */\n  displayDistanceLabels?: boolean;\n  /**\n   * Display the distance and elevation units alongside the labels.\n   *\n   * Default: `true`\n   */\n  displayUnits?: boolean;\n  /**\n   * Color of the elevation and distance labels.\n   *\n   * Default: `\"#0009\"` (partially transparent black)\n   */\n  labelColor?: string;\n  /**\n   * Color of the elevation profile line.\n   * Can be `null` to not display the line and rely on the background color only.\n   *\n   * Default: `\"#66ccff\"`\n   */\n  profileLineColor?: string | null;\n  /**\n   * Width of the elevation profile line.\n   *\n   * Default: `1.5`\n   */\n  profileLineWidth?: number;\n  /**\n   * Color of the elevation profile background (below the profile line)\n   * Can be `null` to not display any backgound color.\n   *\n   * Default: `\"#66ccff22\"`\n   */\n  profileBackgroundColor?: string | null;\n  /**\n   * Display the tooltip folowing the pointer.\n   *\n   * Default: `true`\n   */\n  displayTooltip?: boolean;\n  /**\n   * Color of the text inside the tooltip.\n   *\n   * Default: `\"#fff\"`\n   */\n  tooltipTextColor?: string;\n  /**\n   * Color of the tooltip background.\n   *\n   * Default: `\"#000A\"` (partially transparent black)\n   */\n  tooltipBackgroundColor?: string;\n  /**\n   * Display the distance information inside the tooltip if `true`.\n   *\n   * Default: `true`\n   */\n  tooltipDisplayDistance?: boolean;\n  /**\n   * Display the elevation information inside the tooltip if `true`.\n   *\n   * Default: `true`\n   */\n  tooltipDisplayElevation?: boolean;\n  /**\n   * Display the D+ (cumulated positive ascent) inside the tooltip if `true`.\n   *\n   * Default: `true`\n   */\n  tooltipDisplayDPlus?: boolean;\n  /**\n   * Display the slope grade in percentage inside the tooltip if `true`.\n   *\n   * Default: `true`\n   */\n  tooltipDisplayGrade?: boolean;\n  /**\n   * Display the distance grid lines (vertical lines matching the distance labels) if `true`.\n   *\n   * Default: `false`\n   */\n  displayDistanceGrid?: boolean;\n  /**\n   * Display the elevation grid lines (horizontal lines matching the elevation labels) if `true`.\n   *\n   * Default: `true`\n   */\n  displayElevationGrid?: boolean;\n  /**\n   * Color of the distance grid lines.\n   *\n   * Default: `\"#0001\"` (partially transparent black)\n   */\n  distanceGridColor?: string;\n  /**\n   * Color of the elevation drig lines.\n   *\n   * Default: `\"#0001\"` (partially transparent black)\n   */\n  elevationGridColor?: string;\n  /**\n   * Padding at the top of the chart, in number of pixels.\n   *\n   * Default: `30`\n   */\n  paddingTop?: number;\n  /**\n   * Padding at the bottom of the chart, in number of pixels.\n   *\n   * Default: `10`\n   */\n  paddingBottom?: number;\n  /**\n   * Padding at the left of the chart, in number of pixels.\n   *\n   * Default: `10`\n   */\n  paddingLeft?: number;\n  /**\n   * Padding at the right of the chart, in number of pixels.\n   *\n   * Default: `10`\n   */\n  paddingRight?: number;\n  /**\n   * Display the crosshair, a vertical line that follows the pointer, if `true`.\n   *\n   * Default: `true`\n   */\n  displayCrosshair?: boolean;\n  /**\n   * Color of the crosshair.\n   *\n   * Default: `\"#0005\"` (partially transparent black)\n   */\n  crosshairColor?: string;\n  /**\n   * Callback function to call when the chart is zoomed or panned.\n   * The argument `windowedLineString` is the GeoJSON LineString corresponding\n   * to the portion of the route visible in the elevation chart.\n   *\n   * Default: `null`\n   */\n  onChangeView?: ((windowedLineString: LineString) =\u003e void) | null;\n  /**\n   * Callback function to call when the the elevation chart is clicked.\n   *\n   * Default: `null`\n   */\n  onClick?: ((data: CallbackData) =\u003e void) | null;\n  /**\n   * Callback function to call when the pointer is moving on the elevation chart.\n   *\n   * Default: `null`\n   */\n  onMove?: ((data: CallbackData) =\u003e void) | null;\n}\n```\n\nWith `CallbackData` being:\n```ts\n{\n  /**\n   * The position as `[lon, lat, elevation]`.\n   * Elevation will be in meters if the component has been set with the unit \"metric\" (default)\n   * of in feet if the unit is \"imperial\".\n   */\n  position: Position;\n  /**\n   * The distance from the start of the route. In km if the component has been set with the unit \"metric\" (default)\n   * of in miles if the unit is \"imperial\".\n   */\n  distance: number;\n  /**\n   * Cumulated positive elevation from the begining of the route up to this location.\n   * In meters if the component has been set with the unit \"metric\" (default)\n   * of in feet if the unit is \"imperial\".\n   */\n  dPlus: number;\n  /**\n   * Slope grade in percentage (1% being a increase of 1m on a 100m distance)\n   */\n  gradePercent: number;\n};\n```\n\u003c/details\u003e\n\nFind more usage examples in [the documentation](https://docs.maptiler.com/sdk-js/examples/).\n\n\n\n\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmaptiler%2Fmaptiler-elevation-profile-control","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmaptiler%2Fmaptiler-elevation-profile-control","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmaptiler%2Fmaptiler-elevation-profile-control/lists"}