2012-03-19 2 views
2

현재 맵 레이어로 렌더링 된 융합 테이블에서 필터가 작동하고 있으며 필터가 변경 될 때마다 모든 데이터를 가장 잘 맞도록 확대하고 싶습니다.FusionTablesLayer에서 쿼리를 적용한 후 마커를 반복 할 수 있습니까?

나는 내가 최소/최대 X & Y 위치를 찾아 그 사각형으로 이동하는 마커를 반복 다음 쿼리를 적용 할 때까지 기다릴 필요가 파악,하지만 난에 대한지도 API에서 방법을 볼 수 없습니다 레이어의 마커에 액세스합니다.

누구나 어떻게 할 수 있습니까?

답변

0

짧은 대답은 아니오입니다. 필자에게 이것은 Maps API를 통해 Fusion Tables를 처리 할 때의 단점 중 하나입니다. 예 : 가장 최근 쿼리의 결과 수를 표시하려고합니다. 그러나 퓨전 테이블에 대한 "문서화되지 않은"JSONP API를 통한 해결 방법이 있습니다. 나는 그것을 사용하여 큰 성공을 거두었지만 Robin Kraft에게이 API에 대해 알려주지 않으면 안됩니다. http://www.reddmetrics.com/2011/08/10/fusion-tables-javascript-query-maps.html.

다음은 AJAX JSONP 요청을 통해 가장 최근의 쿼리를 다시 실행하고 바운딩 박스 계산과 같은 결과를 원하는대로 수행 할 수있는 코드입니다. 참고 :이 예제에서는 AJAX JSONP 호출에 Jquery를 사용합니다.이 예에서는 디스플레이 > 테이블을 생성하지만 필요에 따라 수정할 수 있습니다.

<script src="http://code.jquery.com/jquery-1.7.1.min.js"></script> 

// Example call 
getFTData(tableid, 'latitude,longitude', example_dataHandler); 

<script> 
// Globals same for all requests 
var queryUrlHead = 'https://fusiontables.googleusercontent.com/fusiontables/api/query?sql='; 
var queryUrlTail = '&jsonCallback=?'; // ? could be a function name 

// getFTData() 
// table_id - Fusion Table id MUST have public permissions 
// col_list - comma separated list of FT column names 
// successFunction - function to parse the CSV results (see exampleParser below) 
////////////////////////////// 
function getFTData(table_id, col_list, successFunction) { 

    var query = "SELECT " + col_list + " FROM " + table_id; 

    var queryurl = encodeURI(queryUrlHead + query + queryUrlTail); 

    $.ajax({ 
     type: "GET", 
     url: queryurl, 
     dataType: "jsonp", // return CSV FustionTable response as JSON 
     success: successFunction, 
     error: function() {alert("AJAX ERROR for " + queryurl); } 
    }); 
} 
function example_dataHandler(d) { 
    // get the actual data out of the JSON object 
    var cols = d.table.cols; 
    var rows = d.table.rows; 
    var row_count = 0; 
    var results = '<table border="1" cellpadding="4">'; 
    results += '<tr>'; 
    for (var i = 0; i < cols.length; i++) { 
     results += '<th>' + cols[i] + '</th>'; 
    } 
    results += '</tr>'; 
    // loop through all rows to add them to the map 
    for (var i = 0; i < rows.length; i++) { 

     // Per the expected columns 
     results += '<tr>'; 
     for(j=0; j < rows[i].length; j++) 
     { 
      results += '<td>' + rows[i][j] + '</td>'; 
     } 
     results += '</tr>'; 
     row_count++; 
    } 
    results += '</table>'; 
    results += '<br />'; 

    results += 'Row Count: ' + row_count + '<br />';; 
    document.getElementById("program_select").innerHTML = results; 
} 

</script> 

반환 된 최근 Fusion Table 행의 수를 검색하는 것이 일반적이므로,이를 수행하는 방법에 대한 스 니펫을 추가합니다. 데이터가 융합 테이블에있는 경우

<script src="http://code.jquery.com/jquery-1.7.1.min.js"></script> 

<script type="text/javascript"> 
var tableid = 3167783 

var where = "WHERE type = 9"; 

getFTCount(current_table_id, where, displayCount); 

// Globals same for all request 
var queryUrlHead = 'https://fusiontables.googleusercontent.com/fusiontables/api/query?sql='; 
var queryUrlTail = '&jsonCallback=?'; // ? could be a function name 

/////////////////////////////// 
// Get Counts from Fusion Tables. 
// table_id required 
// where optional "WHERE column == 'value' " where clause for count() 
// successFunction callback required 
/////////////////////////////// 
function getFTCount(table_id, where, successFunction) { 
    if(!table_id){ 
     alert("table_id required."); 
     return; 
    } 
    if(!successFunction){ 
     alert("successFunction callback required."); 
     return; 
    } 
    var query = "SELECT count() FROM " + table_id; 
    if(where){ 
     query += ' ' + where; 
    } 

    var queryurl = encodeURI(queryUrlHead + query + queryUrlTail); 

    $.ajax({ 
     type: "GET", 
     url: queryurl, 
     dataType: "jsonp", // return CSV FustionTable response as JSON 
     success: successFunction, 
     error: function() {alert("AJAX ERROR for " + queryurl); } 
    }); 
} 

function displayCount(d) { 
    var count = d.table.rows[0]; 
    alert(count); 
} 
</script> 
1

, 다음 각각 위도와 LNG의 최대/최소 발을 찾기 위해 융합 테이블의 SQL API를 사용

https://www.googleapis.com/fusiontables/v1/query?sql=SELECT 
MINIMUM(Lat) AS MinLat, MAXIMUM(Lat) AS MaxLat, 
MINIMUM(Long) AS MinLong, MAXIMUM(Long) AS MaxLong 
FROM <table_id> 

을 API에 대한 자세한 내용 여기를 참조하십시오 : https://developers.google.com/fusiontables/docs/v1/sql-reference. (한 가지 기억해야 할 것은이 SQL 문을 ecodeURI하는 것입니다)

이 값은 json 배열에 대한 값을 반환합니다. 그리고 내가 알고있는 것처럼이 값을 사용하여지도의 '가운데'및 '확대/축소'매개 변수를 설정하십시오.

관련 문제