【发布时间】:2018-10-23 17:26:24
【问题描述】:
我正在用多边形创建地图,以显示城市的不同区域。每个多边形(区域)都应该可以点击到另一个网站(包含该区域信息的子页面)。我已经添加了一个 add.listener ,当我将鼠标悬停在多边形上时,我可以看到多边形后面有一个链接,但它不可点击。
这是迄今为止我对一个多边形的了解:
<body>
<h1>Headline</h1>
<div id="map"></div>
<script>
function initMap() {
var map = new google.maps.Map(document.getElementById('map'), {
zoom: 12,
center:{lat:52.516754,lng:13.415202},
mapTypeId: 'terrain'
});
//Define the LatLng coordinates for the polygon's path DistrictOne
var DistrictOneCoords = [
{lat:52.528198300, lng:13.424935300},
{lat:52.527989500, lng:13.423905300},
{lat:52.525065200, lng:13.420386300},
{lat:52.522819700, lng:13.426480300},
{lat:52.521148500, lng:13.429141000},
{lat:52.519111700, lng:13.427596100},
{lat:52.528198300, lng:13.424935300}
];
// Construct the polygon.
var DistrictOne = new google.maps.Polygon({
paths: DistrictOneCoords,
strokeColor: '#FF0000',
strokeOpacity: 0.8,
strokeWeight: 2,
fillColor: '#FF0000',
fillOpacity: 0.35
});
DistrictOne.setMap(map);
}
// link
google.maps.event.addListener(DistrictOne, "click", function(event) { window.location.href = "https://www.berlin.de" });
</script>
正如我已经提到的,我无法点击该链接。
【问题讨论】:
标签: javascript google-maps-api-3 dom-events polygon