gpt4 book ai didi

google-maps-api-3 - 谷歌地图和透明点击标记

转载 作者:行者123 更新时间:2023-12-04 14:40:53 24 4
gpt4 key购买 nike

我正在使用 Google map API v3。在 map 中间有一个(自定义)旗帜标记,旗身周围有大片透明区域。在旗帜图标下还有另一个标记,由于透明区域无效而无法访问。有什么方法可以将标记标记设置为点击?我找不到解决方案。

最佳答案

是的,Marker 类可能有一个采用 MarkerShape object 的形状属性.这描述了 Marker 的可点击区域。

这里是 Google's Example .他们有一个自定义的旗帜图像并调整了形状,以便只有矩形旗帜部分是可点击的。使用 MarkerShape 对象,您可以绘制圆形、矩形或多边形形状区域。

Google 示例代码段:

function setMarkers(map, locations) {
// Add markers to the map

// Marker sizes are expressed as a Size of X,Y
// where the origin of the image (0,0) is located
// in the top left of the image.

// Origins, anchor positions and coordinates of the marker
// increase in the X direction to the right and in
// the Y direction down.
var image = new google.maps.MarkerImage('images/beachflag.png',
// This marker is 20 pixels wide by 32 pixels tall.
new google.maps.Size(20, 32),
// The origin for this image is 0,0.
new google.maps.Point(0,0),
// The anchor for this image is the base of the flagpole at 0,32.
new google.maps.Point(0, 32));
var shadow = new google.maps.MarkerImage('images/beachflag_shadow.png',
// The shadow image is larger in the horizontal dimension
// while the position and offset are the same as for the main image.
new google.maps.Size(37, 32),
new google.maps.Point(0,0),
new google.maps.Point(0, 32));
// Shapes define the clickable region of the icon.
// The type defines an HTML <area> element 'poly' which
// traces out a polygon as a series of X,Y points. The final
// coordinate closes the poly by connecting to the first
// coordinate.
var shape = {
coord: [1, 1, 1, 20, 18, 20, 18 , 1],
type: 'poly'
};
for (var i = 0; i < locations.length; i++) {
var beach = locations[i];
var myLatLng = new google.maps.LatLng(beach[1], beach[2]);
var marker = new google.maps.Marker({
position: myLatLng,
map: map,
shadow: shadow,
icon: image,
shape: shape,
title: beach[0],
zIndex: beach[3]
});
}
}

关于google-maps-api-3 - 谷歌地图和透明点击标记,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8700793/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com