我一直在尝试在谷歌地图上创建一些多边形叠加层,点击后将链接到新窗口中的另一个网页。然而,它只链接到最后生成的多边形的 URL。任何想法为什么?我想我错过了一些基本的东西,但这与我如何生成多边形然后尝试从中提取 URL 有关吗?
<script type="text/javascript">
var mapSquares = {};
mapSquares['square1'] = {
coords: [
new google.maps.LatLng(52.572177, -0.247192),
new google.maps.LatLng(52.612177, -0.247192),
new google.maps.LatLng(52.612177, -0.347192),
new google.maps.LatLng(52.572177, -0.347192)
],
url: 'http://www.google.co.uk'
};
mapSquares['square2'] = {
coords: [
new google.maps.LatLng(52.522177, -0.247192),
new google.maps.LatLng(52.572177, -0.247192),
new google.maps.LatLng(52.572177, -0.347192),
new google.maps.LatLng(52.522177, -0.347192)
],
url: 'http://www.bbc.co.uk'
}
var allMapSquares;
function initialize() {
var myLatLng = new google.maps.LatLng(52.572177, -0.247192);
var mapOptions = {
zoom: 12,
center: myLatLng,
mapTypeId: google.maps.MapTypeId.TERRAIN
};
var map = new google.maps.Map(document.getElementById("map_canvas"),mapOptions);
for (var mapSquare in mapSquares) {
var drawMapSquare = {
paths: mapSquares[mapSquare].coords,
strokeColor: "#FF0000",
strokeOpacity: 0.8,
strokeWeight: 3,
fillColor: "#FF0000",
fillOpacity: 0.35,
map: map
};
google.maps.event.addListener(drawMapSquare, 'click', function() {
window.open(mapSquares[mapSquare].url,'_blank');
});
allMapSquares = new google.maps.Polygon(drawMapSquare);
}
}
</script>
非常感谢!