ol-elevation-profile 0.5.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +97 -0
- package/dist/ol-elevation-profile.css +110 -0
- package/dist/ol-elevation-profile.esm.js +740 -0
- package/dist/ol-elevation-profile.esm.min.js +16 -0
- package/dist/ol-elevation-profile.js +759 -0
- package/dist/ol-elevation-profile.min.js +16 -0
- package/package.json +75 -0
- package/src/ol-elevation-profile.css +110 -0
- package/src/ol-elevation-profile.js +738 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 lc-4918
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
# ol-elevation-profile
|
|
2
|
+
|
|
3
|
+
<p>
|
|
4
|
+
<a href="https://www.npmjs.com/package/ol-elevation-profile"><img src="https://img.shields.io/npm/v/ol-elevation-profile.svg" alt="npm version"></a>
|
|
5
|
+
<a href="https://openlayers.org/"><img src="https://img.shields.io/badge/OpenLayers-6%20%E2%80%93%2010.9.0-1f6feb.svg" alt="OpenLayers 6 to 10.9.0"></a>
|
|
6
|
+
<a href="https://d3js.org/"><img src="https://img.shields.io/badge/d3-%E2%89%A5%207-f9a03c.svg" alt="d3 >= 7"></a>
|
|
7
|
+
<a href="./LICENSE"><img src="https://img.shields.io/badge/license-MIT-green.svg" alt="License: MIT"></a>
|
|
8
|
+
</p>
|
|
9
|
+
|
|
10
|
+
A synchronized, themeable **elevation profile control for [OpenLayers](https://openlayers.org/)**, rendered with [d3](https://d3js.org/).
|
|
11
|
+
|
|
12
|
+
It reads elevation (**Z**) directly from a track's geometry (`[lon, lat, z]` GPX/GeoJSON), so **no elevation service is queried** — distance, ascent/descent and min/max are computed from the track itself. Clicking (or hovering) a track shows its profile; a marker stays synchronized on both the map and the chart, and a click on the empty map hides it. The control is fully responsive (full-width docked bar on phones), supports slope-class colouring, metric smoothing, an A↔B crop, six themes, transparency, and a track-colour mode.
|
|
13
|
+
|
|
14
|
+
## Screenshots
|
|
15
|
+
|
|
16
|
+

|
|
17
|
+
|
|
18
|
+
> Animated demos (hover sync, A↔B crop, slope colouring) are best seen live — see the [demo](#demo). GIFs can be added under `assets/`.
|
|
19
|
+
|
|
20
|
+
## Installation
|
|
21
|
+
|
|
22
|
+
### Script tags (UMD)
|
|
23
|
+
|
|
24
|
+
The control expects `ol` and `d3` to be present as globals (provided by your map page):
|
|
25
|
+
|
|
26
|
+
```html
|
|
27
|
+
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/ol@10.9.0/ol.css">
|
|
28
|
+
<script src="https://cdn.jsdelivr.net/npm/ol@10.9.0/dist/ol.js"></script>
|
|
29
|
+
<script src="https://cdn.jsdelivr.net/npm/d3@7/dist/d3.min.js"></script>
|
|
30
|
+
|
|
31
|
+
<link rel="stylesheet" href="ol-elevation-profile.css">
|
|
32
|
+
<script src="ol-elevation-profile.js"></script>
|
|
33
|
+
<!-- exposes window.OlElevationProfile -->
|
|
34
|
+
```
|
|
35
|
+
|
|
36
|
+
### npm / bundler (ESM)
|
|
37
|
+
|
|
38
|
+
```bash
|
|
39
|
+
npm i ol-elevation-profile
|
|
40
|
+
# ol and d3 are peer dependencies you install yourself
|
|
41
|
+
```
|
|
42
|
+
|
|
43
|
+
```js
|
|
44
|
+
import OlElevationProfile from 'ol-elevation-profile'
|
|
45
|
+
import 'ol-elevation-profile/css'
|
|
46
|
+
```
|
|
47
|
+
|
|
48
|
+
## Usage
|
|
49
|
+
|
|
50
|
+
```js
|
|
51
|
+
const profile = new OlElevationProfile({
|
|
52
|
+
position: 'bottom',
|
|
53
|
+
theme: 'steelblue',
|
|
54
|
+
units: 'meters',
|
|
55
|
+
color: 'auto', // chart uses the track colour
|
|
56
|
+
trackLayer: vectorLayer, // layer to read that colour from
|
|
57
|
+
slope: true, // colour the profile by gradient class
|
|
58
|
+
tooltipItems: ['distance', 'elevation', 'slope'],
|
|
59
|
+
titleLink: 'link' // title becomes a link from a feature property
|
|
60
|
+
})
|
|
61
|
+
map.addControl(profile)
|
|
62
|
+
|
|
63
|
+
const feats = new ol.format.GeoJSON().readFeatures(geojson, {
|
|
64
|
+
dataProjection: 'EPSG:4326',
|
|
65
|
+
featureProjection: map.getView().getProjection()
|
|
66
|
+
})
|
|
67
|
+
vectorSource.addFeatures(feats)
|
|
68
|
+
profile.setFeature(feats[0]) // or let a click on the track select it
|
|
69
|
+
```
|
|
70
|
+
|
|
71
|
+
Full option reference: see the [documentation](#documentation).
|
|
72
|
+
|
|
73
|
+
## Features
|
|
74
|
+
|
|
75
|
+
### Slope classes
|
|
76
|
+
|
|
77
|
+
With `slope: true`, the profile is split into contiguous portions of the same slope class (width `slopeClassSize`, in %), capped at `maxClasses` (default 8). Colours run from **blue** (flattest class) to **red** (steepest), via cyan/green and a pure yellow, spread across the classes that are actually present — not stretched on the real maximum slope. A vertical separator marks each class change, and a legend appears under the title.
|
|
78
|
+
|
|
79
|
+
### Smoothing
|
|
80
|
+
|
|
81
|
+
`smoothing` is a sliding-window average over **metres** of track (`0` = none, the default). Because the unit is metric, the result is independent of GPS point density; it softens both the profile and the slope.
|
|
82
|
+
|
|
83
|
+
### Attributions
|
|
84
|
+
|
|
85
|
+
When the profile occupies the bottom-right corner (or full-width at the bottom), the OpenLayers attribution control is automatically lifted **above** the profile, right-aligned, with a vertical gap equal to the map-edge-to-profile-bottom gap. Other placements leave the attribution untouched.
|
|
86
|
+
|
|
87
|
+
## Demo
|
|
88
|
+
|
|
89
|
+
Live, interactive demo (toggle every option): **https://lc-4918.github.io/ol-elevation-profile/demo/**
|
|
90
|
+
|
|
91
|
+
## Documentation
|
|
92
|
+
|
|
93
|
+
Full guide and API (English & French): **https://lc-4918.github.io/ol-elevation-profile/**
|
|
94
|
+
|
|
95
|
+
## License
|
|
96
|
+
|
|
97
|
+
[MIT](./LICENSE) © lc-4918
|
|
@@ -0,0 +1,110 @@
|
|
|
1
|
+
/*! ol-elevation-profile — styles (MIT) */
|
|
2
|
+
|
|
3
|
+
.ol-elevation-profile {
|
|
4
|
+
--oep-area: #4682b4;
|
|
5
|
+
--oep-line: #3a6d96;
|
|
6
|
+
--oep-axis: #555;
|
|
7
|
+
--oep-text: #222;
|
|
8
|
+
--oep-focus: #e6550d;
|
|
9
|
+
--oep-bg: rgba(255, 255, 255, 1);
|
|
10
|
+
|
|
11
|
+
position: absolute;
|
|
12
|
+
box-sizing: border-box;
|
|
13
|
+
background: var(--oep-bg);
|
|
14
|
+
color: var(--oep-text);
|
|
15
|
+
font: 12px/1.3 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
|
|
16
|
+
border-radius: 8px;
|
|
17
|
+
box-shadow: 0 2px 12px rgba(0, 0, 0, 0.18);
|
|
18
|
+
padding: 6px 8px 4px;
|
|
19
|
+
z-index: 5;
|
|
20
|
+
max-width: 100%;
|
|
21
|
+
}
|
|
22
|
+
.ol-elevation-profile.oep-transparent { backdrop-filter: blur(2px); }
|
|
23
|
+
|
|
24
|
+
/* ---- 8 ancrages ---- */
|
|
25
|
+
.ol-elevation-profile.oep-pos-bottom { left: 50%; bottom: .6em; transform: translateX(-50%); }
|
|
26
|
+
.ol-elevation-profile.oep-pos-top { left: 50%; top: .6em; transform: translateX(-50%); }
|
|
27
|
+
.ol-elevation-profile.oep-pos-left { left: .6em; top: 50%; transform: translateY(-50%); }
|
|
28
|
+
.ol-elevation-profile.oep-pos-right { right: .6em; top: 50%; transform: translateY(-50%); }
|
|
29
|
+
.ol-elevation-profile.oep-pos-top-left { left: .6em; top: .6em; }
|
|
30
|
+
.ol-elevation-profile.oep-pos-top-right { right: .6em; top: .6em; }
|
|
31
|
+
.ol-elevation-profile.oep-pos-bottom-left { left: .6em; bottom: .6em; }
|
|
32
|
+
.ol-elevation-profile.oep-pos-bottom-right { right: .6em; bottom: .6em; }
|
|
33
|
+
|
|
34
|
+
/* ---- mobile : pleine largeur, collé en haut ou en bas ---- */
|
|
35
|
+
.ol-elevation-profile.oep-mobile { left: 0 !important; right: 0 !important; width: auto !important; transform: none !important; }
|
|
36
|
+
.ol-elevation-profile.oep-mobile.oep-pos-bottom { bottom: 0; border-radius: 10px 10px 0 0; }
|
|
37
|
+
.ol-elevation-profile.oep-mobile.oep-pos-top { top: 0; border-radius: 0 0 10px 10px; }
|
|
38
|
+
|
|
39
|
+
/* ---- entête ---- */
|
|
40
|
+
.oep-header { display: flex; align-items: center; gap: 8px; width: 100%; padding: 0 2px 2px; }
|
|
41
|
+
.oep-title { flex: 0 1 auto; min-width: 0; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
|
|
42
|
+
.oep-title a { color: inherit; text-decoration: underline; text-underline-offset: 2px; }
|
|
43
|
+
.oep-stats { flex: 1 1 auto; min-width: 0; font-size: 11px; opacity: .85; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
|
|
44
|
+
.oep-stats a { color: var(--oep-focus); }
|
|
45
|
+
.oep-stats .oep-up { color: #c0392b; }
|
|
46
|
+
.oep-stats .oep-down { color: #2471a3; }
|
|
47
|
+
|
|
48
|
+
/* ---- barre d'outils zoom ---- */
|
|
49
|
+
.oep-toolbar { flex: 0 0 auto; display: inline-flex; gap: 2px; margin-left: auto; }
|
|
50
|
+
.oep-tbtn {
|
|
51
|
+
display: inline-flex; align-items: center; justify-content: center; width: 24px; height: 22px;
|
|
52
|
+
border: 1px solid transparent; background: transparent; cursor: pointer; color: var(--oep-text);
|
|
53
|
+
opacity: .7; border-radius: 4px; padding: 0;
|
|
54
|
+
}
|
|
55
|
+
.oep-tbtn:hover { opacity: 1; background: rgba(0, 0, 0, .07); }
|
|
56
|
+
.oep-tbtn.armed { opacity: 1; border-color: var(--oep-focus); color: var(--oep-focus); }
|
|
57
|
+
.oep-tbtn svg { width: 16px; height: 16px; display: block; }
|
|
58
|
+
|
|
59
|
+
.oep-toggle {
|
|
60
|
+
flex: 0 0 auto; display: inline-flex; align-items: center; justify-content: center;
|
|
61
|
+
width: 22px; height: 22px; padding: 0; border: 0; background: transparent; cursor: pointer;
|
|
62
|
+
color: var(--oep-text); opacity: .65; border-radius: 4px;
|
|
63
|
+
}
|
|
64
|
+
.oep-toolbar + .oep-toggle { margin-left: 0; }
|
|
65
|
+
.oep-toggle:hover { opacity: 1; background: rgba(0, 0, 0, .07); }
|
|
66
|
+
.oep-toggle svg { width: 15px; height: 15px; display: block; }
|
|
67
|
+
|
|
68
|
+
/* ---- légende de pente ---- */
|
|
69
|
+
.oep-legend { display: flex; flex-wrap: wrap; gap: 4px 10px; padding: 0 2px 4px; font-size: 10px; opacity: .9; }
|
|
70
|
+
.oep-leg-it { display: inline-flex; align-items: center; gap: 4px; white-space: nowrap; }
|
|
71
|
+
.oep-sw { width: 10px; height: 10px; border-radius: 2px; display: inline-block; }
|
|
72
|
+
|
|
73
|
+
.oep-body { overflow: hidden; }
|
|
74
|
+
|
|
75
|
+
/* ---- mode réduit : on rétracte le contrôle à la largeur Titre + bouton ---- */
|
|
76
|
+
.ol-elevation-profile.oep-collapsed { width: auto !important; }
|
|
77
|
+
.ol-elevation-profile.oep-collapsed .oep-body,
|
|
78
|
+
.ol-elevation-profile.oep-collapsed .oep-legend { display: none !important; }
|
|
79
|
+
.ol-elevation-profile.oep-collapsed .oep-stats,
|
|
80
|
+
.ol-elevation-profile.oep-collapsed .oep-toolbar { display: none !important; }
|
|
81
|
+
.ol-elevation-profile.oep-collapsed .oep-header { width: auto; }
|
|
82
|
+
|
|
83
|
+
/* ---- chart ---- */
|
|
84
|
+
.oep-svg { display: block; }
|
|
85
|
+
.oep-area { fill: var(--oep-area); opacity: .6; }
|
|
86
|
+
.oep-line { fill: none; stroke: var(--oep-line); stroke-width: 1.4; }
|
|
87
|
+
.oep-area-slope { opacity: .92; stroke: none; }
|
|
88
|
+
.oep-slope-sep { stroke: rgba(40, 40, 40, .35); stroke-width: .8; shape-rendering: crispEdges; }
|
|
89
|
+
|
|
90
|
+
.oep-ab-line { stroke: var(--oep-focus); stroke-width: 1.4; }
|
|
91
|
+
.oep-ab-label { fill: var(--oep-focus); font-size: 11px; font-weight: 700; }
|
|
92
|
+
|
|
93
|
+
.oep-axis path, .oep-axis line { stroke: var(--oep-axis); shape-rendering: crispEdges; }
|
|
94
|
+
.oep-axis text { fill: var(--oep-text); font-size: 10px; }
|
|
95
|
+
.oep-axis-label { fill: var(--oep-text); font-size: 10px; opacity: .8; }
|
|
96
|
+
.oep-grid line { stroke: var(--oep-axis); opacity: .16; shape-rendering: crispEdges; }
|
|
97
|
+
.oep-grid path { stroke: none; }
|
|
98
|
+
|
|
99
|
+
.oep-overlay { fill: transparent; cursor: crosshair; }
|
|
100
|
+
.oep-focus-line { stroke: var(--oep-focus); stroke-width: 1; stroke-dasharray: 3 2; }
|
|
101
|
+
.oep-focus-dot { fill: var(--oep-focus); stroke: #fff; stroke-width: 1.5; }
|
|
102
|
+
.oep-focus-txt { fill: var(--oep-text); font-size: 10px; font-weight: 600; }
|
|
103
|
+
.oep-focus-bg { fill: rgba(255, 255, 255, .9); }
|
|
104
|
+
|
|
105
|
+
.oep-marker {
|
|
106
|
+
width: 14px; height: 14px; border-radius: 50%;
|
|
107
|
+
background: var(--oep-focus, #e6550d); border: 2px solid #fff;
|
|
108
|
+
box-shadow: 0 0 0 1px rgba(0, 0, 0, .35); pointer-events: none;
|
|
109
|
+
}
|
|
110
|
+
.ol-elevation-profile.oep-floating { transform: none; }
|