【问题标题】:Is there a limit to how many different markers you can have in a fusion layer?融合层中可以有多少个不同的标记是否有限制?
【发布时间】:2012-04-13 21:51:04
【问题描述】:

我有这个融合表层的实现,我尝试使用带有字母 A-Z 的预定义标记图标来在地图上显示搜索查询的结果(就像原始谷歌地图一样)。

我实现这一点的方法是首先创建一个图层,所有标记都有一个通用图标..

var layer = new google.maps.FusionTablesLayer({
    query: {
        select: 'Geometry',
        from: 0000000
    },
    map: map,
    options: {
        suppressInfoWindows: true
    },
    styles: [{
        markerOptions: {
            iconName: "measle_white"
        }
    }]
});

同时,我根据地图的中心位置(地理定位)使用 ST_DISTANCE 排序查询同一张表的 25 个结果,

var queryUrlHead = 'http://www.google.com/fusiontables/api/query?sql=',
    queryUrlTail = '&jsonCallback=success',
    query = 'SELECT+ID+FROM+0000000+ORDER+BY+ST_DISTANCE(Geometry,LATLNG('+position.coords.latitude+','+position.coords.longitude+'))+LIMIT+25';

var queryurl = queryUrlHead + query + queryUrlTail;

返回的 JSON 对象是一个唯一 ID 的数组,我称之为“ids”。然后我使用一些触发器(zoomchanged)用字母图标重绘最近的 25 个图标(由this 启发)。

    google.maps.event.addListener(map, 'zoom_changed', function () {

layer.setOptions({
    styles: [{
            markerOptions: {
                iconName: "measle_white"
            }
        }, //fallback
        {
            where: "'ID' = " + ids.table.rows[0][0],
            markerOptions: {
                iconName: "a_blue"
            }
        }, {
            where: "'ID' = " + ids.table.rows[1][0],
            markerOptions: {
                iconName: "b_blue"
            }
        }, {
            where: "'ID' = " + ids.table.rows[2][0],
            markerOptions: {
                iconName: "c_blue"
            }
        }, {
            where: "'ID' = " + ids.table.rows[3][0],
            markerOptions: {
                iconName: "d_blue"
            }
        }, {
            where: "'ID' = " + ids.table.rows[4][0],
            markerOptions: {
                iconName: "e_blue"
            }
        }, {
            where: "'ID' = " + ids.table.rows[5][0],
            markerOptions: {
                iconName: "f_blue"
            }
        }, {
            where: "'ID' = " + ids.table.rows[6][0],
            markerOptions: {
                iconName: "g_blue"
            }
        }, {
            where: "'ID' = " + ids.table.rows[7][0],
            markerOptions: {
                iconName: "h_blue"
            }
        }, {
            where: "'ID' = " + ids.table.rows[8][0],
            markerOptions: {
                iconName: "i_blue"
            }
        }, {
            where: "'ID' = " + ids.table.rows[9][0],
            markerOptions: {
                iconName: "j_blue"
            }
        }, {
            where: "'ID' = " + ids.table.rows[10][0],
            markerOptions: {
                iconName: "k_blue"
            }
        }, {
            where: "'ID' = " + ids.table.rows[11][0],
            markerOptions: {
                iconName: "l_blue"
            }
        }, {
            where: "'ID' = " + ids.table.rows[12][0],
            markerOptions: {
                iconName: "m_blue"
            }
        }, {
            where: "'ID' = " + ids.table.rows[13][0],
            markerOptions: {
                iconName: "n_blue"
            }
        }, {
            where: "'ID' = " + ids.table.rows[14][0],
            markerOptions: {
                iconName: "o_blue"
            }
        }, {
            where: "'ID' = " + ids.table.rows[15][0],
            markerOptions: {
                iconName: "p_blue"
            }
        }, {
            where: "'ID' = " + ids.table.rows[16][0],
            markerOptions: {
                iconName: "q_blue"
            }
        }, {
            where: "'ID' = " + ids.table.rows[17][0],
            markerOptions: {
                iconName: "r_blue"
            }
        }, {
            where: "'ID' = " + ids.table.rows[18][0],
            markerOptions: {
                iconName: "s_blue"
            }
        }, {
            where: "'ID' = " + ids.table.rows[19][0],
            markerOptions: {
                iconName: "t_blue"
            }
        }, {
            where: "'ID' = " + ids.table.rows[20][0],
            markerOptions: {
                iconName: "u_blue"
            }
        }, {
            where: "'ID' = " + ids.table.rows[21][0],
            markerOptions: {
                iconName: "v_blue"
            }
        }, {
            where: "'ID' = " + ids.table.rows[22][0],
            markerOptions: {
                iconName: "w_blue"
            }
        }, {
            where: "'ID' = " + ids.table.rows[23][0],
            markerOptions: {
                iconName: "x_blue"
            }
        }, {
            where: "'ID' = " + ids.table.rows[24][0],
            markerOptions: {
                iconName: "z_blue"
            }
        }
    ]
});

现在,这实际上非常有效,除了前 5 个结果 A-D(后备图标 +1)。这里出了什么问题?我是否达到了一些限制(markerOptions 只需要 5 个值??)还是我弄乱了代码?

旁注:This example 似乎每层有超过 5 个图标,但 Google 做到了,我一个都不懂。

【问题讨论】:

    标签: javascript google-maps-api-3 google-fusion-tables


    【解决方案1】:

    抱歉,通过 Maps API 只能设置 5 种样式。 developers guide 中提到了此限制。 我怀疑显示所有可能图标的地图不是 FT 图层。如果通过 FT UI 完成,您可以拥有更多样式,但这不是动态的,可能不适用于您的情况。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2012-07-23
      • 2023-03-25
      • 2016-05-15
      • 1970-01-01
      • 1970-01-01
      • 2017-05-09
      • 2011-06-24
      相关资源
      最近更新 更多