简体   繁体   English

Google将标记映射为SVG(内部带有png标签)

[英]Google maps marker as SVG (with image png tag inside)

Is it possible to use .png image inside SVG block as google maps marker? 是否可以在SVG块中使用.png图像作为Google地图标记? I want to have one picture and draw it in different colors with SVG filter so then use as google markers. 我想拥有一张图片,并使用SVG滤镜以不同的颜色绘制它,然后用作Google标记。

I am trying to use picture without filter at least for now: 我正在尝试至少现在不使用过滤器的图片:

var svg = '<?xml version="1.0"?>' +
          '<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" height="200px" width="200px" viewBox="0 0 200 200">' +
          '<image width="200" height="200" preserveAspectRatio="xMinYMin slice" xlink:href="{link.to.png.image}"/>' +
          '</svg>';

var icon = {
  url: 'data:image/svg+xml;charset=UTF-8,' + svg,
  scaledSize: iconSize // scaled size
};

And if I will take svg code and try to use it just via browser it renders ok 如果我将使用svg代码并尝试仅通过浏览器使用它,它将呈现确定

<?xml version="1.0"?>
<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" height="200px" width="200px" viewBox="0 0 200 200">
<image width="200" height="200" preserveAspectRatio="xMinYMin slice" xlink:href="{link.to.png.image}"/>
</svg>

But it shows nothing while trying to use with google maps 但是在尝试与Google Maps结合使用时什么也没显示

I had no success with embeding a PNG directly using it's URL, in a SVG marker for google maps. 我无法直接使用其网址将PNG嵌入到Google地图的SVG标记中。 I tryied both http and https. 我尝试了http和https。

But, it works if you encode the binary file as data-uri : 但是,如果将二进制文件编码为data-uri,则可以使用:

var svg = '<?xml version="1.0"?>' +
          '<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" height="200px" width="200px" viewBox="0 0 200 200">' +
          '<image width="200" height="200" preserveAspectRatio="xMinYMin slice" xlink:href="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAUAAAAFCAYAAACNbyblAAAAHElEQVQI12P4//8/w38GIAXDIBKE0DHxgljNBAAO9TXL0Y4OHwAAAABJRU5ErkJggg=="/>' +
          '</svg>';

I found a older Question that might help you. 我发现了一个较旧的问题可能会对您有所帮助。

Here 这里

var markercolor = "#fff";
var icon = {
   path: "M-20,0a20,20 0 1,0 40,0a20,20 0 1,0 -40,0",
   fillColor: markercolor,
   fillOpacity: .6,
   anchor: new google.maps.Point(0,0),
   strokeWeight: 0,
   scale: 1
}

var marker = new google.maps.Marker({
    position: event.latLng,
    map: map,
    draggable: false,
    icon: icon
});

I think the best way is to convert your .png in a .svg with a online converter or something similar. 我认为最好的方法是使用在线转换器或类似工具将.png转换为.svg。 Is there any reason why you need a .png? 有什么理由为什么需要.png?

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM