-
Notifications
You must be signed in to change notification settings - Fork 653
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
WIP: Add contour line endpoint for terrain #1458
base: master
Are you sure you want to change the base?
Changes from all commits
f60de38
619c7f3
21a2559
c94bd22
ac8e038
20ffc99
24154d0
0e87d45
239f107
484de1e
2e92e57
49fa9e1
56eb295
c124b5e
77c4e31
85ec258
15a654f
7ed3ac4
25af93c
978c8cd
616717d
88b8554
ba6054f
02ab2b4
9477a4b
a8d7295
12c9d12
e6a892d
8dd927e
b72f662
c7377e8
2e74bc7
61e81e0
a0fb368
b638208
d635d3c
c72d6f5
70d6986
e1460fb
8dc3809
ab20e81
9f3a7ce
1f0ee0d
d255cdc
c4adfa8
3aaab82
848f7c5
5a883d9
c9bc1ec
12b818b
b6537b5
d521546
279421c
8ea4b50
7cbafe8
08e1d34
c0e14bd
40ecf4c
d98cc33
4c6f379
592e74c
32fd488
576f02e
d6f7f5e
99afa33
d5d938b
6fddbae
8186aa1
7133587
0d72d57
468779b
8bdd14a
3260611
ff4ab84
d0aad8e
4c58ebb
6ab84eb
a805302
5f85802
b825c9a
e1cae33
e6750dc
8420ef1
faf01d7
3517060
d4aaa62
afa5952
2be472b
f6b24a5
f187d32
4abc616
bc85d7a
4fe9bda
7a81e47
0dcf296
2505249
4e2e46a
7e67f40
23f50d0
f888286
c2f95ab
3def0d2
1c5ee75
59f4dcc
aa936ea
1c3baef
d85226f
9a98b38
e79e011
dce7732
0f3629c
b1e1d72
e0574b1
96b35a3
54bc82c
3fedd5b
1f69300
340e5db
7dddbf7
62a3212
5de617d
e18874f
aceb306
ecfcaeb
097c0e1
941e283
36cbcf7
8f28789
5315123
930e571
03b1c31
8412c08
02210f0
4d33886
1f1fe49
a10555e
b95a207
cd4f162
fb73f53
088a5e8
b65ea05
5b753ca
f7883a2
d4c2ce1
2d90d8a
1961c24
07b6ccc
15a51ac
d9d606b
43f86e9
1bfeac2
904f379
c9e7f10
56dbeb2
6ad99a3
450de42
e1634d1
63ff3fc
eb6a11b
32668ed
f15d1df
4b51f87
fc0e36d
043c84b
25702fb
6335abf
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
class MaplibreContourControl { | ||
constructor(options) { | ||
this.source = options["source"]; | ||
this.confLayers = options["layers"]; | ||
this.visibility = options["visibility"]; | ||
} | ||
|
||
getDefaultPosition() { | ||
const defaultPosition = "top-right"; | ||
return defaultPosition; | ||
} | ||
|
||
onAdd(map) { | ||
this.map = map; | ||
this.controlContainer = document.createElement("div"); | ||
this.controlContainer.classList.add("maplibregl-ctrl"); | ||
this.controlContainer.classList.add("maplibregl-ctrl-group"); | ||
this.contourButton = document.createElement("button"); | ||
this.contourButton.type = "button"; | ||
this.contourButton.textContent = "C"; | ||
|
||
this.map.on("style.load", () => { | ||
this.confLayers.forEach(layer => { | ||
this.map.setLayoutProperty(layer, "visibility", this.visibility ? "visible" : "none"); | ||
if (this.visibility) { | ||
this.controlContainer.classList.add("maplibre-ctrl-contour-active"); | ||
this.contourButton.title = "Disable Contours"; | ||
} else { | ||
this.contourButton.title = "Enable Contours"; | ||
} | ||
}); | ||
}); | ||
|
||
this.contourButton.addEventListener("click", () => { | ||
this.confLayers.forEach(layer => { | ||
var visibility = this.map.getLayoutProperty(layer, "visibility"); | ||
if (visibility === "visible") { | ||
this.map.setLayoutProperty(layer, "visibility", "none"); | ||
this.controlContainer.classList.remove("maplibre-ctrl-contour-active"); | ||
this.contourButton.title = "Disable Contours"; | ||
} else { | ||
this.controlContainer.classList.add("maplibre-ctrl-contour-active"); | ||
this.map.setLayoutProperty(layer, "visibility", "visible"); | ||
this.contourButton.title = "Enable Contours"; | ||
} | ||
}); | ||
}); | ||
this.controlContainer.appendChild(this.contourButton); | ||
return this.controlContainer; | ||
} | ||
|
||
onRemove() { | ||
if ( | ||
!this.controlContainer || | ||
!this.controlContainer.parentNode || | ||
!this.map || | ||
!this.contourButton | ||
) { | ||
return; | ||
} | ||
this.contourButton.removeEventListener("click"); | ||
this.controlContainer.parentNode.removeChild(this.controlContainer); | ||
this.map = undefined; | ||
} | ||
}; |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -9,6 +9,7 @@ | |
<link rel="stylesheet" type="text/css" href="{{public_url}}maplibre-gl-inspect.css{{&key_query}}" /> | ||
<script src="{{public_url}}maplibre-gl.js{{&key_query}}"></script> | ||
<script src="{{public_url}}maplibre-gl-inspect.js{{&key_query}}"></script> | ||
<script src="{{public_url}}contour-control.js{{&key_query}}"></script> | ||
{{^is_light}} | ||
<script src="{{public_url}}elevation-control.js{{&key_query}}"></script> | ||
{{/is_light}} | ||
|
@@ -23,6 +24,7 @@ | |
h1 {position:absolute;top:5px;right:0;width:240px;margin:0;line-height:20px;font-size:20px;} | ||
#layerList {position:absolute;top:35px;right:0;bottom:0;width:240px;overflow:auto;} | ||
#layerList div div {width:15px;height:15px;display:inline-block;} | ||
.maplibre-ctrl-contour-active button { color: #33b5e5; font-weight: bold; } | ||
{{^is_light}} | ||
.maplibre-ctrl-elevation { padding-left: 5px; padding-right: 5px; } | ||
{{/is_light}} | ||
|
@@ -76,6 +78,8 @@ | |
{{/is_terrain}} | ||
{{#is_terrain}} | ||
|
||
let baseUrl = window.location.origin; | ||
|
||
var style = { | ||
version: 8, | ||
sources: { | ||
|
@@ -88,8 +92,13 @@ | |
"type": "raster-dem", | ||
"url": "{{public_url}}data/{{id}}.json", | ||
"encoding": "{{terrain_encoding}}" | ||
}, | ||
"contour": { | ||
"type": "vector", | ||
"tiles": [ baseUrl + "/data/{{id}}/contour/{z}/{x}/{y}" ], | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. One thing I would like to do is make a json endpoint for the contour lines, so this does not need baseurl I tried to use {{public_url}} here also, but "tiles" doesn't like the relative link it seemed. |
||
} | ||
}, | ||
"glyphs": "/fonts/{fontstack}/{range}.pbf", | ||
"terrain": { | ||
"source": "terrain" | ||
}, | ||
|
@@ -114,6 +123,33 @@ | |
"hillshade-illumination-direction": 315, | ||
"hillshade-exaggeration": 0.8 | ||
} | ||
}, | ||
{ | ||
"id": "contours", | ||
"type": "line", | ||
"source": "contour", | ||
"source-layer": "contours", | ||
"paint": { | ||
"line-opacity": 1, | ||
"line-width": ["match", ["get", "level"], 1, 1, 0.5] | ||
} | ||
}, | ||
{ | ||
"id": "contour-label", | ||
"type": "symbol", | ||
"source": "contour", | ||
"source-layer": "contours", | ||
"filter": [">", ["get", "ele"], 0 ], | ||
"paint": { | ||
"text-halo-color": "white", | ||
"text-halo-width": 1 | ||
}, | ||
"layout": { | ||
"symbol-placement": "line", | ||
"text-size": 10, | ||
"text-field": "{ele}", | ||
"text-font": ["Noto Sans Bold"] | ||
} | ||
} | ||
] | ||
}; | ||
|
@@ -139,6 +175,14 @@ | |
}) | ||
); | ||
|
||
map.addControl( | ||
new MaplibreContourControl({ | ||
source: "contour", | ||
visibility: false, | ||
layers: [ "contours", "contour-label" ] | ||
}) | ||
); | ||
|
||
{{^is_light}} | ||
map.addControl( | ||
new ElevationInfoControl({ | ||
|
Check notice
Code scanning / CodeQL
Unused variable, import, function or class Note