-
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
- Loading branch information
Showing
8 changed files
with
174 additions
and
95 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
import { IControl } from 'maplibre-gl'; | ||
|
||
import { Config } from '../config.js'; | ||
|
||
const LabelsDisabledLayers = new Set(['topographic']); | ||
|
||
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.button.innerHTML = `<i class="material-icons material-icons-outlined">more</span>`; | ||
|
||
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
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.