Google地图标记 - 设置背景颜色 [英] Google Maps Marker — set background color

查看:212
本文介绍了Google地图标记 - 设置背景颜色的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用透明PNG作为我的标记,并且希望为透明区域填充某种颜色。我之前使用标记阴影完成了这些工作,但是这些工作不能与视觉刷新(即v3.14)一起工作。

I'm using a transparent PNG as my marker, and would like for the transparent area to be filled a certain color. I previously accomplished this using marker shadows, but those don't work with the visual refresh (i.e. v3.14).

谢谢!

推荐答案

如果这是一个选项,一个技巧可能是操纵PNG图像与PHP。以下脚本需要4个参数:图片来源,红色,绿色和蓝色的量。

A trick could be to manipulate the PNG image with PHP, if this is an option. The following script takes 4 parameters: the image source, the amount of red, green and blue.

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: p>

In javascript, call image.php with the desired parameters:

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'
});

原始图片

输出图片

这篇关于Google地图标记 - 设置背景颜色的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