0

我希望了解如何从 Fusion Tables (FT) 更新 jqGrid 表 -

目前我可以在谷歌地图上搜索或滚动,发送一个事件监听器来编译视口/地图空间边界的 FT 查询,以获得一组新的结果。我想使用新的 FT 查询字符串(或者可以使用 Google 代码来检索数据 - query.send(getData);)用新值更新 jqGrid 表。

在我开始使用 jqGrid 之前,我尝试/成功使用了 Google Visualization API,其中一些代码如下所示。谁能建议如何从 table.draw 移动到加载/重新加载 jqGrid 表?提前非常感谢。

function tilesLoaded() {
        google.maps.event.clearListeners(map, 'tilesloaded');
        google.maps.event.addListener(map, 'zoom_changed', getSpatialQuery);
        google.maps.event.addListener(map, 'dragend', getSpatialQuery);
        getSpatialQuery();  
    }   

    function getSpatialQuery() {
      sw = map.getBounds().getSouthWest();
      ne = map.getBounds().getNorthEast();
      var spatialQuery = "ST_INTERSECTS(latitude, RECTANGLE(LATLNG(" + sw.lat() + "," + sw.lng() + "), LATLNG(" + ne.lat() + "," + ne.lng() + ")))";

      changeDataTable(spatialQuery);
    }

function changeDataTable(spatialQuery) {
  var whereClause = "";
  if(spatialQuery) {
    whereClause =  " WHERE " + spatialQuery;
  }
  var queryText = encodeURIComponent("SELECT 'latitude', 'longitude', 'name' FROM xxxxxxxx" + whereClause + " LIMIT 50");
  var query = new google.visualization.Query('http://www.google.com/fusiontables/gvizdata?tq='  + queryText);
  query.send(getData);
}

function getData(response) {
  var table = new google.visualization.Table(document.getElementById('visualization'));
  table.draw(response.getDataTable(), {showRowNumber: true});
}

哦,我使用 Oleg 的代码jqGrid 返回空白单元格作为基础,看看我是否可以获得一个简单的多选表来从我的 FT 中提取数据——这与简单的 mod 配合得很好

网址:' http ://www.google.com/fusiontables/api/query?sql= '+

4

1 回答 1

0

如果这对某人有帮助,我已经采取了一些我想出的代码并将其粘贴在下面:

// You can get the map bounds via then pass it via a function (below is hacked from several functions
sw = map.getBounds().getSouthWest();
ne = map.getBounds().getNorthEast();
var whereClause = "ST_INTERSECTS(latitude, RECTANGLE(LATLNG(" + sw.lat() + "," + sw.lng() + "), LATLNG(" + ne.lat() + "," + ne.lng() + ")))";

//construct the URL to get the JSON
var queryUrlHead = 'http://www.google.com/fusiontables/api/query?sql=';
var queryUrlTail = '&jsonCallback=?'; // 
var queryOrderBy = ' ORDER BY \'name\' ASC';
var queryMain = "SELECT * FROM " + tableid + whereClause + queryOrderBy + " LIMIT 100";
var queryurl = encodeURI(queryUrlHead + queryMain + queryUrlTail);

//use the constructed URL to update the jqGrid table - this is the part that I didn't know in my above question
$("#gridTable").setGridParam({url:queryurl});
$("#gridTable").jqGrid('setGridParam',{datatype:'jsonp'}).trigger('reloadGrid');
于 2011-10-27T07:18:36.213 回答