0

我正在尝试在 Fusion Tables Map 中创建一个重置按钮,一旦单击它就会显示所有标记。但是有些东西不起作用。请看一下:

这是整个代码:

实际上,我试图从函数 clearBox() 的 layer10 部分“模仿”函数 initialize()。我也尝试使用reset()方法,但也没有用。

<!DOCTYPE html>
<html>
<head>
<style>
#map-canvas { width:500px; 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 layerl0;
function initialize() {
  map = new google.maps.Map(document.getElementById('map-canvas'), {
    center: new google.maps.LatLng(-30.070876662388095, -51.1907958984375),
    zoom: 12,
    mapTypeId: google.maps.MapTypeId.ROADMAP
  });
  layerl0 = new google.maps.FusionTablesLayer({
    query: {
      select: "'ENDERECO'",
      from: '3385625'
    },
    map: map
  });
}
function changeMapl0() {
  var searchString = document.getElementById('search-string-l0').value.replace(/'/g, "\\'");
  layerl0.setOptions({
    query: {
      select: "'ENDERECO'",
      from: 3385625,
      where: "'TIPO' = '" + searchString + "'"
    }
  });
}
google.maps.event.addDomListener(window, 'load', initialize);

//Function to be activated by the reset button
function clearBox() {
document.getElementById('search-string-l0').value = "";
  layerl0 = google.maps.FusionTablesLayer({
    query: {
      select: "'ENDERECO'",
      from: '3385625'
    },
  });
}

 </script>
 </head>
 <body>
<div id="map-canvas"></div>
<div style="margin-top: 10px;">
  <label>Tipo</label>
  <select id="search-string-l0" onchange="changeMapl0 (this.value);">
    <option value="">--Select--</option>
    <option value="Comidas variadas">Comidas variadas</option>
    <option value="Restaurante">Restaurante</option>
    <option value="Bar">Bar</option>
    <option value="Hotel">Hotel</option>
    <option value="Shopping Center">Shopping Center</option>
    <option value="Teatro">Teatro</option>
    <option value="Igreja">Igreja</option>
    <option value="Museu">Museu</option>
    <option value="Espaço de Cultura">Espaço de Cultura</option>
  </select><br/>
<input type="button" onclick="clearBox()" value="Reset Map" />
</div>
</body>
</html>
4

1 回答 1

1

听起来你需要从最近的这篇关于 SO 的帖子中重置你的查询,比如这张地图

查看您的完整代码,使其工作的最简单方法是更改​​您的重置功能以仅更改查询,而不是重新创建 FusionTablesLayer:

改变:

function clearBox() {
document.getElementById('search-string-l0').value = "";
  layerl0 = google.maps.FusionTablesLayer({
    query: {
      select: "'ENDERECO'",
      from: '3385625'
    },
  });
}

至:

function clearBox() {
document.getElementById('search-string-l0').value = "";
  layerl0.setOptions({
    query: {
      select: "'ENDERECO'",
      from: '3385625'
    }
  });
}

注意:我还删除了一个可能会导致 IE 出现问题的多余逗号。

工作示例

于 2012-07-27T03:22:02.980 回答