Interactions (click, tap, swipe) are not functioning properly on the Mapbox-gl-js map within a Vue.js single file component

I am facing an issue with a Vuejs single file component that displays the map properly:

However, none of the default handlers seem to work, even after I have made them explicit during initialization.

Here is the code for the single file component:

<template>
  <div id='map'></div>
</template>

<script>
import mapboxgl from 'mapbox-gl'

export default {
  data () {
    return {}
  },
  created () {
    this.createMap()
  },
  methods: {
    createMap: function () {
      mapboxgl.accessToken = [myapikey]
      var simple = {
        'version': 8,
        'sources': {
          'osm': {
            'type': 'vector',
            'tiles': ['https://vector.mapzen.com/osm/all/{z}/{x}/{y}.mvt?api_key=vector-tiles-[myapikey]']
          }
        },
        'layers': [{
          'id': 'background',
          'type': 'background',
          'paint': {
            'background-color': '#bbccd2'
          }
        },
          {
            'id': 'majorroad',
            'source': 'osm',
            'source-layer': 'roads',
            'type': 'line'
          },
          {
            'id': 'buildings',
            'type': 'fill',
            'source': 'osm',
            'source-layer': 'buildings'
          }]
      }

      // initialize the map
      this.map = new mapboxgl.Map({
        container: 'map',
        style: simple,
        minzoom: 1.3,
        bearingSnap: 15,
        hash: true,   // displays coordinates and zoom in URL widget
        center: [-74.0073, 40.7124], // Manhattan
        zoom: 16,
        attributionControl: true,
        interactive: true,
        scrollZoom: true,
        dragRotate: true,
        dragPan: true,
        doubleClickZoom: true,
        pitch: 60
      })

      this.map.addControl(new mapboxgl.NavigationControl())
      this.map.addControl(new mapboxgl.GeolocateControl({position: 'top-left'}))
      this.map.addControl(new mapboxgl.AttributionControl({position: 'bottom-right'}))
      this.map.addControl(new mapboxgl.ScaleControl({
        position: 'bottom-left',
        maxWidth: 80,
        unit: 'imperial'
      }))
    }
  }
}
</script>

<style>

#map {
  position: absolute;
  top: 0;
  bottom: 0;
  width: 100%;
}

</style> 

Can anyone provide some insights into why the handlers are not functioning properly? I am able to zoom in and out using the widget, but the handlers do not work. Interestingly, when I initialize the map outside of the component, all handlers work as expected.

Answer №1

I've reviewed your repository and identified an additional #map DOM element in your index.html file. This element is positioned absolutely above the user interface, causing it to intercept all touch/click events before reaching the map itself. I have submitted a pull request to remove this excess markup.

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Tips for modifying prop values after they have been initially set in a Component

