【问题标题】:How do I apply a circular mask on a google Map, so that the window only shows the map within the circle?如何在谷歌地图上应用圆形蒙版,以便窗口仅显示圆圈内的地图?
【发布时间】:2022-01-04 01:21:54
【问题描述】:

我知道 Google Maps API 允许您在地图上覆盖一个透明的圆圈,但我希望实际的地图元素本身呈现在一个圆圈内。您推荐的最干净的方法是什么?我不认为 API 具有重塑窗口的功能。我需要通过 CSS 覆盖它吗?任何帮助将不胜感激。

【问题讨论】:

标签: javascript css google-maps google-api


【解决方案1】:

如果只是一个圆圈,只需将 iframe 放在带有overflow:hidden 的圆圈中即可。

.circle-wrapper {
  width: 70vh;
  height: 70vh;
  overflow: hidden;
  border-radius: 50%;
}
.circle-wrapper iframe {
  width: 100%;
  height: 100%;
}

这是密码笔?https://codepen.io/phucbui/pen/YzrLaJY

【讨论】:

    【解决方案2】:

    你可以使用面具:

    将您的谷歌地图 iframe 包装在标签中,并为标签添加遮罩样式。

    <div class="mask-tag"><iframe src=""></iframe></div>
    
    .mask-tag {
        /** use any image you would like */
        mask-image: url(/img/theme/shape-heart.svg);
        mask-size: contain;
        mask-repeat: no-repeat;
        mask-position: center;
        -webkit-mask-image: url(/img/theme/shape-heart.svg);
        -webkit-mask-size: contain;
        -webkit-mask-repeat: no-repeat;
        -webkit-mask-position: center;
    }
    

    【讨论】:

      猜你喜欢
      • 2018-06-24
      • 2023-04-10
      • 1970-01-01
      • 1970-01-01
      • 2011-09-28
      • 1970-01-01
      • 2015-06-10
      • 2018-09-25
      • 1970-01-01
      相关资源
      最近更新 更多