【问题标题】:Embedded google maps iframe in SVG element在 SVG 元素中嵌入谷歌地图 iframe
【发布时间】:2017-02-06 18:07:23
【问题描述】:

如何将我的谷歌地图添加到 svg 元素中? 我想用地图填充 svg。

地图出现,但被拉伸并超出 svg 形状

要测试代码,您必须在 iframe 中插入 src 链接。

我的代码:

svg
{
  stroke: red;
}
<svg viewBox="0 0 100 100" preserveAspectRatio="none">
  <foreignObject id="map" width="560" height="349">
    <iframe width="560" height="349" frameborder="0" style="border:0" src="LINK + API_KEY" allowfullscreen></iframe>
  </foreignObject>
  <path fill="url(#map)" d="M 50 15, 100 25, 100 100, 50 100, 0 100, 0 25Z" />
</svg>

谢谢

【问题讨论】:

  • 欢迎来到 SO!提供示例代码时,请将其设为minimal, complete, verifiable example(因此,请给我们一个有效的 iframe 示例)。我正确理解您的最小问题是可以使用 svg 来掩盖 iframe,对吗?
  • 是的,就是这个!我没有显示有效的 iframe,因为谷歌地图的 api 键。
  • 酷。如果这是问题所在,那么谷歌地图并不重要,任何工作的 iframe 都可以

标签: css iframe svg google-maps-api-3


【解决方案1】:

这是基于 Yoksel 的"Masking video with SVG Clippath" 的解决方案。占位符视频只是为了提供一个有效的公共 iframe。要使用此解决方案,您必须重新定义 &lt;path&gt; 以具有正确的大小(如果幸运的话,您将能够像 Yoksel 那样使用百分比)。

(@yoksel 你是同一个 Yoksel 吗?)

.svg {
  width: 560px;
  height: 349px;
}
<svg class="svg">
  <clippath id="my-clippath">
    <path d="M 50 15, 100 25, 100 100, 50 100, 0 100, 0 25Z"></path>
  </clippath>

  <g clip-path="url(#my-clippath)">
    <foreignObject width="560" x="0" y="0" height="349">
        <iframe width="560" height="349" src="https://www.youtube.com/embed/NpEaa2P7qZI" frameborder="0" allowfullscreen></iframe>
    </foreignObject>
  </g>
</svg>

【讨论】:

猜你喜欢
  • 2012-10-31
  • 2011-09-26
  • 1970-01-01
  • 1970-01-01
  • 2012-07-13
  • 1970-01-01
  • 1970-01-01
  • 2013-07-30
  • 1970-01-01
相关资源
最近更新 更多