What is the best way to iterate through a multi-dimensional array and only load a single section at a time? - Using JavaScript

I have a massive multidimensional JavaScript array object that stores coordinates of numerous earthquakes.

Here is an example:

var earthquakeArray = [
            [
            0 : {
              "place": "home",
              "lat": "30",
              "lng": "40"
              },
            //...//
            400 : {
              "place": "home",
              "lat": "30",
              "lng": "40"
              }
            ],
           [
            0 : {
              "place": "home",
              "lat": "30",
              "lng": "40"
              },
            //...//
            400 : {
              "place": "home",
              "lat": "30",
              "lng": "40"
              }
            ]
           ];

Each "array container" contains 400 earthquake records. The entire array can include more than 120,000 earthquakes...

Displaying all this data on Google Maps takes a long time, so I attempted to show the earthquakes in each "array container" (every 400) one by one.

I tried looping through the array like this:

 for(var f= 0; f < earthquakeArray.length; f++){   
    for(var i= 0; i < earthquakeArray[f].length; i++){ 
     //add earthquakes/markers on Google Maps
    }
 }

However, there doesn't seem to be a progressive loading action, as all earthquakes in the array load at once. This results in a lengthy waiting time for users....

Do you have any suggestions on how to address this issue?

Could using AJAX help resolve this problem?

Answer №1

To enhance filter control, consider creating a function specifically for this purpose. I have made updates to JSFiddle showcasing a potential solution. One approach is to implement a function like filterTurma() as demonstrated below:

$scope.filterTurma = function(user) {

// If the selected value is '!!' (meaning 'Everyone'), 
// simply return 'true' to display all cases...
if ($scope.search_turma.turmas.value == '!!')
return true;

// Otherwise, iterate through the user's classes and check if at least
// one matches an advanced class in the combobox...
for (var i = 0; i < user.turma.length; i++) {
var turma = user.turmas[i];
if (turma.value == $scope.search_turma.turma.value)
return true;
}

// If no match is found, return 'false' to hide this user...
return false;
};

In essence, your combo box contains various classes including an option labelled "Everyone" with the value '!!'. The logic of the filter function checks if the current item's value aligns with the selected class in the combobox or if any of the user's classes correspond to it. To apply this filtering in your HTML, utilize the following syntax:

tr ng-repeat="user in dataUserAndTurma | filter: {name: search_nome} | filter: filterTurma"

Notice that the method name does not include parentheses (AngularJS automatically passes the current user iteration to the method). Furthermore, the original filter is retained, ensuring both filters work in tandem.

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 an issue with both of my states being called simultaneously, resulting in a TypeError: Cannot read property 'map' of undefined

I am facing an issue with displaying both of my states on localhost (I am receiving the following error message: TypeError: Cannot read property 'map' of undefined). Skills.js import React, { Component } from 'react'; import ProgressBa ...

Encountered an error: Uncaught TypeError - Unable to access property 'active' as it is undefined within React code

