Stop an idle event in the Google Maps API v3

I use a Google map with marker settings to show locations on the map. I use an event idleto determine when to send a request for new data, so when the user clicks or zooms in on the map, the ajax service will be called and the markers will be updated to find locations in a new viewport.

The problem is that when a user clicks on a marker to pop up a window, the map often moves slightly to the center of the infowindow, which fires another event idleand discards the map, closing the infowindow.

Is there any best practice for this? Is there a way to disable the listener idlewhen I open the info field, or is there a standard workaround?

+4
source share
2 answers

I had a similar problem with my googleMaps and here was my solution ...

During my call of markers, I loaded points outside the viewport. For example .... If my N-lat was 85, and my S-bit was 88, I would have typed the points between 83 and 90 latitudes.

viewportN = 85;
viewportS = 88;
searchBoundN = 83;
searchBoundS = 90;

When you click on a marker, it automatically sets you up so that your Northbound is now 84. You add an if statement to your unoccupied function, which states:

 map.addListener("idle", function () {
      //get map viewport bounds
       .....
      // check if you're in territory that doesn't have markers
      if (viewPortN < searchBoundN || viewportS > searchBoundS || <<repeat for E, W>>) {
           refreshMarkers();
      }
});

. script . , , . , .

0

, , Front-end development, , , "" " ", .

, , . .

"idle", ( , ) "" , isUserInteraction .

0

Source: https://habr.com/ru/post/1543437/


All Articles