我正在创建一个带有Fusion Layer的Google地图,因此网站的访问者可以获得有关各州技术人员的信息。以下是供参考的网站:http://horizonwebtest.zxq.net/techmap.html地图需要锁定到美国大陆,因此我已禁用默认用户界面,可拖动,双击缩放,键盘快捷键,滚轮和自动平移。问题是当信息窗口弹出时,它仍然强制地图平移。有没有人知道解决这个问题的方法?这是JavaScript:
// JavaScript Document
function initialize() {
var mapOptions = {
center: new google.maps.LatLng(38.816223025492505, -94.15954943749999),
zoom: 4,
disableDefaultUI: true,
draggable: false,
disableDoubleClickZoom: true,
keyboardShortcuts: false,
scrollwheel: false,
disableAutoPan: true,
mapTypeId: google.maps.MapTypeId.ROADMAP
};
var horizonStyles = [
{
featureType: "water",
stylers: [
{ hue: "#0077ff" },
{ saturation: 20 },
{ lightness: -50 },
]
},{
featureType: "administrative.locality",
stylers: [
{ visibility: "off" }
]
},{
featureType: "administrative.province",
elementType: "labels.text.fill",
stylers: [
{ lightness: -80 }
]
}
];
var layer = new google.maps.FusionTablesLayer({
query: {
select: 'geometry',
from: '18KqZR_1Nd39CyWN1kKt8Pufd6wlLS2oQArpCugw'
},
});
var map = new google.maps.Map(document.getElementById("map_canvas"),
mapOptions);
map.setOptions({styles: horizonStyles});
layer.setMap(map);
}
任何想法都会非常感激。
答案 0 :(得分:0)
经过大量的搜索和反复试验后,融合图层似乎不包含可编辑的元素。要编辑信息框,您需要设置suppressInfoWindows:true,然后创建信息窗口。以下是完成的参考代码:
// JavaScript Document
function initialize() {
var latlng = new google.maps.LatLng(38.816223025492505, -94.15954943749999);
var infoposition = new google.maps.LatLng(40, -81);
var infowindow = new google.maps.InfoWindow({
disableAutoPan: true,
position: infoposition,
});
var infoWindowContent = '';
var mapOptions = {
center: latlng,
zoom: 4,
disableDefaultUI: true,
draggable: false,
disableDoubleClickZoom: true,
keyboardShortcuts: false,
scrollwheel: false,
disableAutoPan: true,
mapTypeId: google.maps.MapTypeId.ROADMAP
};
var horizonStyles = [
{
featureType: "water",
stylers: [
{ hue: "#0077ff" },
{ saturation: 20 },
{ lightness: -50 },
]
},{
featureType: "administrative.locality",
stylers: [
{ visibility: "off" }
]
},{
featureType: "administrative.province",
elementType: "labels.text.fill",
stylers: [
{ lightness: -80 }
]
}
];
var layer = new google.maps.FusionTablesLayer({
query: {
select: 'geometry',
from: '18KqZR_1Nd39CyWN1kKt8Pufd6wlLS2oQArpCugw',
},
suppressInfoWindows: true,
});
var map = new google.maps.Map(document.getElementById("map_canvas"),
mapOptions);
map.setOptions({styles: horizonStyles});
layer.setMap(map);
//click listener on layer
google.maps.event.addListener(layer, 'click', function(e) {
if(infowindow) infowindow.close();
else infowindow;
//create info window layer
infoWindowContent = infowindow.setContent(
'<p class="info_window" style="font-weight: bold">' + e.row['State'].value + '</p>' +
'<p class="info_window">' + e.row['Number of Technicians'].value + ' technicians available<br>' +
'<a href="http://horizonwebtest.zxq.net/contact/">Click here to schedule a service call or installation<br>' +
'or <style="font-weight:bold">CALL 727-845-4444 NOW</style> for a live help desk<br>' +
'person to assist you over the phone or to dispatch<br>' +
'a technician to your site.</a></p>'
);
map.setCenter(latlng);
infowindow.open(map);
});
}
我希望能帮助别人......