我使用透明的 PNG 作为我的标记,并希望透明区域填充某种颜色。我以前使用标记阴影完成此操作,但这些不适用于视觉刷新(即 v3.14)。
谢谢!
最佳答案
一个技巧可能是使用 PHP 操作 PNG 图像,如果这是一个选项。以下脚本有 4 个参数:图像源、红色、绿色和蓝色的数量。
image.php 脚本:
$src = $_GET['src'];
$r = $_GET['r'];
$g = $_GET['g'];
$b = $_GET['b'];
$image = @imagecreatefrompng($src);
// Create a new true color image with the same size
$w = imagesx($image);
$h = imagesy($image);
$color = imagecreatetruecolor($w, $h);
// Fill the new image with desired color
$bg = imagecolorallocate($color, $r, $g, $b);
imagefill($color, 0, 0, $bg);
// Copy original transparent image onto the new image
imagecopy($color, $image, 0, 0, 0, 0, $w, $h);
// Serve the image
header("Content-type: image/png");
imagepng($color);
imagedestroy($color);
在 javascript 中,使用所需参数调用 image.php:
var marker = new google.maps.Marker({
position: new google.maps.LatLng(0, 0),
map: map,
icon: 'path/to/image.php?src=http://maps.google.com/mapfiles/marker.png&r=100&g=125&b=255'
});
原图:
输出图像:
关于javascript - 谷歌地图标记 — 设置背景颜色,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19296323/