0
我今天創建了一個使用Fusion Tables的地圖,我約需要的90%,但我完全停留在啓用地圖上的mouseover事件。基本上我想讓縣名在地圖上懸停。我從這裏拿到了示例代碼: http://gmaps-utility-gis.googlecode.com/svn/trunk/fusiontips/docs/examples.htmlFusion Tables fusiontips mouseover event not working
我想我已經正確填寫了所需的信息。我從Fusion Tables自動生成HTML/JS地圖。這裏是我的實時地圖:http://www.casalett.net/map/map.html
任何和所有幫助,將不勝感激!
下面的代碼:
<script type="text/javascript" src="https://maps.google.com/maps/api/js?sensor=false&v=3"></script>
<script src="js/fusiontipsV1.js" type="text/javascript"></script>
<script type="text/javascript">
function initialize() {
google.maps.visualRefresh = true;
var isMobile = (navigator.userAgent.toLowerCase().indexOf('android') > -1) ||
(navigator.userAgent.match(/(iPod|iPhone|iPad|BlackBerry|Windows Phone|iemobile)/));
if (isMobile) {
var viewport = document.querySelector("meta[name=viewport]");
viewport.setAttribute('content', 'initial-scale=1.0, user-scalable=no');
}
var mapDiv = document.getElementById('googft-mapCanvas');
//mapDiv.style.width = isMobile ? '100%' : '1000px';
//mapDiv.style.height = isMobile ? '100%' : '400px';
var map = new google.maps.Map(mapDiv, {
center: new google.maps.LatLng(35.196111, -79.464167),
zoom: 8,
mapTypeId: google.maps.MapTypeId.ROADMAP
});
map.controls[google.maps.ControlPosition.RIGHT_BOTTOM].push(document.getElementById('googft-legend-open'));
map.controls[google.maps.ControlPosition.RIGHT_BOTTOM].push(document.getElementById('googft-legend'));
layer = new google.maps.FusionTablesLayer({
map: map,
heatmap: { enabled: false },
query: {
select: "col4\x3e\x3e0",
from: "1ohK_Kmh7JbNZH1nC7NM-1MjhVf8OBzCJrxmbC0tq",
where: ""
},
options: {
styleId: 2,
templateId: 2
}
});
// This is the only section I added myself from the example page
layer.enableMapTips({
select: "'County Name'", // list of columns to query, typially need only one column.
from: "1ohK_Kmh7JbNZH1nC7NM-1MjhVf8OBzCJrxmbC0tq", // fusion table name
geometryColumn: 'gemoetry', // geometry column name
suppressMapTips: false, // optional, whether to show map tips. default false
delay: 200, // milliseconds mouse pause before send a server query. default 300.
tolerance: 8 // tolerance in pixel around mouse. default is 6.
});
//listen to events if desired.
google.maps.event.addListener(layer, 'mouseover', function(fEvent) {
var row = fEvent.row;
myHtml = 'mouseover:<br/>';
for (var x in row) {
if (row.hasOwnProperty(x)) {
myHtml += '<b>' + x + "</b>:" + row[x].value + "<br/>";
}
}
document.getElementById('info').innerHTML = myHtml;
});
google.maps.event.addListener(layer, 'mouseout', function(fevt) {
document.getElementById('info').innerHTML = '';
});
// Section I added myself ends here
if (isMobile) {
var legend = document.getElementById('googft-legend');
var legendOpenButton = document.getElementById('googft-legend-open');
var legendCloseButton = document.getElementById('googft-legend-close');
legend.style.display = 'none';
legendOpenButton.style.display = 'block';
legendCloseButton.style.display = 'block';
legendOpenButton.onclick = function() {
legend.style.display = 'block';
legendOpenButton.style.display = 'none';
}
legendCloseButton.onclick = function() {
legend.style.display = 'none';
legendOpenButton.style.display = 'block';
}
}
}
google.maps.event.addDomListener(window, 'load', initialize);
</script>
感謝您的答覆和澄清API密鑰的需要。我繼續創建一個公共API密鑰,並在代碼片段中將其交換出來,但仍然無法使mouseover函數正常工作。它實際上並沒有在你的代碼片段上面工作。我還錯過了什麼嗎?乾杯! – user3684918 2015-02-06 14:01:31
我確實有它的工作,但現在我看到代碼片段中的這個JavaScript錯誤:'錯誤,代碼= 403消息=有一個per-IP或per-Referer限制在您的API密鑰上配置,並且請求不符合這些限制。如果允許來自此IP或引薦者的請求,請使用Google Developers Console更新您的API密鑰配置。原因= ipRefererBlocked'。不知道爲什麼會發生,不能在我預期的領域。 – geocodezip 2015-02-06 14:05:04
啊!我也有工作,然後停下來。混亂。我想我會繼續挖掘... – user3684918 2015-02-06 17:19:27