简体   繁体   English

在Google Maps API中加载具有正确呈现彩色光盘地标的KML

[英]Load a KML in Google Maps API with proper rendering of colored disc placemarks

I am using this piece of code to load a KML file in GoogleMapsAPI: 我正在使用这段代码在GoogleMapsAPI中加载KML文件:

<script>
function googleMapInitialize() {
  var myOptions = {
    center: new google.maps.LatLng(-34.397, 150.644),
    zoom: 8,
    mapTypeId: google.maps.MapTypeId.ROADMAP
  }
  var myMap = new google.maps.Map(document.getElementById("map_canvas"), myOptions);
  var ctaLayer = new google.maps.KmlLayer('http://www.freemages.fr/test/session_k.kml');
  ctaLayer.setMap(myMap);
}
</script>

While it works properly to load the points, the style I have defined is not rendered properly, as it uses a white disc in PNG format that is supposed to be re-colorized according to the color parameter, and also a resizing of the picture according to the scale parameter: 虽然它可以正常加载点,但是我定义的样式无法正确呈现,因为它使用的是PNG格式的白色光盘,该光盘应根据color参数重新着色,并根据到scale参数:

<Style id="sn_style_0">
    <IconStyle>
        <color>FF4ea24a</color>
        <scale>0.4</scale>
        <Icon>
            <href>http://www.freemages.fr/test/disc.png</href>
        </Icon>
    </IconStyle>
    <LabelStyle>
        <scale>0.5</scale>
    </LabelStyle>
</Style>
<Style id="sh_style_0">
    <IconStyle>
        <color>FF4ea24a</color>
        <scale>0.5</scale>
        <Icon>
            <href>http://www.freemages.fr/test/disc.png</href>
        </Icon>
    </IconStyle>
    <LabelStyle>
        <scale>0.5</scale>
    </LabelStyle>
</Style>
<StyleMap id="msn_style_0">
    <Pair>
        <key>normal</key>
        <styleUrl>#sn_style_0</styleUrl>
    </Pair>
    <Pair>
        <key>highlight</key>
        <styleUrl>#sh_style_0</styleUrl>
    </Pair>
</StyleMap>

Google Earth can render properly this kind of style and it works very nicely. Google Earth可以正确呈现这种样式,并且效果很好。

In my project, I want to let the user choose exactly the color he wants, so I cannot use a collection of colored discs that I would use without recoloring, which otherwise would be a simple option. 在我的项目中,我想让用户精确选择他想要的颜色,所以我不能使用没有重新着色就可以使用的彩色光盘集合,否则这将是一个简单的选择。

I also tried to use a dynamic creation of PNG transparent disc in PHP using the following code, but PHP does not manage transparency very well and it does not display properly in the file: 我还尝试使用以下代码在PHP中动态创建PNG透明光盘,但PHP不能很好地管理透明性,并且不能在文件中正确显示:

<?php
header('Content-type: image/png');

$r = $_GET["r"];
$fg = $_GET["fg"];

is_numeric($r) or $r = 16; // radius
strlen($fg)==6 or $fg = '22e822'; // fill color
$bg = 'ffffff';

function hex2rgb($im,$hex) {
    return imagecolorallocate($im,
        hexdec(substr($hex,0,2)),
        hexdec(substr($hex,2,2)),
        hexdec(substr($hex,4,2))
        );
}

$d = $r*2;
$dm = $d-4;

$im1 = imagecreatetruecolor($d,$d);
imagecolortransparent($im1, hex2rgb($im1,$bg));
imagefill($im1,0,0,hex2rgb($im1,$bg));
imagefilledellipse($im1, $r, $r, $dm, $dm, hex2rgb($im1,$fg));
imagepng($im1);
?>

Ideally if it could be possible just to create a colored disc by code in the KML file it would be the best, but I did not find any way to do so in the documentation. 理想情况下,如果仅可以通过KML文件中的代码创建彩色光盘,那将是最好的选择,但是我在文档中找不到任何方法。

Any suggestion how to workaround this issue? 任何建议如何解决此问题?

Thanks! 谢谢!

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

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