I am making an interactive map with mapbox and nuxt that sets the visibility of certain layers when the map loads. I also set up a queryRenderedFeatures function using this.map.on('mousemove'), like this:
export default {
props: {
map: {
type: Object,
required: true
}
},
data: () => ({
layerIds: ['Zip Code', 'Network'],
zone: 'Zip Code'
}),
mounted () {
this.map.on('load', () => { this.map.setLayoutProperty(this.layerIds[0], 'visibility', 'visible') })
this.map.on('load', () => { this.map.setLayoutProperty(this.layerIds[1], 'visibility', 'none') })
this.map.on('mousemove', (e) => {
if( this.zone == 'Zip Code'){
const features = this.map.queryRenderedFeatures(e.point)
...
Right now this is all being called in the mounted hook of a child of my map component and everything works as it should when i deploy to a local server. However, when I deploy to vercel, the map displays both layers on load, instead of just the first one, and returns a console error:
TypeError: this.map.on is not a function
at c.mounted (98d0728.js:1)
at ii (b366f77.js:2)
at vn (b366f77.js:2)
at Object.insert (b366f77.js:2)
at $ (b366f77.js:2)
at zn.__patch__ (b366f77.js:2)
at zn.t._update (b366f77.js:2)
at zn.o (b366f77.js:2)
at Tn.get (b366f77.js:2)
at new Tn (b366f77.js:2)
ai @ b366f77.js:2
manifest.js:1 Failed to load resource: the server responded with a status of 404 ()
I have found some threads that suggest mapbox is not compatible with server side rendering but I'm not confident thats the issue or even true at this point. either way, my attempts to add the target: 'static' line to my nuxt.config.js and refactor the mapbox gl import as a const in mounted have been unsuccessful so far. Anyone know what could be causing this error?