简体   繁体   English

为 Google 标记添加透明度

[英]Add transparency to a Google Marker

I have a marker that looks like the on in this tutorial: http://www.powerhut.co.uk/googlemaps/custom_markers.php我有一个看起来像本教程中的标记: http://www.powerhut.co.uk/googlemaps/custom_markers.php

Can I add transparency to this marker?我可以为这个标记添加透明度吗?

I've looked over the net and failed to find something that would help me in this issue.我查看了网络并没有找到可以帮助我解决这个问题的东西。 In Bing Maps I can do something like this:在 Bing 地图中,我可以执行以下操作:

var veCustomIco = new VECustomIconSpecification();
veCustomIco.CustomHTML= "<img src='" + url + "' style='filter: Alpha(opacity=10);-moz-opacity: 0.1;opacity: 0.10;'/>";
pin.SetCustomIcon(veCustomIco);

Thank you.谢谢你。

It looks like this is possible in version 3.21 of the Google Maps API:在 Google Maps API 的 3.21 版中,这似乎是可能的:

https://developers.google.com/maps/documentation/javascript/reference?csw=1#MarkerOptions https://developers.google.com/maps/documentation/javascript/reference?csw=1#MarkerOptions

You can either use the setOpacity() opacity method or pass in the opacity as an option when creating the marker.您可以使用setOpacity() opacity 方法,也可以在创建标记时将 opacity 作为选项传入。

You can add transparency as you wish as this is a PNG file.您可以根据需要添加透明度,因为这是一个 PNG 文件。 PNG files can have transparency. PNG 文件可以具有透明度。 Just edit the image file with photoshop or the like.只需使用 Photoshop 等编辑图像文件。

Sounds like it's a common PNG with an alpha channel.听起来这是一个带有 alpha 通道的常见 PNG。 No fancy software work, just plain gfx editing.没有花哨的软件工作,只是简单的 gfx 编辑。 GIMP can do this. GIMP 可以做到这一点。 "Layer"->"Transparency"->"Add alpha channel", then use "eraser" tool to remove whatever you want, or layer opacity to make layer partially transparent, or adjust Alpha channel in curves... anyway, "checkerboard" background means transparency. “图层”->“透明度”->“添加Alpha通道”,然后使用“橡皮擦”工具删除您想要的任何内容,或使用图层不透明度使图层部分透明,或调整曲线中的Alpha通道......无论如何,“棋盘格" 背景意味着透明度。 Save as PNG and you're done.保存为PNG,你就完成了。

I ran into the similar problem and solved it loading transparent png's trough a php request and pass a 'transparency' variable trough get.我遇到了类似的问题,并通过 php 请求解决了它加载透明 png 的问题,并通过获取传递了“透明度”变量。

like: pathtoyourphpfile/index.php?input=darkcyan_0c.png&transparency=40 where 'input' is the original image and 'transparency' is the amount % of transparency you want.比如:pathtoyourphpfile/index.php?input=darkcyan_0c.png&transparency=40 其中'input'是原始图像,'transparency'是你想要的透明度百分比。 In this case it outputs 'output-40.png'在这种情况下,它输出“output-40.png”

I used imagick to process the png.我使用imagick来处理png。 A very simple example without image paths:一个没有图像路径的非常简单的例子:

$percent   = $_GET[transparency];
$transparency   = 100 / $percent;
$command = "/usr/bin/convert ".$_GET[input]." -channel Alpha -evaluate Divide {$transparency} output-{$transparency}.png";
$output         = shell_exec($commando1); 

but you could also use php's GD library to adjust png's transparency但你也可以使用 php 的 GD 库来调整 png 的透明度

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

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