Google地图是否足够聪明,避免在当前未显示的位置添加标记? [英] Is Google Maps smart enough to refrain from adding markers at positions that are not currently being displayed?

查看:141
本文介绍了Google地图是否足够聪明,避免在当前未显示的位置添加标记?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的应用/网站中,我开始显示连续的美国,但允许用户从下拉列表(选择小部件)中选择一个状态(或返回USA48,或选择USA50 +):

 < select id =stateSelector> 
< option id =USA48> USA(48)< / option>
< option id =USA50> USA(50 +)< / option>
< option id =Alabama>阿拉巴马州< / option>
。 。 。
< option id =Wyoming> Wyoming< / option>
< / select>

我还允许用户显示各种标记,具体取决于他们所做的复选框选择。这些标记放置在扩展美国的任何地方(包括美属萨摩亚,干燥的Tortugas等)。

当他们选择一个州时,比如阿拉巴马州,我需要首先使地图数据无效,就像这样(removeData行是我在这里提到的关键):

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

但是,我不希望 标记加载,因为它们不可见(我只需要一个状态大写标记,而不是50;我只需要一个NFL团队标记,而不是32等)。 Google Maps是否足够聪明,可以忽略将标记放置在当前显示的地图之外的地方?

注意:ReloadMarkers()方法显示或隐藏标记组,如所以:

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

我可以编写代码来考虑显示的区域,然后过滤那些超出正在显示的经度/纬度范围的标记(基于它的中央纬度/长度和地图的缩放值),但如果Google地图足够聪明,我会满足于(轻描淡写)。那对我来说。是否?

解决方案


谷歌地图足够智能,可以忽略将标记置于当前显示的地图?


没有。但有两个缓解因素/选项:


  1. 除非标记具有优化:false draggable:true 设置,它们将在画布上绘制。这种高度优化的方法可以非常快速地处理10,000个标记。
  2. 如果您需要DOM标记,您可以使用 MarkerManager库位于 Google Maps API v3实用程序库


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?

解决方案

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.

这篇关于Google地图是否足够聪明,避免在当前未显示的位置添加标记?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