<script type="text/babel"> class Frame extends React.Component{ render(){ return ( <div> <h2 className="os-animation" dat ...

Detect the initial collision exclusively (Collision detection using raycasting)

I am currently working on a never-ending runner game where a character is positioned at (0,0) and can only move along the X-axis by using arrow keys or the mouse. There are two different types of objects moving from z = -10000 towards the character, and on ...

Executing JavaScript functions within Vue JS components

I'm currently working on a project that involves Vue JS within a Laravel Project Can someone guide me on how to fetch data from another JS file? Here's what I have so far: MainComponent.vue data() { return this.getData() } DataComponent.j ...

Utilizing the variable $this outside of an object context within an Ajax function

Encountering the following error: Fatal error: Uncaught Error: Using $this when not in object context in E:\xampp\htdocs\StudentGuideBook\Version1.0\models\AjaxChecking.php:4 Stack trace: #0 {main} thrown in E:\xampp&b ...

How to remove the initial negative value present in an array using C#

I have searched for various solutions, but none of them effectively address my requirement to eliminate the initial negative number in a sequence while retaining the others (there may be several negative numbers in the array). ...

Adjusting the height of a vertical slider in Vuetify2 is not customizable

I've been trying to adjust the height of a vertical slider in vuetify2, but setting it to "800px" or using style="height:800px" doesn't seem to work as intended. Even though the box within my grid expands, the height of the slider remains unchan ...

Accessing several values in Angular by clicking

I have a dropdown that contains an input field and two more dropdowns. I am looking for a way to retrieve the values of all three fields when the search button is clicked. Screenshot https://i.sstatic.net/5Imaq.png Code HTML <nz-dropdown-menu #menu=&q ...

Exploring the Factory Design Pattern Together with Dependency Injection in Angular

I'm currently implementing the factory design pattern in Angular, but I feel like I might be missing something or perhaps there's a more efficient approach. My current setup involves a factory that returns a specific car class based on user input ...

What Are the Possible Use Cases for Template Engine in Angular 2?

For the development of a large single page application (SPA) with Angular 2.0, I have decided to utilize a template engine like JADE/PUG in order to enhance clarity and clean up the code. My goal is to achieve optimal performance for the application. Th ...

PHP Brandwatch HTTP API Request

Upon making an API request, a server response in JSON format is returned as a single string: {"resultsTotal":3,"resultsPage":-1,"resultsPageSize":-1,"results":[{"id":1998425622,"name":"Regionale Mentions_Branche","type":"search string","creationDate":"201 ...

What coding techniques can be used to create dynamic animation of a log stream in javascript/css

When I have a series of events in my browser, I want to display them as a list with a smooth animation effect. As each new event comes in, I'd like the existing items to slide down gracefully, making room for the new event to fade in at the top of the ...

Accessing error information from server side through AJAX request in C#

When my application makes an AJAX call and encounters an error, I want to be able to capture it on the client side. What is the best approach for achieving this? Here is my server-side code: try { ... } catch (Exception ex) { throw new HttpExce ...

extract information from a document and store it in an array

As I delve into the realm of programming, I find myself grappling with the best approach to extract data from a file and store it in an array. My ultimate aim is to establish a dictionary for a game that can verify words provided by players. Despite my no ...

Troubleshooting AJAX, PHP, and mySQL Interactions

I am experiencing issues with my password change script on my website. I am utilizing an AJAX connection to my php file. While my database connection seems stable and variables are being sent correctly (based on firebug), they seem to disappear along the w ...

Discovering duplicates for properties within an array of objects in React.js and assigning a sequential number to that specific field

I am working with an array of objects where each object contains information like this: const myArr=[{name:"john",id:1}{name:"john",id:2}{name:"mary",id:3}] In the first 2 elements, the "name" property has duplicates with the value "john". How can I updat ...

transition from jQuery to Zepto

I have been utilizing multiple jQuery plugins in my codebase... Recently, I decided to switch over to Zepto, but encountered an issue Uncaught TypeError: Object function (a,b){return A.init(a,b)} has no method 'data' when checking the console ...

Subdomain for an Ajax request

Can we use ajax requests to extract data from and fetch information from pages like ? It appears that JavaScript still does not permit subdomain requests. ...

Using Jquery to access Wcf service

Being unfamiliar with WCF services and coming from a Java background, I am seeking guidance on utilizing a specific WCF service at http://192.168.1.5/xeservices/AccountManagement.svc using jQuery and ajax. Unfortunately, I do not have access to .NET on m ...

Can Backbone be used to retrieve a local JSON file?

I have a simple and validated local JSON file that I am trying to fetch using Backbone.js. Here is the snippet of Backbone.js code: MyModel = Backbone.Model.extend({ defaults:{ name: '', age: 0 } }); MyCollection =Backbo ...