0

希望这是有道理的。我将两张表合并在一起,一张包含有关电话交换机及其在英国的具体位置的信息,另一张包含英国的地区信息。我想要做的是,当我滚动或单击一个区域时,我希望能够在我的网页面板上列出属于该区域的所有交易所。在我单击一个区域时,会显示表中的最后一个交易所。我猜这可能是我需要在 addListeners2() 函数中做的简单事情。任何指向正确方向的指针将不胜感激。

var map, layer;   
function initialize() 
{

    map = new google.maps.Map(document.getElementById('map_canvas'), {
            center: new google.maps.LatLng(54.54658,-4.87793),
            zoom: 6,
            mapTypeId: google.maps.MapTypeId.ROADMAP
          });
          loadPoint();            
    }  

        function loadPoint() 
        {
           if (layer != null) 
           {
                layer.setMap(null);
                google.maps.event.clearInstanceListeners(layer);
           }
           var tableid = '3569550';
           layer = new google.maps.FusionTablesLayer
           ({
                query: 
                {
                    select: 'LATITUDE',
                    from: tableid
                    //where: 'latitude is not null'
                },

            map: map                
           })
            layer.enableMapTips({
            select: "'REGION','EXCHANGE','MPF','WLR','SMPF','BB_CONNECT'", // list of columns to query, typially need only one column.
            from: tableid, // fusion table name
            geometryColumn: 'LATITUDE', // geometry column name
            suppressMapTips: true, // optional, whether to show map tips. default false
            delay: 100, // milliseconds mouse pause before send a server query. default 300.
            tolerance: 8 // tolerance in pixel around mouse. default is 6.
            });
            addListeners1();
        }

        function loadRegion() 
        {
           if (layer != null) 
           {
                layer.setMap(null);
                google.maps.event.clearInstanceListeners(layer);
           }
           var tableid = '3569550';
           layer = new google.maps.FusionTablesLayer
           ({
                query: 
                {
                    select: 'geometry',
                    from: tableid
                },

            map: map                
           })
            layer.enableMapTips({
            select: "'REGION','EXCHANGE','MPF','WLR','SMPF','BB_CONNECT'",
            from: tableid, // fusion table name
            geometryColumn: 'geometry', // geometry column name
            suppressMapTips: true, // optional, whether to show map tips. default false
            delay: 100, // milliseconds mouse pause before send a server query. default 300.
            tolerance: 8 // tolerance in pixel around mouse. default is 6.
            });
            addListeners2();
        }

        function addListeners1() 
        {
            google.maps.event.addListener(layer, 'mouseover', function(fEvent) 
            {
                var row = fEvent.row;
                myHtml = '<TABLE width = "600" cellspacing="0" cellpadding="0"><TR>';
                myHtml += '<TD><b>REGION</b></TD>';
                myHtml += '<TD><b>EXCHANGE</b></TD>';
                myHtml += '<TD><b>MPF</b></TD>';
                myHtml += '<TD><b>WLR</b></TD>';
                myHtml += '<TD><b>SMPF</b></TD>';
                myHtml += '<TD><b>BB_CONNECT</b></TD></TR><TR>';
                for (var x in row) 
                {
                    if (row.hasOwnProperty(x)) 
                    {
                        myHtml += '<td>' + row[x].value +'</td>';
                    }
                }
                myHtml += '</TR></TABLE>';
                document.getElementById('info').innerHTML = myHtml;
            });
        }

        function addListeners2() 
        {
            google.maps.event.addListener(layer, 'mouseover', function(fEvent) 
            {
                var row = fEvent.row;
                myHtml = '<TABLE width = "600" cellspacing="0" cellpadding="0"><TR>';
                myHtml += '<TD><b>REGION</b></TD>';
                myHtml += '<TD><b>EXCHANGE</b></TD>';
                myHtml += '<TD><b>MPF</b></TD>';
                myHtml += '<TD><b>WLR</b></TD>';
                myHtml += '<TD><b>SMPF</b></TD>';
                myHtml += '<TD><b>BB_CONNECT</b></TD></TR><TR>';
                for (var x in row) 
                {
                    if (row.hasOwnProperty(x)) 
                    {
                        myHtml += '<td>' + row[x].value +'</td>';
                    }
                }
                myHtml += '</TR></TABLE>';
                document.getElementById('info').innerHTML = myHtml;
            });
        }
}
4

2 回答 2

0

我找到了解决办法!!!

function loadRegion() 
{
    if (layer != null) 
    {
        layer.setMap(null);
        google.maps.event.clearInstanceListeners(layer);
    }
    layer = new google.maps.FusionTablesLayer
    ({
        query: 
        {
            select: 'geometry',
            from: tableid
        },
        map: map                
    })
    google.maps.event.addListener(layer, 'click', function(e) 
    {
        if (e && e.row && e.row["REGION"]) 
        {
            query4infowindowData(e.row["REGION"].value);
            infowindow.setPosition(e.latLng);
        } 
        else 
        {
            alert("no row:"+e.latLng);
        }
    });
}
function query4infowindowData(term) 
{
    var queryText = "SELECT 'REGION', 'EXCHANGE', 'MPF', 'WLR', 'BB_CONNECT', 'SMPF' FROM "+tableid+" WHERE 'REGION' = '"+term+"';";
    var encodedQuery = encodeURIComponent(queryText);
    var query = new google.visualization.Query('http://www.google.com/fusiontables/gvizdata?tq='  + encodedQuery);
    query.send(openInfoWindow);
}
function openInfoWindow(response) 
{
    if (!response) 
    {
        alert('no response');
        return;
    }
    if (response.isError()) 
    {
        alert('Error in query: ' + response.getMessage() + ' ' + response.getDetailedMessage());
        return;
    } 
    FTresponse = response;
    numRows = response.getDataTable().getNumberOfRows();
    numCols = response.getDataTable().getNumberOfColumns();
    var dataTable = response.getDataTable();
    var contents = "REGION: <u><b>"+dataTable.getValue(0,0)+"</b></u><br><table border='1'><tr><th>#</th><th>EXCHANGE</th><th>MPF</th><th>WLR</th><th>BB_CONNECT</th><th>SMPF</th></tr>";
    for(i = 0; i < numRows; i++) 
    {
        contents += "<tr><th>"+i+"</th><td>"+dataTable.getValue(i,1)
            +"</td><td>"+dataTable.getValue(i,2)
            +"</td><td>"+dataTable.getValue(i,3)
            +"</td><td>"+dataTable.getValue(i,4)
            +"</td><td>"+dataTable.getValue(i,5)
            +"</td></tr>";
    }
    contents += "</table>";
    document.getElementById('info').innerHTML = contents;

}
于 2012-05-04T13:56:05.273 回答
0

我不熟悉Fusion Tips实用程序库,但文档显示它不支持 where 子句。哪种有意义。工具提示将与单个点或多边形相关联。您需要一个 where 子句,即选择交换 where region = XXX。

我会尝试 google.visualization 库,它允许您执行这样的查询,或者您可以使用允许相同的 Fusion Table JSONP API。这里有一个可视化示例,有点不同,但可以修改以处理您想要做的事情。

于 2012-04-26T17:30:08.097 回答