Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 226533
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T19:31:15+00:00 2026-05-11T19:31:15+00:00

I have a large set of data to be plotted on google map. Because

  • 0

I have a large set of data to be plotted on google map. Because of the data set size, google map always freezes for a few seconds before all the points are plotted. I used an animated spinning circle during the loading time to show it’s in progress. But end users prefer to see actions. They want data plotted on the map step by step, instead of all at a once. Since javascript doesn’t support multithreading, what’s the best way to approach this?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-11T19:31:15+00:00Added an answer on May 11, 2026 at 7:31 pm

    Javascript engine executes functions one by one by taking them from sort of a queue. Functions can be put there either by your script or as result of user’s actions (event handlers). So idea is to split long-running task into small short-running subtasks and feed them into this ‘queue’ in the manner so they can be mixed with functions responding to user’s action.
    This can be done by calling window’s setTimeout with zero delay and passing your sub-task as a function. Thus you will give a chance for UI event handler to be executed earlier

    function plotSpot(spot) {
        // adding spots to map
    };
    var spots = [1,2,3,4,5,6,7,8,9,10,11,12];
    var plotSpotsBatch;
    plotSpotsBatch = function() {
        var spotsInBatch = 10;
        while(spots.length > 0 && spotsInBatch--) {
            var spot = spots.shift();
            plotSpot(spot);
        }
        if (spots.length > 0) {
            setTimeout(plotSpotsBatch, 0);
        }
    };
    plotSpotsBatch();
    

    Here is extension for Array prototype:

    Array.prototype.forEachInBatches = function(batchSize, func) {
        var arr = this;
        var i = 0;
        var doer;
        doer = function() {
            setTimeout(function() {
                for (var stopBatch = i + batchSize; i < stopBatch && i < arr.length; i++) {
                    func(arr[i], i);
                }
                if (i < arr.length) {
                    doer();
                }
            }, 0);
        };
        doer();
    };
    

    Usage example (you have to have div with id ‘spots’ somewhere in document). To see the difference, set batch size equal to number of spots:

    var spots = [];
    for (var i = 0; i < 10000; i++) {
        spots.push('{x: ' + Math.ceil(Math.random() * 180) + ', y: ' + Math.ceil(Math.random() * 180) + '}');
    }
    spots.forEachInBatches(10, function(spot, i) {
        document.getElementById('spots').innerHTML += spot + (i < spots.length ? '; ' : '');
    });
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a large data set and I would like to read specific columns
I have a large data set of nucleotide sequences (long strings simply put) which
I have a large set of real-world text that I need to pull words
I have a set of approximately 1.1 million unique IDs and I need to
I work with an application that uses a large set of xml interfaces for
We have pretty large files, the order of 1-1.5 GB combined (mostly log files)
I have a large number of styles defined for my grid (cell colors based
This is based on a question I asked yesterday. It got very muddled, so
I am new to mySQL and would like some help with a query I'm
Edit: For simplicity, and in order to try and make this question and the

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.