【问题标题】:Google maps and Transparent click-through marker谷歌地图和透明点击标记
【发布时间】:2012-01-31 19:34:12
【问题描述】:

我正在使用 Google 地图 api v3。在地图的中间有一个(自定义)标志标记,标志主体周围有大的透明区域。在标志图标下还有另一个标记,由于死透明区域而无法访问。有没有办法将标志标记设置为点击?我找不到解决办法。

【问题讨论】:

    标签: google-maps-api-3 google-maps-markers


    【解决方案1】:

    是的,将clickable 属性设置为false。例如:

    const newMarker = new google.maps.Marker(
              position: {
                lat: 10,
                lng: -66
              },
              clickable: false // <------
    )
    

    【讨论】:

      【解决方案2】:

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

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

      谷歌示例代码段:

      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 &lt;area&gt; 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]
          });
        }
      }
      

      【讨论】:

        猜你喜欢
        • 2012-09-27
        • 1970-01-01
        • 2017-10-20
        • 2011-10-11
        • 1970-01-01
        • 1970-01-01
        • 2016-02-10
        • 2012-12-04
        • 1970-01-01
        相关资源
        最近更新 更多