Completed processing graphical event layer

I am utilizing the Google Maps API v3 to build a map with multiple layers that are loaded upon user request. The layers are loaded in Geojson format using the following code:

function getgeojson(json) 
    {            
        proplayer = new google.maps.Data();
        proplayer.loadGeoJson('../public/geoprop/index');
        proplayer.setStyle({  
                               fillColor: 'red',
                               strokeColor: 'red',
                               fillOpacity: 0.3,
                               strokeWeight: 1
                            });
         proplayer.setMap(map);                 
         proplayer.addListener('mouseover', function(event) {                                   
                                infoWindow.setContent(event.feature.getProperty('kta'));
                                infoWindow.setPosition(event.latLng);
                                infoWindow.open(map);
                            });     

    }

The layers consist of approximately 3.5 K polygons with simple geometries (mainly rectangular shapes) and take around 5 seconds to be fully displayed on the map. To indicate loading while the layer is rendered, I am using two functions:

ajaxindicatorstart('loading data.. please wait..');
ajaxindicatorstop();

to initiate and stop the loader. However, I am facing difficulty in detecting when the rendering is completed. I have attempted using:

proplayer.addListener( 'metadata_changed', function () {ajaxindicatorstop();}); 

and

google.maps.event.addListener(map, 'idle', function() {
                                            ajaxindicatorstop();
                            }); 

suggested by other users but it was not successful. Is it possible to achieve this? Are there any alternative solutions to overcome this issue?

Thank you in advance

Answer №1

One potential method to consider:

  1. Instead of using loadGeoJson, load the JSON data through AJAX
  2. Determine the number of features in the JSON file and save this value to a variable
  3. Monitor the addfeature event of the layer (more details provided at the end)
  4. Use addGeoJson to add the features to the layer

Within the addfeature handler, you can decrease the feature count that was stored in step 2. When it reaches 0, all features have been successfully added.

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

Share edited collection with Observer

The challenge Imagine creating an Angular service that needs to expose an Observable<number[]> to consumers: numbers: Observable<number[]>; Our requirements are: Receive the latest value upon subscription Receive the entire array every tim ...

An error occurs when attempting to assign a value to a MUI file TextField

Struggling with setting the value of a MUI Textfield that has type="file" props, resulting in the following exception being thrown: Uncaught DOMException: An attempt was made to use an object that is not, or is no longer, usable Interest ...

What is the best way to transfer the data from one JavaScript object to a new, empty object?

My Angular site requires a JavaScript object (JSON retrieved from a database) to display widgets: [{'widget_id':'1','widget_name':'Blue Widget','widget_description':'A nice blue widget','wid ...

Utilizing Vue.js to ensure that nested components remain within the parent component even when the store

I have been working on a chat messaging system, where I initially populate the store with root messages and then map the state of that list (array). Everything works fine when posting a new message - the store updates and displays the new post. However, I ...

Exploring Angular 4's Capabilities: Navigating a Multi-Dimensional Array

I am currently working with a multi-dimensional array that has two keys, and it is structured as follows: user: any = {}; // The index is incremented within a for loop to add values to the user object (this part is functioning correctly) this.user[index++ ...

What is the best way to incorporate a smooth transition for an object as it appears on the screen in React?

After configuring my code to display a component in the HTML only if a specific hook is set to true, I encountered an issue with a CSS transition. The problem arises because the 'open' class is triggered at the same time the element becomes true, ...

When using $.getJSON and $.ajax, the expected JSON object is not being returned

Currently, I am taking on the "local weather" front-end development challenge on freecodecamp.com. However, I'm facing some challenges when it comes to making an API call to fetch weather data from various weather APIs. This particular task requires r ...

JavaScript is throwing an error stating that the requestData is undefined, even though the

Hello, I am attempting to retrieve weather information based on the country and city using the openweather api. JSON is a new concept for me in coding, so please bear with me through this learning process. Below is the code snippet that I have been workin ...

Dividing a set of dates into intervals

My goal is to organize this array of objects into smaller arrays based on consecutive dates. These bookings span the next couple of years and I need to break them down efficiently. [ { state: 'BOOKED', date: 2017-01-01T23:00:00.000Z }, { state ...

Identify the significance within an array and employ the filter function to conceal the selected elements

I'm in the process of filtering a list of results. To do this, I have set up a ul list to display the results and checkboxes for selecting filter options. Each item in the ul list has associated data attributes. When a checkbox with value="4711" is c ...

"Is there a way to modify the color of the button once it's been clicked, but only for the specific button that was

Looking to create a Quiz App using React and facing an issue where all buttons change color when clicked, instead of just the one that was clicked. Any solutions on how to make only the clicked button change its color in React.js? App.js import Main from ...

Unable to view the most recent state

Looking at the code below: export function loginUserRequest() { console.log('ACTION INITIATED'); return { type: LOGIN_USER_REQUEST, }; } we can see the matching reducer: export default function loginReducer(state = initialState, acti ...

Steps for automatically toggling a button within a button-group when the page is loaded using jQuery in Bootstrap 3

Here is a button group setup: <div class="btn-group" data-toggle="buttons"> <label class="btn btn-default"> <input type="radio" name="environment" id="staging" value="staging" />Staging </label> <label class= ...

I am looking to enhance the readability of my asynchronous function calls

At the moment, I am handling my Promises by calling an async function and then chaining it with .then(). But I feel like there could be a more readable approach. This is how it currently works: const fetchData = async() => { const response = await ax ...

Dynamically assigning anchor tags to call JavaScript functions

Creating a list dynamically, full of <span class="infa9span"><img src="/csm/view/include/images/foldericon.png"/><a id="infa9Service">'+servicename+'</a><br/></span> tags. This list is then appended to a div. ...

Generate Swagger documentation for an API developed using Express 4.x

My challenge lies in documenting my Node and Express 4 server with Swagger for a client. I have explored various tools for this purpose, but haven't found the perfect fit yet. The swagger-node-express tool seems promising, but unfortunately does not ...

Traversing through nested arrays within nested objects using AngularJS

In my project, I am utilizing angularjs 1 and dealing with a complex json object that has multiple levels of nesting. My goal is to use ng-repeat in order to access a nested array within the json structure. [{ "information": { "name": "simdi jinki ...

Manipulating prop values through dropdown selection

I'm currently working on implementing filtering based on a prop value that changes according to the dropdown selection. Here's my progress so far: template(v-for="field in tableFields") th(:id="field.name") select(@change="filterScope(sc ...

Using jQuery to extract the value of an object from an <li> element and updating the class attribute of the <li> element

There is a div element: <div id="ddDistr" class="searchBoxSortDistrict" tabindex="1"> <ul id="ddd"> </ul> </div> I have inserted HTML from json into it: $("#ddd").html(" "), $.each(dis, function( index, value) { $("#dd ...

Having trouble with the page redirection issue? Here's how you can troubleshoot and resolve

My goal is to restrict access to both the user home and admin dashboard, allowing access only when logged in. Otherwise, I want to redirect users to the login or admin login page. import { NextResponse } from 'next/server' import { NextRequest } ...