2012-04-17 18 views
1

Fusion Tablesマップの最終的なタッチで悩んでいます。クエリでSelect Allオプションを得るために、コードを変更する必要がありますか?私は、コードのこの部分を見つけ Google Fusion Tablesクエリ:すべてを選択してください。

...

https://developers.google.com/fusiontables/docs/samples/change_query

そして、私自身のコードでそれを置きます。しかし、私は間違って何をしていますか?すべてのhttp://jsfiddle.net/odi86/hqm5k/

まず:

<!DOCTYPE html> 
<html> 
    <head> 
<title>Aarbevingen 1900-2012 (+1000 dodelijke slachtoffers)</title> 
    <style> 
    #map-canvas { width:1000px; height:600px; } 
    </style> 
    <script type="text/javascript" 
    src="http://maps.google.com/maps/api/js?sensor=false"> 
    </script> 
    <script type="text/javascript"> 
    var map; 
    var layer; 
    var layerl1; 
    var layerl2; 
    var layerl3; 

    function initialize() { 
     map = new google.maps.Map(document.getElementById('map-canvas'), { 
     center: new google.maps.LatLng(0, 20), 
     zoom: 2 
     }); 
     var style = [ 
     { 
      featureType: 'all', 
      elementType: 'all', 
      stylers: [ 
      { saturation: -99 } 
      ] 
     } 
     ]; 
     var styledMapType = new google.maps.StyledMapType(style, { 
     map: map, 
     name: 'Styled Map' 
     }); 
     map.mapTypes.set('map-style', styledMapType); 
     map.setMapTypeId('map-style'); 

     layer = new google.maps.FusionTablesLayer({ 
     query: { 
      select: "'Locatie'", 
      from: 3555344 
     }, 
     map: map 
     }); 

     layer11 = new google.maps.FusionTablesLayer({ 
     query: { 
      select: "'geometry'", 
      from: 3556478 
     }, 
     clickable: false, 
     map: map 
     }); 

     layer12 = new google.maps.FusionTablesLayer({ 
     query: { 
      select: "'geometry'", 
      from: 3556541 
     }, 
     clickable: false, 
     map: map 
     }); 

     layer13 = new google.maps.FusionTablesLayer({ 
     query: { 
      select: "'geometry'", 
      from: 3556712 
     }, 
     clickable: false, 
     map: map 
     }); 

     google.maps.event.addDomListener(document.getElementById('search-string-10'), 
      'change', function() { 
       updateMap(layer); 
     }); 

var legendDiv = document.createElement('DIV'); 
    var legend = new Legend(legendDiv, map); 
    legendDiv.index = 1; 
    map.controls[google.maps.ControlPosition.RIGHT_BOTTOM].push(legendDiv);  

    } 

    function changeMap10(layer) { 
     var searchString = document.getElementById('search-string-10').value; 
     if (searchString) { 
      layer.setOptions({ 
      query: { 
       select: "'Locatie'", 
       from: 3555344, 
       where: "search-string-10 = '" + searchString + "'" 
      } 
      }); 
     } else { 
      layer.setOptions({ 
      query: { 
       select: "'Locatie'", 
       from: 3555344 
      } 
      }); 
     } 
     } 

function Legend(controlDiv, map) { 
    // Set CSS styles for the DIV containing the control 
    // Setting padding to 5 px will offset the control 
    // from the edge of the map 
    controlDiv.style.padding = '5px'; 

    // Set CSS for the control border 
    var controlUI = document.createElement('DIV'); 
    controlUI.style.backgroundColor = 'white'; 
    controlUI.style.borderStyle = 'solid'; 
    controlUI.style.borderWidth = '1px'; 
    controlUI.title = 'Legend'; 
    controlDiv.appendChild(controlUI); 

    // Set CSS for the control text 
    var controlText = document.createElement('DIV'); 
    controlText.style.fontFamily = 'Arial,sans-serif'; 
    controlText.style.fontSize = '11px'; 
    controlText.style.paddingLeft = '4px'; 
    controlText.style.paddingRight = '4px'; 

    // Add the text 
    controlText.innerHTML = '<b>Legenda</b><br />' + 
    '<div style="background-color: #ff0000; height: 10px; width: 10px; margin: 2px; float: left;"></div>> 100.000 doden<br />' + 
    '<div style="background-color: #ffff00; height: 10px; width: 10px; margin: 2px; float: left;"></div>10.000-100.000 doden<br />'+ 
    '<div style="background-color: #00ff00; height: 10px; width: 10px; margin: 2px; float: left;"></div>1.000-10.000 doden<br />'; 
    controlUI.appendChild(controlText); 
}  

    google.maps.event.addDomListener(window, 'load', initialize); 


    </script> 
    </head> 
    <body> 
    <div id="map-canvas"></div> 
    <div style="margin-top: 10px;"> 
     <label>Dodental</label> 
     <select id="search-string-10"> 
     <option value="">--Selecteer--</option> 
     <option value="1.000-10.000">1.000-10.000</option> 
     <option value="10.000-100.000">10.000-100.000</option> 
     <option value="> 100.000">> 100.000</option> 
     </select> 
    </div> 
    </body> 
</html> 

答えて

2

は、私は私のマイナーな改善と、jsFiddleにあなたのコードを入れて、あなたの選択リストから使用可能な値を返す必要がありますので、私は変更されている:

<select id="search-string-10"> 
    <option value="">All</option> 
    <option value="1000">1.000-10.000</option> 
    <option value="10000">10.000-100.000</option> 
    <option value="100000"> 100.000</option> 
</select> 

物事を明確にするために、私は "すべての"レコードのための新しいエントリーを追加しましたが、基本的には値を返さない最初のエントリーと同じです。

そして、あなたはあなたのクエリでこの値を使用することができます。

EDIT:を具体的なオプションが

function changeMap10(layer) { 
    var searchString = document.getElementById('search-string-10').value; 
    var whereCondition = ''; 
    if (searchString) { 
     whereCondition = "zoekveld = '" + searchString + "'"; 
    } 
    layer.setOptions({ 
     query: { 
      select: "'Locatie'", 
      from: 3555344, 
      where: whereCondition 
     } 
    }); 
} 

選択されていない場合、私は空の文字列にWHERE条件を設定するには、この機能を変更if/elseが必要でない場合は、同じクエリをデフォルト値で使用できます。

google.maps.event.addDomListener(document.getElementById('search-string-10'), 
    'change', function() { 
     changeMap10(layer); 
}); 
+0

スクリプトにいくつかの変更を加えなければなりませんでした。別の列の名前を 'zoekveld'で検索する必要があったからです。ここでは、1、2、3という3つのカテゴリがあります。そして、検索文字列を "zoekveld =" + searchString、に変更しました。しかし、値を空のままにすると、私はすべてのオプションを取得しません。 [http://jsfiddle.net/hqm5k/8/]のコードを確認してください。 –

+0

わかりました。上記の 'changeMap10()'関数を変更したか、ここで新しいバージョンをチェックすることができます:http://jsfiddle.net/odi86/hqm5k/10/ – Odi

0

ODIが正しい:

は最後に、私はあなたの changeMap10()機能の代わりの例から updateMap()関数を呼び出すためにイベントリスナーを変更しました。いくつかのより多くの例は、この答えであります https://stackoverflow.com/a/9401345/1211981 はまた、あなたが空の句を使用することができ、すべてのレコードを取得するには:

また
where: "" 

、数字は引用符を必要としないはずのように、おそらくあるべき場所:

where: "Dodental > " + searchString, 
関連する問題