Is Google Maps smart enough to refrain from adding

2019-08-01 04:28发布

In my app/site, I start off showing the contiguous USA but allow the user to select a state (or go back to USA48, or select USA50+) from a dropdown list (selection widget):

<select id="stateSelector">
  <option id="USA48">USA (48)</option>
  <option id="USA50">USA (50+)</option>
  <option id="Alabama">Alabama</option>
  . . .
  <option id="Wyoming">Wyoming</option>
</select>

I also allow the user to display various categories of markers depending on checkbox selections they make. These markers are placed anywhere in the "extended USA" (including American Samoa, the Dry Tortugas, etc.).

When they select a state, such as Alabama, I need to "invalidate" the map data first, like so (the "removeData" line is key to what I am referring to here):

function LoadAlabama() {
      $("#map").removeData();
      $("#map").goMap({ 
            latitude: 32.806673, 
            longitude: -86.791133, 
            zoom: 8 
      }); 
      ReloadMarkers();
}

However, I don't want to have all the markers load, as they won't be visible (I only need one state capital marker, not 50; I only need one NFL team marker, not 32, etc.). Is Google Maps smart enough to ignore requests to place markers at places outside of the currently displayed map?

Note: The ReloadMarkers() method shows or hides groups of markers, like so:

function ReloadMarkers() {
    if ($('#NFLCheckbox').is(':checked')) {
        $.goMap.showHideMarkerByGroup('NFLGroup', true)
    } else {
        $.goMap.showHideMarkerByGroup('NFLGroup', false)
    }
    . . . 
}

I could write code to take into consideration the area being displayed, and then filter out those markers that fall outside the longitude/latitude range of what is being displayed (based on it's central lat/long and the map's zoom value), but I would be content (to put it mildly) if Google Maps is smart enough to do that for me. Is it?

1条回答
The star\"
2楼-- · 2019-08-01 05:11

Is Google Maps smart enough to ignore requests to place markers at places outside of the currently displayed map?

No. However there are two mitigating factors/options:

  1. Unless the markers have either optimized:false or draggable:true set, they will be drawn on canvas tiles. This highly optimized method can handle over 10,000 markers very fast. Gone are the performance bottlenecks of the old DOM markers.
  2. If you need DOM markers, you can use the MarkerManager library in the Google Maps API v3 utility library.
查看更多
登录 后发表回答