通过使用Fusion Table Layer平移和缩放以显示查询结果

Pan and zoom to display the query results by using Fusion Table Layer

本文关键字:缩放 显示 结果 查询 Fusion Layer Table      更新时间:2023-09-26

我是Fusion表层的初学者。我想在这里显示查询结果(平移和缩放):https://developers.google.com/fusiontables/docs/samples/search_and_zoom,但我不能用AND子句为我的函数做这件事:

函数changeMap(){

    var dzialka = document.getElementById('dzialka').value;
    var symbol = document.getElementById('symbol').value;
    var where = '';
    if (dzialka) {
      dzialka = dzialka.replace(/'/g, '''''');
      where = "'NUMER' CONTAINS IGNORING CASE '" +
          dzialka + "'";
    }
    if (symbol) {
      if (dzialka) {
        where += ' AND ';
      }
      where += "SYMBOL_OG = '" + symbol + "'";
    }
    layer.setOptions({
      query: {
        select: locationColumn,
        from: tableid,
        where: where
      }
    });
  }

有人能帮我吗?我将感谢你的帮助。

Trebor

做你想做的事情肯定是可能的,但并不是那么容易。在该示例中,要平移到的位置由Google Geocoding API使用地址计算。但是您的JavaScript代码中并没有地址(即locationColumn的内容)。这取决于你在locationColumn中存储的信息类型,我想这是某种可以进行地理编码的地址。

因此,您必须将select语句直接发送到Fusion Tables。Google Fusion Tables有一个JSONP接口,您可以将其用于此目的。

var gftUrl = 'http://www.google.com/fusiontables/api/query?';
var jsonUrlTail = '&jsonCallback=?';
var query = 'select ' + locationColumn + ' from ' + tableid + ' where ' + where;
var params = "sql=" + encodeURI(query + jsonUrlTail);
var myCallback = function(data,status) {
    if(status !== 'success') {
        window.alert('Call to Google Fusion Tables failed: ' + status);
        return;
    }
    var address = data.table.rows[0][0];
    /* start code from google example */
    geocoder.geocode({
    address: address
    }, function(results, status) {
    if (status == google.maps.GeocoderStatus.OK) {
      map.setCenter(results[0].geometry.location);
      map.setZoom(10);
      // OPTIONAL: run spatial query to find results within bounds.
      var sw = map.getBounds().getSouthWest();
      var ne = map.getBounds().getNorthEast();
      var where = 'ST_INTERSECTS(' + locationColumn +
          ', RECTANGLE(LATLNG' + sw + ', LATLNG' + ne + '))';
      layer.setOptions({
        query: {
          select: locationColumn,
          from: tableId,
          where: where
        }
      });
    } else {
      window.alert('Address could not be geocoded: ' + status);
    }
    });
    /* end code from google example */
}
var jqxhr = $.post(gftUrl, params, myCallback, "jsonp"); /* jsonp parameter is very important */

在本例中,我将jQuery用于$.post函数。