3

我需要帮助更改每个 KML 图层的颜色和/或脚本在下面的 Google Maps Api 随机颜色。我在下面附上了整个脚本。我想知道如何更改每个多边形的填充和边框并生成随机颜色。这是一个动态 SQL 脚本。任何帮助将不胜感激。谢谢。

enter code here
<!DOCTYPE html>
<html>
<head>
<meta name="viewport" content="initial-scale=1.0, user-scalable=no" />
<meta http-equiv="content-type" content="text/html; charset=UTF-8"/>
<link href="http://code.google.com/apis/maps/documentation/javascript/examples/default.css"   rel="stylesheet" type="text/css" />
<script type="text/javascript" src="http://maps.googleapis.com/maps/api/js?sensor=false"></script>
<script type="text/javascript">
function createCookie(name,value,days) {
if (days) {
var date = new Date();
date.setTime(date.getTime()+(days*24*60*60*1000));
var expires = "; expires="+date.toGMTString();
}
else var expires = "";
document.cookie = name+"="+value+expires+"; path=/";
}
function readCookie(name) {
var nameEQ = name + "=";
var ca = document.cookie.split(';');
for(var i=0;i < ca.length;i++) {
var c = ca[i];
while (c.charAt(0)==' ') c = c.substring(1,c.length);
if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
}
return null;
}
function eraseCookie(name) {
createCookie(name,"",-1);
}
function initialize() {
var soil = new google.maps.LatLng(41.875696,-87.624207);
var myOptions = {
zoom: 7,
center: new google.maps.LatLng(36.4098320, -85.2748718),
mapTypeId: google.maps.MapTypeId.TERRAIN
}
var map = new google.maps.Map(document.getElementById("map_canvas"), myOptions);
layerl0 = new google.maps.FusionTablesLayer({
query: {
select: "'col2'",
from: '1-nKJJErStEiMLY52mxzBxhjizorvs5ZXDJXu_IA'
},
map: map,
styleId: 1,
templateId: 1
});
var
ctaLayer = new        google.maps.KmlLayer('http://casoilresource.lawr.ucdavis.edu/soil_web/export.php?  format=kmz&srid=4326&mukey_query=527031&BBOX=1,1,1,1',    {preserveViewport:false});ctaLayer.setMap(map);
ctaLayer = new    google.maps.KmlLayer('http://casoilresource.lawr.ucdavis.edu/soil_web/export.php?   format=kmz&srid=4326&mukey_query=527128&BBOX=1,1,1,1',    {preserveViewport:false});ctaLayer.setMap(map);
ctaLayer = new   google.maps.KmlLayer('http://casoilresource.lawr.ucdavis.edu/soil_web/export.php?  format=kmz&srid=4326&mukey_query=527489&BBOX=1,1,1,1',   {preserveViewport:false});ctaLayer.setMap(map);
ctaLayer = new  google.maps.KmlLayer('http://casoilresource.lawr.ucdavis.edu/soil_web/export.php? format=kmz&srid=4326&mukey_query=527504&BBOX=1,1,1,1',  {preserveViewport:false});ctaLayer.setMap(map);
ctaLayer = new  google.maps.KmlLayer('http://casoilresource.lawr.ucdavis.edu/soil_web/export.php? format=kmz&srid=4326&mukey_query=527505&BBOX=1,1,1,1',  {preserveViewport:false});ctaLayer.setMap(map);
ctaLayer = new  google.maps.KmlLayer('http://casoilresource.lawr.ucdavis.edu/soil_web/export.php? format=kmz&srid=4326&mukey_query=527560&BBOX=1,1,1,1',  {preserveViewport:false});ctaLayer.setMap(map);
ctaLayer = new    google.maps.KmlLayer('http://casoilresource.lawr.ucdavis.edu/soil_web/export.php?   format=kmz&srid=4326&mukey_query=528148&BBOX=1,1,1,1',    {preserveViewport:false});ctaLayer.setMap(map);
ctaLayer = new    google.maps.KmlLayer('http://casoilresource.lawr.ucdavis.edu/soil_web/export.php?   format=kmz&srid=4326&mukey_query=529859&BBOX=1,1,1,1',   {preserveViewport:false});ctaLayer.setMap(map);
ctaLayer = new   google.maps.KmlLayer('http://casoilresource.lawr.ucdavis.edu/soil_web/export.php?  format=kmz&srid=4326&mukey_query=2396878&BBOX=1,1,1,1',   {preserveViewport:false});ctaLayer.setMap(map);
}
</script>
</head>
<body onload="initialize()">
<div id="map_canvas" style="width: 600px; height: 450px;"></div>
</body>
</html>
4

2 回答 2

4

您无法使用 Google Maps API v3 更改 KmlLayer 中多边形的颜色。您可以更改生成的 KML 以设置颜色。

请参阅KML 参考

使用 geoxml3 的多个 KML 文件的示例

使用 geoxml3 更改颜色(突出显示)的示例

于 2013-05-04T00:05:07.580 回答
1

您可以使用 geoxml3 更改 kml 颜色。这是一个链接..看这个例子

于 2013-05-04T09:28:08.883 回答