@geoblocks/elevation-profile 0.0.11 → 0.0.13
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/README.md +63 -0
- package/dist/elevation-profile.d.ts +6 -2
- package/dist/elevation-profile.d.ts.map +1 -1
- package/dist/elevation-profile.js +35 -6
- package/dist/elevation-profile.js.map +1 -1
- package/elevation-profile.ts +25 -7
- package/package.json +8 -8
- package/dist/index.600fa9d1.js +0 -5366
- package/dist/index.600fa9d1.js.map +0 -1
- package/dist/index.html +0 -291
package/dist/index.html
DELETED
|
@@ -1,291 +0,0 @@
|
|
|
1
|
-
<!DOCTYPE html>
|
|
2
|
-
|
|
3
|
-
<html>
|
|
4
|
-
<head>
|
|
5
|
-
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1">
|
|
6
|
-
<script src="/index.600fa9d1.js" defer=""></script>
|
|
7
|
-
<style>body {
|
|
8
|
-
margin: 0;
|
|
9
|
-
}
|
|
10
|
-
|
|
11
|
-
.container {
|
|
12
|
-
margin: 50px;
|
|
13
|
-
position: relative;
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
#tooltip {
|
|
17
|
-
color: #fff;
|
|
18
|
-
background-color: #707070;
|
|
19
|
-
padding: 10px;
|
|
20
|
-
display: none;
|
|
21
|
-
position: absolute;
|
|
22
|
-
transform: translate(-50%, -100%);
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
elevation-profile {
|
|
26
|
-
width: 80%;
|
|
27
|
-
height: 300px;
|
|
28
|
-
display: block;
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
elevation-profile .grid.x {
|
|
32
|
-
display: none;
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
elevation-profile line {
|
|
36
|
-
shape-rendering: crispedges;
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
elevation-profile .axis .domain, .grid .domain {
|
|
40
|
-
display: none;
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
elevation-profile .axis line, .grid line {
|
|
44
|
-
stroke: #707070;
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
elevation-profile .pointer-line {
|
|
48
|
-
stroke: #707070;
|
|
49
|
-
stroke-opacity: .3;
|
|
50
|
-
stroke-width: 2px;
|
|
51
|
-
stroke-dasharray: 3 3;
|
|
52
|
-
}
|
|
53
|
-
|
|
54
|
-
elevation-profile .pointer-circle {
|
|
55
|
-
fill: #3761a4;
|
|
56
|
-
stroke: #fff;
|
|
57
|
-
stroke-width: 3px;
|
|
58
|
-
}
|
|
59
|
-
|
|
60
|
-
elevation-profile .pointer-circle-outline {
|
|
61
|
-
fill: #000;
|
|
62
|
-
fill-opacity: .2;
|
|
63
|
-
}
|
|
64
|
-
|
|
65
|
-
elevation-profile .elevation, elevation-profile .elevation.highlight {
|
|
66
|
-
stroke: #3761a4;
|
|
67
|
-
stroke-width: 2px;
|
|
68
|
-
stroke-linejoin: round;
|
|
69
|
-
}
|
|
70
|
-
|
|
71
|
-
elevation-profile .elevation.highlight {
|
|
72
|
-
stroke-width: 3px;
|
|
73
|
-
}
|
|
74
|
-
|
|
75
|
-
elevation-profile .area {
|
|
76
|
-
fill: #e6e6e6;
|
|
77
|
-
fill-opacity: .85;
|
|
78
|
-
}
|
|
79
|
-
|
|
80
|
-
</style>
|
|
81
|
-
</head>
|
|
82
|
-
<body>
|
|
83
|
-
<div class="container">
|
|
84
|
-
<div id="tooltip"></div>
|
|
85
|
-
|
|
86
|
-
<elevation-profile locale="de-CH"></elevation-profile>
|
|
87
|
-
</div>
|
|
88
|
-
<button id="set-lines">set lines</button>
|
|
89
|
-
<button id="reset-lines">reset lines</button>
|
|
90
|
-
<button id="save">save</button>
|
|
91
|
-
|
|
92
|
-
<pre id="logs"></pre>
|
|
93
|
-
|
|
94
|
-
<script>const profile = document.querySelector("elevation-profile");
|
|
95
|
-
const tooltip = document.querySelector("#tooltip");
|
|
96
|
-
const logs = document.querySelector("#logs");
|
|
97
|
-
const setLines = document.querySelector("#set-lines");
|
|
98
|
-
const resetLines = document.querySelector("#reset-lines");
|
|
99
|
-
const save = document.querySelector("#save");
|
|
100
|
-
profile.updateScale = (x, y, width, height)=>{
|
|
101
|
-
// Flattened array of [xMax,ratioYOverX].
|
|
102
|
-
const ratiosXY = [
|
|
103
|
-
0,
|
|
104
|
-
0.5,
|
|
105
|
-
0.33,
|
|
106
|
-
0.2,
|
|
107
|
-
0.1,
|
|
108
|
-
0.05
|
|
109
|
-
];
|
|
110
|
-
const ratiosMinDist = [
|
|
111
|
-
0,
|
|
112
|
-
2000,
|
|
113
|
-
5000,
|
|
114
|
-
20000,
|
|
115
|
-
100000,
|
|
116
|
-
Infinity
|
|
117
|
-
];
|
|
118
|
-
console.assert(ratiosXY.length === ratiosMinDist.length);
|
|
119
|
-
let i;
|
|
120
|
-
const xDomain = x.domain();
|
|
121
|
-
let yDomain = y.domain();
|
|
122
|
-
// Add padding to Y domain
|
|
123
|
-
const padding = (yDomain[1] - yDomain[0]) * 0.1;
|
|
124
|
-
y.domain([
|
|
125
|
-
yDomain[0] - padding,
|
|
126
|
-
yDomain[1] + padding
|
|
127
|
-
]);
|
|
128
|
-
yDomain = y.domain();
|
|
129
|
-
const xMin = xDomain[0];
|
|
130
|
-
const xMax = xDomain[1];
|
|
131
|
-
const yMin = yDomain[0];
|
|
132
|
-
let yMax = yDomain[1];
|
|
133
|
-
// Search for the best XY ratio
|
|
134
|
-
let yDomainLength = 0;
|
|
135
|
-
i = 0;
|
|
136
|
-
let reverse = false;
|
|
137
|
-
// The algorithm is:
|
|
138
|
-
// - advance to reach the expected ratio;
|
|
139
|
-
// - if the computed ydomain would not be large enough, reverse direction;
|
|
140
|
-
// - go backwards until a good ydomain is found;
|
|
141
|
-
// - if none is found keep the ydomain values from d3.
|
|
142
|
-
while(true){
|
|
143
|
-
if (!reverse && xMax > ratiosMinDist[i]) {
|
|
144
|
-
// advance in the ratio table
|
|
145
|
-
++i;
|
|
146
|
-
continue;
|
|
147
|
-
}
|
|
148
|
-
const ratioYOverX = ratiosXY[i];
|
|
149
|
-
const xResolution = (xMax - xMin) / width;
|
|
150
|
-
yDomainLength = ratioYOverX * xResolution * height;
|
|
151
|
-
if (i > 0 && yDomainLength < yMax - yMin) {
|
|
152
|
-
// not enough space with this ratio to show all the
|
|
153
|
-
// y values. Go back to try another ratio.
|
|
154
|
-
reverse = true;
|
|
155
|
-
--i;
|
|
156
|
-
continue;
|
|
157
|
-
}
|
|
158
|
-
break;
|
|
159
|
-
}
|
|
160
|
-
// Apply XY ratio
|
|
161
|
-
if (yDomainLength) {
|
|
162
|
-
const yMean = (yMax + yMin) / 2;
|
|
163
|
-
const yHalfDomain = yDomainLength / 2;
|
|
164
|
-
y.domain([
|
|
165
|
-
yMean - yHalfDomain,
|
|
166
|
-
yMean + yHalfDomain
|
|
167
|
-
]);
|
|
168
|
-
}
|
|
169
|
-
// Lower bound for y-axis
|
|
170
|
-
if (y.domain()[0] < 0) {
|
|
171
|
-
const shift = 0 - y.domain()[0];
|
|
172
|
-
// For yLowerBound=0 and y0=-50, y is shifted 50m up
|
|
173
|
-
y.domain([
|
|
174
|
-
0,
|
|
175
|
-
y.domain()[1] + shift
|
|
176
|
-
]);
|
|
177
|
-
}
|
|
178
|
-
};
|
|
179
|
-
save.addEventListener("click", ()=>{
|
|
180
|
-
const svg = profile.innerHTML;
|
|
181
|
-
const blob = new Blob([
|
|
182
|
-
svg
|
|
183
|
-
], {
|
|
184
|
-
type: "image/svg+xml"
|
|
185
|
-
});
|
|
186
|
-
const url = URL.createObjectURL(blob);
|
|
187
|
-
const a = document.createElement("a");
|
|
188
|
-
a.href = url;
|
|
189
|
-
a.download = "elevation.svg";
|
|
190
|
-
a.click();
|
|
191
|
-
});
|
|
192
|
-
setLines.addEventListener("click", ()=>{
|
|
193
|
-
profile.lines = [
|
|
194
|
-
[
|
|
195
|
-
[
|
|
196
|
-
740073,
|
|
197
|
-
5905947,
|
|
198
|
-
434,
|
|
199
|
-
0
|
|
200
|
-
],
|
|
201
|
-
[
|
|
202
|
-
740073,
|
|
203
|
-
5905947,
|
|
204
|
-
485,
|
|
205
|
-
25
|
|
206
|
-
],
|
|
207
|
-
[
|
|
208
|
-
740073,
|
|
209
|
-
5905947,
|
|
210
|
-
490,
|
|
211
|
-
60
|
|
212
|
-
],
|
|
213
|
-
[
|
|
214
|
-
740072,
|
|
215
|
-
5905940,
|
|
216
|
-
512,
|
|
217
|
-
100
|
|
218
|
-
]
|
|
219
|
-
],
|
|
220
|
-
[
|
|
221
|
-
[
|
|
222
|
-
740007,
|
|
223
|
-
5905729,
|
|
224
|
-
490,
|
|
225
|
-
155
|
|
226
|
-
],
|
|
227
|
-
[
|
|
228
|
-
740000,
|
|
229
|
-
5905709,
|
|
230
|
-
489,
|
|
231
|
-
169
|
|
232
|
-
],
|
|
233
|
-
[
|
|
234
|
-
739997,
|
|
235
|
-
5905704,
|
|
236
|
-
501,
|
|
237
|
-
173
|
|
238
|
-
],
|
|
239
|
-
[
|
|
240
|
-
739997,
|
|
241
|
-
5905704,
|
|
242
|
-
512,
|
|
243
|
-
180
|
|
244
|
-
],
|
|
245
|
-
[
|
|
246
|
-
739997,
|
|
247
|
-
5905704,
|
|
248
|
-
501,
|
|
249
|
-
210
|
|
250
|
-
]
|
|
251
|
-
],
|
|
252
|
-
[
|
|
253
|
-
[
|
|
254
|
-
740007,
|
|
255
|
-
5905729,
|
|
256
|
-
512,
|
|
257
|
-
255
|
|
258
|
-
],
|
|
259
|
-
[
|
|
260
|
-
740000,
|
|
261
|
-
5905709,
|
|
262
|
-
505,
|
|
263
|
-
369
|
|
264
|
-
],
|
|
265
|
-
[
|
|
266
|
-
739997,
|
|
267
|
-
5905704,
|
|
268
|
-
501,
|
|
269
|
-
390
|
|
270
|
-
]
|
|
271
|
-
]
|
|
272
|
-
];
|
|
273
|
-
});
|
|
274
|
-
resetLines.addEventListener("click", ()=>{
|
|
275
|
-
profile.lines = [];
|
|
276
|
-
});
|
|
277
|
-
profile.addEventListener("over", (event)=>{
|
|
278
|
-
logs.textContent = JSON.stringify(event.detail, null, 2);
|
|
279
|
-
tooltip.style.display = "block";
|
|
280
|
-
tooltip.textContent = `${event.detail.coordinate[2]} m`;
|
|
281
|
-
tooltip.style.left = `${event.detail.position.x}px`;
|
|
282
|
-
tooltip.style.top = `${event.detail.position.y - 20}px`;
|
|
283
|
-
});
|
|
284
|
-
profile.addEventListener("out", (event)=>{
|
|
285
|
-
logs.textContent = "";
|
|
286
|
-
tooltip.style.display = "none";
|
|
287
|
-
});
|
|
288
|
-
|
|
289
|
-
</script>
|
|
290
|
-
</body>
|
|
291
|
-
</html>
|