Google マップ上にポリゴン オーバーレイを作成しようとしましたが、クリックすると新しいウィンドウで別の Web ページにリンクされます。ただし、最後に生成されたポリゴンの 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>
どうもありがとう!