Can the pointerover event be managed on a container within the am5 library?

While attempting to add an HTML label to a map and trigger a pointerover event, I encountered issues. The objective was to change the HTML content upon hover. Despite trying to incorporate a tooltip, the hover event failed to work properly, and the tooltip displayed an unwanted border.

const base = am5.Root.new('#map');

    base.setThemes([
      am5themes_Animated.new(base), // Integration of animation
    ]);

    const diagram = base.container.children.push(
      am5map.MapChart.new(base, {
        projection: am5map.geoNaturalEarth1(), // Altering the map's shape
      }),
    );
    const polygonGroup = diagram.series.push(
      am5map.MapPolygonSeries.new(base, {
        geoJSON: am5geodata_worldLow,
        exclude: ['AQ'],
      }),
    );

    /**
     * Universal styles for all countries.
     */
    polygonGroup.mapPolygons.template.setAll({
      fill: am5.color(0x9563c7),
      stroke: am5.color(0x292131),
      strokeWidth: 1,
      fillOpacity: 1,
      templateField: 'polygonSettings'
    });

    /**
     * Customizing colors for individual countries
     */
    polygonGroup.data.setAll(
      this.mapService.countries.map(country => ({
        id: country.id,
        polygonSettings: {
          fill: am5.color(country.fill),
        },
      })),
    );

    /**
     * Creating personalized labels for partner nations
     */
    const dotSet = diagram.series.push(
      am5map.ClusteredPointSeries.new(base, {
        minDistance: 30,
        scatterRadius: 10,
        stopClusterZoom: 0.9,
      }),
    );

    dotSet.data.setAll(
      this.mapService.countries.map(country => ({
        countryCode: country.id,
        img: country.img,
        geometry: country.geometry,
      })),
    );

    dotSet.bullets.push(
      (_: Root, _2: Series, dataItem: DataItem<IMapPointSeriesDataItem>): Bullet => {
        const { countryCode, img } = dataItem.dataContext as IMapData;

        const container = am5.Container.new(base, {
          cursorOverStyle: 'pointer',
          interactive: true,
          html: `
                <div class="country-label">
                    <img src="${img}" alt="img">
                    ${countryCode}
                </div>
                `,
          x: am5.percent(50),
          centerX: am5.percent(50),
        });

        container.events.on('pointerover', () => { // The issue persists
          container.set('html', '<div>text</div>');
        });

        container.events.on('pointerout', () => { // Still not functioning as desired
          container.set('html', '<div>text</div>');
        });

        container.events.on('click', function (ev) { // Works perfectly
          console.log(12345);
          container.set('html', '<div>text</div>');
        });

        return am5.Bullet.new(base, {
          sprite: container,
        });
      },
    );

    /**
     * Merging various labels.
     */
    dotSet.set('clusteredBullet', function (base) {
      const container = am5.Container.new(root, {
        cursorOverStyle: 'pointer',
      });

      /**
       * Utilizing a rounded-corner background rectangle for the cluster digit
       */
      container.children.push(
        am5.RoundedRectangle.new(base, {
          width: 60,
          height: 28,
          dx: -30,
          dy: -13,
          cornerRadiusBL: 38,
          cornerRadiusBR: 38,
          cornerRadiusTL: 38,
          cornerRadiusTR: 38,
          fill: am5.color(0x111111),
          fillOpacity: 0.3,
          brightness: 0,
          crisp: true,
          stroke: am5.color(0x171b2c),
        }),
      );

      /**
       * Implementing a background rectangle for a blur effect
       */
      container.children.push(
        am5.RoundedRectangle.new(base, {
          width: 64,
          height: 34,
          dx: -31,
          dy: -14,
          cornerRadiusBL: 38,
          cornerRadiusBR: 38,
          cornerRadiusTL: 38,
          cornerRadiusTR: 38,
          fill: am5.color(0x111111),
          blur: 3,
          fillOpacity: 0.55,
        }),
      );

      /**
       * Including a Label for the digit display
       */
      container.children.push(
        am5.Label.new(base, {
          centerX: am5.p50,
          centerY: am5.p50,
          fill: am5.color(0xffffff),
          populateText: true,
          fontSize: 16,
          text: '+{value}',
        }),
      );

      /**
       * Enabling region zoom on cluster click
       */
      container.events.on('click', function (e: am5.ISpritePointerEvent) {
        dotSet.zoomToCluster(e.target.dataItem);
      });

      return am5.Bullet.new(base, {
        sprite: container,
      });
    });

I utilized container.events.on to attach events. Unfortunately, while click functionality performs correctly, pointerover fails to operate as expected.

Answer №1

Apply a background style to the am5.Label

Learn more about adding backgrounds to labels here.

Add background styling to the am5.Rectangle.new in order to set properties like fill color and opacity:
background: am5.Rectangle.new(root, {
   fill: am5.color(0x000000),
  fillOpacity: 0
})

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

Having difficulty receiving a response from an AJAX call within the success function

After browsing through this stack link Ajax response not calling success:function() when using jQuery 1.8.3, I'm puzzled as to why the success function is not invoked when I uncomment the dataType line. It seems that setting dataType = JSON prevents t ...

