Skip to content

Commit

Permalink
Add map controls
Browse files Browse the repository at this point in the history
## Context:

- The map interface is missing controls to enable the user to interact with it.
- Users can move about the map using pinch-to-zoom controls on their trackpads, but they might not be aware of this, and might be using a mouse.
- We should add these controls in to the map interface.
- The controls need to be added in the JS set up: https://maplibre.org/maplibre-gl-js/docs/examples/navigation/
  • Loading branch information
DilwoarH committed Oct 9, 2024
1 parent 12c62de commit 687f66c
Showing 1 changed file with 14 additions and 1 deletion.
15 changes: 14 additions & 1 deletion src/assets/js/map.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,15 +24,19 @@ const opacity = 0.4
*/
class Map {
constructor (opts) {
this.mapId = opts.containerId
this.bbox = opts.boundingBox ?? null
this.map = new maplibregl.Map({
container: opts.containerId,
container: this.mapId,
style: 'https://api.maptiler.com/maps/basic-v2/style.json?key=ncAXR9XEn7JgHBLguAUw',
zoom: 11,
center: [-0.1298779, 51.4959698],
interactive: opts.interactive ?? true
})

// Add map controls
this.addControls(opts.interactive)

this.map.on('load', () => {
// Store the first symbol layer id
this.setFirstMapLayerId()
Expand All @@ -49,6 +53,15 @@ class Map {
})
}

addControls (interactive = true) {
this.map.addControl(new maplibregl.ScaleControl(), 'bottom-left')

if (interactive) {
this.map.addControl(new maplibregl.NavigationControl())
this.map.addControl(new maplibregl.FullscreenControl())
}
}

setFirstMapLayerId () {
const layers = this.map.getStyle().layers

Expand Down

0 comments on commit 687f66c

Please sign in to comment.