javascript - 谷歌地图标记 — 设置背景颜色

标签 javascript css google-maps google-maps-api-3 google-maps-markers

我使用透明的 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'
});

原图:

Original image

输出图像:

Output image

关于javascript - 谷歌地图标记 — 设置背景颜色,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19296323/

相关文章:

javascript - 使用 jquery 验证插件时重置表单

javascript - 元素之间的空白,来源不明

css - 有没有办法让 CSS 属性 mask-image 响应?

java - GoogleMap Android API V2 捕获错误

Android 谷歌地图位置管理器无法在 SupportMapFragment 中工作

javascript - 这可能以 HTML 形式嵌入图像吗?

javascript - CSS渐变一种鲜明的颜色

javascript 文本字段计数器显示在加载和按键时显示

css - 有没有办法让浏览器在设备模式下减少 "width"以及 "device-width"

ios - 如何在 GMSMapView 上实现 GMSMarker 拖放?