When working with a Vue component, it is important to remember that setting the 'props' immediately requires updating the collection to include additional properties. The component code is as follows: Vue.component('blog-post', { pr ...

Is it possible to apply a class without using ng-class?

Seeking a more efficient way to apply conditional classes to multiple elements on a validation form page, I am exploring options to assign one of five potential classes to each form input. While the traditional method involves manually specifying the class ...

Ways to retrieve the value of the variable within the confines of this particular

In my code, I have private variables in the constructor and public variables in the class. To reference these variables and functions, I use the "this" keyword. However, when trying to access these variables inside a function, I am getting an "undefined" ...

Troubleshooting: Error in angular JavaScript due to minification: $injector:modulerr Module Error

After defining my angular code as shown below, I encountered an issue when trying to minify the javascript. The error message displayed was: $injector:modulerr Module Error. angular.module('myModule').controller('MyController', functio ...

Manage multiple sessions at the same time

In a specific scenario, we face the need to manage multiple sessions similar to Google Accounts. Users should be able to add different accounts in separate tabs, each with its own unique content. For example, user1 may be logged in on Tab1 while user2 is l ...

Display multiple markers on a Google Map using google-map-react library

I am currently struggling to display markers on my Google Map using the map function. I have tried various approaches but nothing seems to work. Could there be limitations that I'm not aware of, or am I overlooking something critical? I experimented w ...

Utilize a single JavaScript file to handle various views without encountering errors due to undefined functions

My backend editing requires a single JS file. However, I face the challenge of needing different sets of methods for view A and view B — never both at the same time. To streamline this process, I combined all the jQuery functions for both views into one ...

Tips for refreshing the tawk.to widget when the language changes with the help of i18next

Utilizing i18n-jquery for language switching and integrating the tawk.to chat widget, I've successfully loaded different languages on page reload. However, due to i18n not refreshing the page (which I don't want to do), I need to figure out how t ...

Undefined elements in an array of objects in Javascript

I've been working on creating an array of objects in JavaScript, but I'm facing an issue when attempting to print the array to the console in Chrome. It keeps returning undefined unless I print the array right after pushing new elements into it. ...

Another network request within the ng-repeat loop

My Angular application needs to call web services from two different URLs. The first URL abc.com/student/3 provides a list of students, while the second URL abc.com/parent/idofStudent3 gives the parent's first name when passed the student ID. I have ...

Scrolling a div automatically without affecting its parent element

On a page, I have a scrollable list of items that can be updated with a PUT request. Once the update is successful, another network request is made to fetch the updated list. The goal is to automatically highlight the recently updated item in the list. Al ...

Leveraging Ajax for transmitting JSON data and performing decoding operations

Previously, I used an AJAX script to fetch data from viewCommentsJson.php. The data retrieved looked like this: [{"comments":"Greta"},{"comments":"John"}]. Is there a way to decode and display this return value properly? Appreciate any assistance. Gret ...

Transform a JSON array containing individual objects into a new JSON array with objects

My array contains objects with nested objects in each element, structured like this: [ { "person": { "name": "John", "isActive": true, "id": 1 } }, { "person": { "name": "Ted", "isActive": true, "id": 2 } } ] I ...

Angular is patiently waiting for the initial function to activate

I have a situation where I need to wait for the results of my first function before executing the second one. code First function getUser() { this.authService.user().subscribe( user => { this.user = user; console.log('c ...

Guidelines for implementing drag and drop functionality for my specific scenario

Looking to create a restricted area for dragging elements within my app. Specifically, I want the element to only be draggable within a certain defined space. Here is what I currently have: http://jsfiddle.net/L73T5/10/ html <div id='background ...

Choose the dropdown item depending on the related text

I am currently working on a drop-down menu where each option has a value and associated text. The selected option is then displayed row by row in a table, with an edit button next to each row that allows the user to change the selection. I am trying to imp ...

I'm looking for a way to incorporate JavaScript code within an iframe tag. Specifically, I'm attempting to embed code into a Wix website using the "Embed HTML

Trying to execute the code below on a Wix website using "Embed HTML", but IFRAME is blocking scripts. Seeking help to embed custom HTML with JavaScript on platforms like Wix.com or Wordpress.com, as the embedded code is not functioning due to IFRAME restri ...

Error: Supabase and Next.js encountered a self-signed certificate within the certificate chain causing an AuthRetryableFetchError

Encountering an error related to certificates while attempting to retrieve the user from Supabase within getServerSideProps using Next.js: AuthRetryableFetchError: request to https://[redacted].supabase.co/auth/v1/user failed, reason: self signed certifica ...

Having trouble with jQuery.validate.js while using type="button" for AJAX calls in an MVC application

I have come across several questions similar to mine, but I haven't found a solution that fits my situation in MVC, so I am reaching out for help. I am a beginner with MVC and I am utilizing jQuery AJAX to invoke a controller method for data insertio ...

Issue with back button functionality when loading page with history.pushState in JavaScript

My current issue involves loading a page via ajax using history.pushState. The page loads successfully, but the back button does not work as expected. I have included my code below for reference: function processAjaxData(response, urlPath){ document.wr ...