Information bubble from HERE Maps -

Currently, I am integrating HereMap into my Vue.js application. You can find the code for implementing HereMap in Vue.js here. Next, I need to add an InfoBubble to this map using the code available here. However, I encounter a problem where the InfoBubble is displayed on the map but fails to show any information when clicked. It remains static and does not open as expected. The console displays an error stating "Uncaught TypeError: this.ui is undefined", even though ui is defined in my code. Here is the relevant portion of my code:

export default {
  name: "MapContainer",
  props: {
    center: Object
  },
  data() {
    return {
      platform: null,
      apikey:"AuXyuAIzhpLcZgo4JTieWmGjl1BwTvP0u4SbRQl8r9U",
      map: null,
      ui: {}
    };
  },
  mounted() {
    const platform = new window.H.service.Platform({
      apikey: this.apikey
    });
    this.platform = platform;
    this.initializeHereMap()
    this.addInfoBubble()
  },
  methods: {
    initializeHereMap() {
      const mapContainer = this.$refs.hereMap;
      const H = window.H;
      var maptypes = this.platform.createDefaultLayers();
      this.map = new H.Map(mapContainer, maptypes.vector.normal.map, {
        zoom: 15.15,
        center: this.center
      });
      addEventListener("resize", () => this.map.getViewPort().resize());
      new H.mapevents.Behavior(new H.mapevents.MapEvents(this.map));
      this.ui = H.ui.UI.createDefault(this.map, maptypes) 
    },

    addMarkerToGroup(group, coordinate, html) {
      var marker = new H.map.Marker(coordinate);
      marker.setData(html);
      group.addObject(marker);
    },

    addInfoBubble() {
      var group = new H.map.Group();
      this.map.addObject(group);

      group.addEventListener('tap', function (evt) {
        var bubble = new H.ui.InfoBubble(evt.target.getGeometry(), {
          content: evt.target.getData()
          });
        this.ui.addBubble(bubble);        
      }, false);

      this.addMarkerToGroup(group, {lat: 40.7679, lng: 14.0200},
      '<div><a href="https://www.mcfc.co.uk">Manchester City</a></div>' +
      '<div>City of Manchester Stadium<br />Capacity: 55,097</div>');
    }

  }
};

Answer №1

Ensure to either proxy this within the function or employ =>. Modify this segment:

group.addEventListener('tap', function (evt) {

To

group.addEventListener('tap', (evt)=> {

By doing so, the code will be functional.

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

Django and Vue: Unable to locate static file

Whenever I am using Django+Vue to develop a web application, I always encounter issues where the static files are not found even though I have placed all the files correctly. The server logs show messages like: WARNING Not Found: /static/js/app.4c2224dc.j ...

Retrieve all entries and merge a field with aggregated information in Mongoose (MongoDB)

I am faced with the challenge of working with two Mongo collections, Users and Activities. The Activities collection consists of fields such as createdAt (type Date), hoursWorked (type Number), and a reference to the user through the user field. On the oth ...

Deleting a page reference from the page history stack in Angular 4

I am working on my angular web application and I am looking for a way to remove a specific page reference from the angular page history stack. For example, if I navigate from the login page to the dashboard page, I want to remove the login page reference f ...

Struggling to verify sessionStorage token and update the route - facing challenges in ReactJS

I am attempting to verify the sessionStorage key, and if it is valid, I want to skip displaying the register page and instead redirect to the dashboard. However, I am encountering an issue where it does not redirect or replace the path, and continues to sh ...

Tips for combining all included files into one with Babel

My current project involves the use of Babel. Within my server.js file, I have the following line of code: import schema from "./data/schema"; The issue arises because data/schema.js is written in ES2015 syntax. After attempting to compile my server.js ...

What causes Vue to only update once when there are two closely timed mutations to reactive data?

Can you take a look at this simple example? export default { data() { return { name: "Amy", age: 18, }; }, computed: { combinedDataForWatching() { return { name: this.name, age: this.age, ...

Sending data to JavaScript in ExpressJS

I am facing a bit of confusion here; I am utilizing NodeJS to retrieve a JSON file and I want to pass the data to my web page so that JavaScript can utilize it. app.get('/test', function(req, res) { res.render('testPage', { ...

Dynamic routing changes forward slashes to %2F

Having a small issue with the dynamic router link. I received an array of objects (pages) from the API, and one of them is my home: { name:"dynamic" parent_id:0 partners:null slug:"/" } When using v-for, I attempt to create a router-link ...

Experiencing a lack of defined or no outcome when outputting the API callback

I am troubleshooting an issue with my script that searches for movie titles from a database. While I receive results in the console without any errors, the renderMovies function is not storing the API movie title, plot, and other details properly in my var ...

A Guide to Displaying Django Forms.TimeField in 12-hour Format on a Template

I am facing an issue with my Django form when creating and updating model data. Upon creation, I simply input 6:30 pm using the timepicker, which works fine. However, when editing an existing record, Django displays the initial time in 24-hour format (e.g. ...

Is employing the HTML 'confirm' method considered a best practice?

How can I alert a user before they discard changes in a form while switching to another page? Is using if (!confirm("Are you sure")) return false;... considered a good practice for this type of message? Or should I consider using a modal panel instead? (W ...

Improving efficiency for handling a vast number of inputs in React applications

Dealing specifically with Material UI, I am faced with the challenge of rendering a large number of inputs (more than 100) while effectively managing global state. Performance issues arise when using the Material UI <TextField /> component, with noti ...

Managing multiple Sequelize DB connections in NestJS: A guide

I recently came across the example in the NestJS documentation regarding setting up a Sequelize DB connection. I'm curious about how to connect to multiple databases using Sequelize and TypeScript with NestJS. Can anyone provide guidance on this? ...

Exploring threejs to project onto a cylindrical surface

Can you provide guidance on how to project an image onto a cylinder using threejs? Do I need to map separate portions of the image onto each face of the cylinder, or is there a more efficient method available? Appreciate any help on this matter! ...

Ways to mimic an Angular directive with a required field

Recently, I encountered a challenge that involves two directives: directive-a, directive-b. The issue arises because directive-b has a `require: '^directive-a' field, which complicates unit testing. In my unit tests, I used to compile the direc ...

JavaScript error: Attempting to assign a value to an undefined property, causing a TypeError

I keep encountering an issue with the following message: "Cannot set property '0' of undefined" var arrItems = { 'product1': [], 'product2': [], 'product3': [] }; var temArr = {}; var dataFor = ""; fu ...

Removing punctuation from time duration using Moment.js duration format can be achieved through a simple process

Currently, I am utilizing the moment duration format library to calculate the total duration of time. It is working as expected, but a slight issue arises when the time duration exceeds 4 digits - it automatically adds a comma in the hours section (similar ...

deleting an element from an array within ReactJS

I am struggling with React and I can't seem to find a solution to remove an item from an array without affecting the rest of the items. I have attempted different approaches but none of them seem to work as expected. Here is the code I have: App.js: ...

Is it possible to have a leaderboard stored in a database without requiring user

I am in the process of developing a game using Javascript that includes a leaderboard feature. Originally, my plan was to allow players to enter their name and then click a button to start the game. Since the game includes a countdown timer, I needed a w ...

Position a moveable item in the middle of two designated drop zones

I have been experimenting with creating a drag-and-drop feature that allows the draggable object to be placed between two droppable targets. The goal is for both droppable targets to receive and acknowledge the draggable object simultaneously, updating the ...