forked from HSLdevcom/OpenTripPlanner
-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge remote-tracking branch 'otp/dev-2.x' into cleanup_filters
- Loading branch information
Showing
104 changed files
with
2,353 additions
and
1,258 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
import type { ControlPosition } from 'react-map-gl'; | ||
import { useControl } from 'react-map-gl'; | ||
import { IControl, Map } from 'maplibre-gl'; | ||
|
||
type LayerControlProps = { | ||
position: ControlPosition; | ||
}; | ||
|
||
/** | ||
* A maplibre control that allows you to switch vector tile layers on and off. | ||
* | ||
* It appears that you cannot use React elements but have to drop down to raw DOM. Please correct | ||
* me if I'm wrong. | ||
*/ | ||
class LayerControl implements IControl { | ||
private readonly container: HTMLDivElement = document.createElement('div'); | ||
|
||
onAdd(map: Map) { | ||
this.container.className = 'maplibregl-ctrl maplibregl-ctrl-group layer-select'; | ||
|
||
map.on('load', () => { | ||
// clean on | ||
while (this.container.firstChild) { | ||
this.container.removeChild(this.container.firstChild); | ||
} | ||
|
||
const title = document.createElement('h6'); | ||
title.textContent = 'Debug layers'; | ||
this.container.appendChild(title); | ||
|
||
map | ||
.getLayersOrder() | ||
.map((l) => map.getLayer(l)) | ||
.filter((s) => s?.type !== 'raster') | ||
.reverse() | ||
.forEach((layer) => { | ||
if (layer) { | ||
const div = document.createElement('div'); | ||
const input = document.createElement('input'); | ||
input.type = 'checkbox'; | ||
input.value = layer.id; | ||
input.id = layer.id; | ||
input.onchange = (e) => { | ||
e.preventDefault(); | ||
e.stopPropagation(); | ||
|
||
if (this.layerVisible(map, layer)) { | ||
map.setLayoutProperty(layer.id, 'visibility', 'none'); | ||
} else { | ||
map.setLayoutProperty(layer.id, 'visibility', 'visible'); | ||
} | ||
}; | ||
input.checked = this.layerVisible(map, layer); | ||
const label = document.createElement('label'); | ||
label.textContent = layer.id; | ||
label.htmlFor = layer.id; | ||
div.appendChild(input); | ||
div.appendChild(label); | ||
this.container.appendChild(div); | ||
} | ||
}); | ||
}); | ||
|
||
return this.container; | ||
} | ||
|
||
private layerVisible(map: Map, layer: { id: string }) { | ||
return map.getLayoutProperty(layer.id, 'visibility') !== 'none'; | ||
} | ||
|
||
onRemove() { | ||
this.container.parentNode?.removeChild(this.container); | ||
} | ||
} | ||
|
||
export default function DebugLayerControl(props: LayerControlProps) { | ||
useControl(() => new LayerControl(), { | ||
position: props.position, | ||
}); | ||
|
||
return null; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.