Modification of data in amCharts4 doesn't automatically update the map display

I am integrating amcharts4 into a meteor project to display a map with dynamic map markers. These map markers need to update themselves whenever the underlying data changes.

I have tried to customize the demo available at this link.

The only modification I made was to assign a different set of data to the imageSeries in order to update the markers on the map dynamically.

You can view and test the functionality in action using this jsfiddle. The setTimeout function is used to simulate a data change every 5 seconds.

setTimeout(function(){
    $('.map-marker').remove()
    imageSeries.data = [{
       "zoomLevel": 5,
       "scale": 0.5,
       "title": "Brussels",
       "latitude": 50.8371,
       "longitude": 4.3676
     }];
    imageSeries.validateData();
}, 5000)

The data does update after 5 seconds, however, the new points do not appear on the map until manual interaction such as panning, zooming in/out occurs.

I am looking for a solution to resolve this issue.

Answer №1

After the redraw/update, AmCharts will indeed update the map. However, the issue arises from utilizing custom HTML markers instead of the standard functionality with simple images like in this demonstration. Since a custom setup is being used, an additional step becomes necessary. It's worth noting that this demo was originally created for version 3, which lacked support for native HTML markers.

Within the demo, updateCustomMarkers is responsible for initially placing the markers on the map. The demo showcases setting up custom markers by assigning this method to the mappositionchanged event of the map instance. This event is triggered during the initialization of the map due to zooming and viewport positioning inherent upon creation. Consequently, the markers are only visible after manually zooming in. In your case, the data update timeout does not include a call to updateCustomMarkers, resulting in the custom markers not being displayed unless the method is manually invoked afterwards. Additionally, there is no need to execute invalidateData when substituting the entire array.

setTimeout(function() {
  $('.map-marker').remove()
  imageSeries.data = [{
    "zoomLevel": 5,
    "scale": 0.5,
    "title": "Brussels",
    "latitude": 50.8371,
    "longitude": 4.3676
  }];
  updateCustomMarkers();
}, 5000)

It should be noted that this extra step is unnecessary when utilizing native images, as the map automatically updates the markers in such cases.

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

JavaScript fails to display image slideshows upon loading

Currently, I am utilizing a slideshow feature in order to display any additional images that may be retrieved from the globalgiving api. However, there is an issue with the slideshow not appearing when the page is initially loaded or when opening a modal, ...

Creating a 3D image gallery within a cube using the three.js library

Embarking on my journey to learn JavaScript, I am now delving into the world of WebGL using Three.js. Currently, my goal is to create a rotating cube along the x-axis as a starting point. This cube will feature four different textures - images and text - ...

Update the grand total based on the values of the checkboxes

I have a code snippet that successfully calculates the total value based on the checkboxes that are selected. Each checkbox has a data attribute value, and I want the total to update dynamically as checkboxes are ticked or unticked. Currently, the code ju ...

What is the reason for not being able to retrieve query parameters in "getStaticProps"?

Let's simplify things: URL: http://localhost:3000/product/bioCloths?activeCategory=medium&id=0 File location: pages/product/[product].js. Expected output: product: "bioCloths, activeCategory: "medium", id: "0" using g ...

Is there a way to delete highlighted text without using execCommand and changing the font color

With my current use of JavaScript, I am able to highlight or bold a selected text range successfully. However, I am unsure how to undo the bold and unhighlight the text if the button is clicked again and the selected range is already bolded or highlighted. ...

Enable checkboxes to be pre-selected upon page loading automatically

Although I've found a lot of code snippets for a "select all" option, what I really need is more direct. I want the WpForms checkboxes to be pre-checked by default when the page loads, instead of requiring users to press a button. My goal is to have a ...

When pasting content that exceeds a certain height, Quill will automatically scroll to the top on webkit-based browsers such as Chrome

This was my original query here I've been attempting to recreate the auto-grow functionality showcased in their interactive playground My approach involved adding a scrolling container and setting specific heights for elements, however, You can als ...

Is it possible to track traffic using Alexa or SimilarWeb on a single-page application?

We are currently grappling with the challenge of how to effectively track traffic and user engagement within our classified sites on a single-page application built in angularJS. While we have successfully managed SEO and tracking with Google Analytics, we ...

Exploring ways to utilize array.find by comparing it to a different object

There are two arrays in JavaScript named designs and articles. var designs = [ { design_id:"bwbmbqlujurv", article_id:14782, name:"adidas demogorgon black" }, { design_id:"lg9yba2gkcwr", article_id:14782, name:"harry potter w ...

Issue with Canvas rendering functionality

Having some trouble testing my app with canvasrenderer as a backup for webgl. I'm having difficulty getting it to start properly. renderer = new THREE.CanvasRenderer(); console.log('renderer', renderer); renderer.sortObjects = true renderer ...

Dealing with SSE reconnection errors in Angular 8

Currently, as part of an Angular 8 project with Electron 6 and Ionic 4, we are in the evaluation phase of deciding whether to replace polling with either SSE (Server-sent events) or Web Sockets. My task involves researching SSE. To test SSE, I set up a sm ...

analyzing strings by comparing their characters to another string

In a scenario where I have two strings; let's call them string a="a-b-c" and string b="a-b". I am looking to determine whether every letter in string b is present within string a. ...

What is the best way to add a CSS rule to JavaScript?

animation: scaleUp 0.3s linear 0.4s forwards; animation: scaleDown 0.3s linear forwards; Greetings! I'm currently working on adding animations to my content filtering functionality. Specifically, I want to incorporate the aforementioned CSS rules in ...

Trigger AJAX request upon selecting a value from the dropdown menu

I am in the process of creating a basic dropdown menu that is only visible to users on mobile devices when they visit our website. The main objective is to allow users to select a value and then have that value sent via AJAX. For desktop devices, I have s ...

Exploring Point Clouds with Three.js

My Three.js point creations are appearing as squares instead of rounds. I've come across blending factors in the documentation, but I'm unsure how to apply them to my points or if it's the correct method for achieving rounded points. ...

The functionality of jQuery's toggleClass is not functioning properly when clicking on a different thumbnail

My objective: I want to display a set of thumbnails. When a thumbnail is clicked, I want to toggle the hiddenElement class and show a large image inside a hidden div. If anywhere in the DOM is clicked, it should hide the current image or allow the user t ...

Retrieve the Current Time with an Ajax Request

Hi there, I am facing an issue with calling code from an ajax request for getting the current time. I have set up an HTML file with a working clock in it, but when loading the text from $container1, the clock and date are not displaying on the page. Can an ...

Angular's change detection mechanism surrenders after the secondary data load on a single-page application

In my single-page application (SPA), I have a feature that displays a large dataset in batches. To handle this, I implemented a component at the end of each batch using a 'Visibility' directive. When this component becomes visible, a new request ...

Switch effortlessly between various THREE.EffectComposer scenes with a single renderer in three.js

Currently, I'm experimenting with creating intricate scenes using Composer in three.js. I'm curious to know if it's achievable to switch between two scenes with distinct composer effects applied to them. To better understand this concept, I& ...

Create a substitute for Object.seal, Object.freeze, and Object.preventExtensions applications

Is there a way to freeze an object's existing properties while still allowing new ones to be added? I can't seem to find any built-in functionality for Object.freezeExisting(), so maybe it's worth considering implementing it, possibly even w ...