-
Notifications
You must be signed in to change notification settings - Fork 17
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(landing): show labels on landing page (#3330)
### Motivation For additional context in aerial imagery its helpful to add vector layers such as placename and roads ### Modifications Allow landing page to request a combined aerial and label style json Add button to enable/disable showing of labels on aerial layer ![image](https://github.com/user-attachments/assets/29f62d82-8191-4ffe-be23-650110eaf26f) ![image](https://github.com/user-attachments/assets/4a1308de-7ea3-4600-ab21-5566e4f7c954) ### Verification Testing locally, but would be nice to test more in dev
- Loading branch information
Showing
12 changed files
with
200 additions
and
105 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
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
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,67 @@ | ||
import { IControl } from 'maplibre-gl'; | ||
|
||
import { Config } from '../config.js'; | ||
|
||
const LabelsDisabledLayers = new Set(['topographic', 'topolite']); | ||
|
||
export class MapLabelControl implements IControl { | ||
map?: maplibregl.Map; | ||
container?: HTMLDivElement; | ||
button?: HTMLButtonElement; | ||
buttonIcon?: HTMLElement; | ||
events: (() => boolean)[] = []; | ||
|
||
onAdd(map: maplibregl.Map): HTMLDivElement { | ||
this.map = map; | ||
this.container = document.createElement('div'); | ||
this.container.className = 'maplibregl-ctrl maplibregl-ctrl-group'; | ||
|
||
this.button = document.createElement('button'); | ||
this.button.className = 'maplibregl-ctrl-labels'; | ||
this.button.type = 'button'; | ||
this.button.addEventListener('click', this.toggleLabels); | ||
|
||
this.buttonIcon = document.createElement('i'); | ||
this.buttonIcon.className = 'material-icons-round'; | ||
this.buttonIcon.innerText = 'more'; | ||
this.button.appendChild(this.buttonIcon); | ||
this.container.appendChild(this.button); | ||
|
||
this.events.push(Config.map.on('labels', this.updateLabelIcon)); | ||
this.events.push(Config.map.on('layer', this.updateLabelIcon)); | ||
|
||
this.updateLabelIcon(); | ||
return this.container; | ||
} | ||
|
||
onRemove(): void { | ||
this.container?.parentNode?.removeChild(this.container); | ||
for (const evt of this.events) evt(); | ||
this.events = []; | ||
this.map = undefined; | ||
} | ||
|
||
toggleLabels = (): void => { | ||
Config.map.setLabels(!Config.map.labels); | ||
}; | ||
|
||
updateLabelIcon = (): void => { | ||
if (this.button == null) return; | ||
this.button.classList.remove('maplibregl-ctrl-labels-enabled'); | ||
|
||
// Topographic style disables the button | ||
if (Config.map.style && LabelsDisabledLayers.has(Config.map.style)) { | ||
this.button.classList.add('display-none'); | ||
this.button.title = 'Topographic style does not support layers'; | ||
return; | ||
} | ||
this.button.classList.remove('display-none'); | ||
|
||
if (Config.map.labels) { | ||
this.button.classList.add('maplibregl-ctrl-labels-enabled'); | ||
this.button.title = 'Hide Labels'; | ||
} else { | ||
this.button.title = 'Show Labels'; | ||
} | ||
}; | ||
} |
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.