我计划显示一个带有下拉列表的空白地图,这将允许用户选择希望显示的图层(来自 Fusion Tables)。在网上我没有找到示例代码。我当前的代码如下。
<html>
<head>
<script type="text/javascript" src="http://maps.google.com/maps/api/js?sensor=false"></script>
<script type="text/javascript">
var center = new google.maps.LatLng(-40.979898,173.305662);
var infowindow = new google.maps.InfoWindow();
function init() {
map = new google.maps.Map(document.getElementById('map_canvas'), {
center: center,
zoom: 6,
mapTypeId: google.maps.MapTypeId.ROADMAP
});
var street_address1 = new google.maps.FusionTablesLayer({
query: {
select: 'street_address_Auckland_000001_080000',
from: '1WoKvD3GvX8Rif7TFmHGEvvbtpbYWFs-K-DeF7WU'
},
suppressInfoWindows: true
});
google.maps.event.addListener(street_address1, 'click', function(e) {
if(infowindow) infowindow.close();
else infowindow = new google.maps.InfoWindow();
infoWindowContent = infowindow.setContent(
'<h3 style="font-family: Arial; font-size: 13px; color: #FFFFFF; background-color: #0099FF; text-align: center; font-style: italic">' + 'Street Address'
+ '<h1 style="font-family: Arial; font-size: 12px; color: #333333; background-color: #E2E2E2; text-align: left "> ID: ' + e.row['id'].value
+ '</a>') ;
infowindow.setPosition(e.latLng);
map.setCenter(e.latLng);
infowindow.open(map);
});
var street_address2 = new google.maps.FusionTablesLayer({
query: {
select: 'street_address_Auckland_080000_160000',
from: '1dlsTxt8kyA92pq3jwODwQtaEcWxn8dax0slrULM'
},
suppressInfoWindows: true
});
google.maps.event.addListener(street_address2, 'click', function(e) {
if(infowindow) infowindow.close();
else infowindow = new google.maps.InfoWindow();
infoWindowContent = infowindow.setContent(
'<h3 style="font-family: Arial; font-size: 13px; color: #FFFFFF; background-color: #0099FF; text-align: center; font-style: italic">' + 'Street Address'
+ '<h1 style="font-family: Arial; font-size: 12px; color: #333333; background-color: #E2E2E2; text-align: left "> ID: ' + e.row['id'].value
+ '</a>') ;
infowindow.setPosition(e.latLng);
map.setCenter(e.latLng);
infowindow.open(map);
});
var street_address3 = new google.maps.FusionTablesLayer({
query: {
select: 'street_address_Auckland_160000_240000',
from: '1bb-M9LcG_dFS3ejYzT3hnpOQUzMMBT2GR8VH5hY'
},
suppressInfoWindows: true
});
google.maps.event.addListener(street_address3, 'click', function(e) {
if(infowindow) infowindow.close();
else infowindow = new google.maps.InfoWindow();
infoWindowContent = infowindow.setContent(
'<h3 style="font-family: Arial; font-size: 13px; color: #FFFFFF; background-color: #0099FF; text-align: center; font-style: italic">' + 'Street Address'
+ '<h1 style="font-family: Arial; font-size: 12px; color: #333333; background-color: #E2E2E2; text-align: left "> ID: ' + e.row['id'].value
+ '</a>') ;
infowindow.setPosition(e.latLng);
map.setCenter(e.latLng);
infowindow.open(map);
});
$('#street_address').select(function(){
if ($(this).is('1'))
street_address1.setMap(map);
else
street_address1.setMap(null);
});
$('#street_address').removeAttr('disabled');
$('#street_address').select(function(){
if ($(this).is('2'))
street_address2.setMap(map);
else
street_address2.setMap(null);
});
$('#street_address').removeAttr('disabled');
$('#street_address').select(function(){
if ($(this).is('3'))
street_address3.setMap(map);
else
street_address3.setMap(null);
});
$('#street_address').removeAttr('disabled');
}
</script>
</head>
<body id="body" onload="init();">
<div id="list" style="position:absolute; left:25; top:5px; width:100px; height:25px;">
<select name="street_address" id="street_address">
<option value="1">Layer 1</option>
<option value="2">Layer 2</option>
<option value="3">Layer 3</option>
</select>
</div>
<div id="map_canvas" style="position:absolute; left:25; top:35px; width:1000px; height:760px"></div>
</body>
</html>
有没有人有这个功能的示例代码?
最好的,达科