How can I enable a button in a React application when the text input is not populating

For my Instagram MERN project, I have implemented a Comment box feature for users. The Post button starts off disabled and becomes enabled when text is entered. However, despite entering text, the button remains disabled, preventing submission. Below is th ...

Adjust the class based on the model's value in AngularJS

items = {'apple', 'banana', 'lemon', 'cat', 'dog', 'monkey', 'tom', 'john', 'baby'} html <div class="variable" ng-repeat="item in items">{{item}} </div> ...

Remix is throwing a Hydration Error while trying to process data mapping

While working on my Remix project locally, I encountered a React hydration error. One thing I noticed is that the HTML rendered by the server does not match the HTML generated by the client. This issue seems to be related to the Material UI library usage. ...

Is it feasible to set a default value in an HTML input field that is not editable using JavaScript?

Is there a way to set a default value in an input field of HTML that is not editable, and then allow users to add additional text to it? For example, having 'AB' as the default and uneditable starting characters, followed by any numbers such as A ...

Various input tools available for every Textarea

I'm grappling with this particular case. Each textarea should have its own toolbox, but currently only one is active (I anticipate having more than 2 areas, so JavaScript needs to be able to recognize them by ID) I attempted to use something like: f ...

Having trouble with a JavaScript Promise that seems to be stuck in limbo

I have developed two custom promises that are quite similar, with the only difference being that they operate on distinct user inputs. Both promises utilize various classes and methods from Google Maps API v-3. What's puzzling is that when the first ...

Using TypeScript: Implementing array mapping with an ES6 Map

If I have an array of key-value objects like this: const data = [ {key: "object1", value: "data1"}, {key: "object2", value: "data2"}, {key: "object3", value: "data3"}, ] const mappedData = data.map(x => [x.key, x.value]); const ES6Map = n ...

Modal Pop-ups Failing to Open on Subsequent Attempts

My table consists of buttons on the right-hand side for a menu. The first button in the menu is supposed to open a modal box upon clicking. However, the first buttons in the subsequent rows do not function as expected and fail to open the modal. Refer to t ...

core.js encountered an issue at line 6210: TypeError - The function this.service.addDepartment does not exist

Whenever I attempt to click the 'Add' button on a web application that I'm constructing, an error pops up. core.js:6210 ERROR TypeError: this.service.addDepartment is not a function at AddEditDepComponent.addDepartment (add-edit-dep.componen ...

Tips for resolving the issue: 'Unhandled Promise Rejection: Error: Unable to resolve bare specifier "app.js" from http://localhost:3000/'

While delving into TypeScript, I have come across an error related to node modules. Upon clicking the anonymous function, it leads me to the following code snippet. <!DOCTYPE html> <html> <head> <meta charset="utf-8"> & ...

Generate visual representations of data sorted by category using AngularJS components

I am facing an unusual issue with Highcharts and Angularjs 1.6 integration. I have implemented components to display graphs based on the chart type. Below is an example of the JSON data structure: "Widgets":[ { "Id":1, "description":"Tes ...

Ways to access the content of the chosen <td> element using Vue?

I have a dynamic table where I retrieve data using $.ajax() from a database. The content in the rows is editable, and I need to save the changes made with vue.js. After updating the content, an $.ajax() function with 4 parameters (name, client_id, url, and ...

How can I implement Jquery ajax calls in various JavaScript functions?

I'm encountering an issue with a particular function in my code function readComm(){ $.post("something.php", {read:"read"}, function(data){ retVal = $.trim(data).toString(); console.log(retVal); return retVal; }); } T ...

What is the best way to adjust the decimal values in my API calls?

Is there a way to adjust the numerical data returned by the API to display only two decimal places instead of three? For example, if the number is 140.444, I want it to show as 140.44 What changes do I need to make? function fetchData() { fetch(" ...

Managing images in JavaScript while conserving memory

Welcome I am embarking on a project to construct a webpage using HTML, CSS, JavaScript (jQuery), and nearly 1000 images. The length of the HTML page is substantial, around 5000px. My vision involves creating a captivating visual experience for users as t ...

By clicking the button, you can add an item to select2

Utilizing the select2 tag style in my Drupal YAML form allows users to easily locate and add various items. These items come with both images and titles on the same page, accompanied by a button next to each image. My goal is to enable users to click the b ...

Tips for setting an identification value within mongodb?

Currently, my focus is on utilizing node.js and mongoose. I am in the process of developing a REST API to showcase my User model: var userSchema = new Schema({ _id: {type:Number}, username: {type:String}, age: {type:Number}, genre:{type: Number,ref:&a ...

Using Ternary Operators in React Components for Styling

Extracting data from a json file and attempting to assign a specific class only when certain criteria are met: render: function() { var gameList = this.props.data.map(function(game) { return ( <li key={game.id} className="l ...

A guide on utilizing buttons within ion list items to execute actions independently for both the button and the list item

Currently, I have a list item with a button that is displayed based on a certain condition. My issue is that when I click the button, a popup should appear, but instead, it also navigates to the next page in the background. Can someone help me figure out h ...