我有一张地图,其中有多个圆圈相互交叉(下面是一个只有两个圆圈的例子,但它至少有100个圆圈)。当它们交叉时,不透明度加倍,所以当我有一个5或6个圆圈之间的交叉时,它变得大约100%不透明度。
有没有办法让第二个圆圈不显示" over"第一个 ?实际上并不是这么认为的,但也许有人已经预料到了这样的事情......
左:我有什么------------------------------------------ ----对:我想要的
以防万一你想玩: http://jsfiddle.net/ZWt6w/
var populationOptions = {
strokeWeight: 0,
fillColor: '#FF0000',
fillOpacity: 0.5,
map: map,
center: citymap[city].center,
radius: citymap[city].population
};
// Add the circle for this city to the map.
cityCircle = new google.maps.Circle(populationOptions);
感谢您的帮助;)
答案 0 :(得分:8)
使用Polygon class,您可以将重叠不透明度设为单个。
var peanut = new google.maps.Polygon({
paths: [drawCircle(citymap['chicago'].center, citymap['chicago'].population/3000, 1),//division by 3000 to suit
drawCircle(citymap['losangeles'].center,citymap['losangeles'].population/3000, 1)],
strokeColor: "#ff0000",
strokeOpacity: 0.35,
strokeWeight: 0,
fillColor: "#FF0000",
fillOpacity: 0.35
});
peanut.setMap(map);
答案 1 :(得分:7)
使用多个路径绘制一个多边形----------绘制多个圆圈
@david strachan的答案解决了我的大部分问题。 以下是此解决方案的一部分:首先,您必须使用此" drawCircle"功能而不是Google Maps API V3的Circle对象:
function drawCircle(point, radius, dir)
{
var d2r = Math.PI / 180; // degrees to radians
var r2d = 180 / Math.PI; // radians to degrees
var earthsradius = 3963; // 3963 is the radius of the earth in miles
var points = 32;
// find the raidus in lat/lon
var rlat = (radius / earthsradius) * r2d;
var rlng = rlat / Math.cos(point.lat() * d2r);
var extp = new Array();
if (dir==1) {var start=0;var end=points+1} // one extra here makes sure we connect the
else{var start=points+1;var end=0}
for (var i=start; (dir==1 ? i < end : i > end); i=i+dir)
{
var theta = Math.PI * (i / (points/2));
ey = point.lng() + (rlng * Math.cos(theta)); // center a + radius x * cos(theta)
ex = point.lat() + (rlat * Math.sin(theta)); // center b + radius y * sin(theta)
extp.push(new google.maps.LatLng(ex, ey));
}
return extp;
}
此函数返回路径,因此您可以使用它来建立一个路径数组,以便在构建单个Polygon对象后使用它:
var polys = [] ;
$(xml).find("trkpt").each(function() { // Parsing every points of my track
var p = new google.maps.LatLng($(this).attr("lat"), $(this).attr("lon"));
points.push(p);
if ( ( i++ % 10 ) == 0 ) // Only display a circle every 10 points
{
polys.push(drawCircle(p,radius/1609.344,1)) ; // Radius value is in meters for me, so i divide to make it in miles
}
});
peanutcircle = new google.maps.Polygon({
paths: polys,
strokeOpacity: 0,
strokeWeight: 0,
fillColor: color,
fillOpacity: 0.35,
});
peanutcircle.setMap(map);
就是这样,你已经绘制了一个复杂但单一的多边形,可能更容易使用。
对我来说唯一的问题是检查这个单一多边形中包含的标记(使用google function containsLocation和github.com/tparkin/Google-Maps-Point-in-Polygon)效果不佳,所以我不得不继续使用我的将圆圈倍增以检查标记是否在我的区域中。
感谢@david strachan的回答。
答案 2 :(得分:0)
我有类似的问题,但我的覆盖层是冲洗形状的rusters。以下示例中的椭圆仅用于演示问题,但实际栅格是任何形式的形状,但具有相同的颜色:
<!DOCTYPE html><html><head>
<title>Multi-Raster</title>
<style type="text/css">html { height: 100% }body { height: 100%}</style>
<script language="javascript" type="text/javascript" src="http://maps.googleapis.com/maps/api/js?sensor=false"></script><script type="text/javascript">
var map;
function initialize() {
var coord = new google.maps.LatLng( 45.4931831359863,-73.6133499145508);
var myOptions = {zoom: 10,center: coord, mapTypeId: google.maps.MapTypeId.ROADMAP};
map = new google.maps.Map(document.getElementById("map_canvas"),myOptions );
var boundaries1 = new google.maps.LatLngBounds(new google.maps.LatLng( 44.59386,-74.89627), new google.maps.LatLng( 46.39251,-72.33043));
rmap1 =new google.maps.GroundOverlay("scrap.png", boundaries1);
rmap1.setMap(map);
rmap2 =new google.maps.GroundOverlay("scrap2.png", boundaries1);
rmap2.setMap(map);
}
function showcov(m,v){if(v.checked) {m.setOpacity(0);m.setMap(map); }else {m.setMap(null);m.setOpacity(100);}}
</script></head>
<body onload="initialize()">
<div id="map_canvas" style="width:100%;height:100%"></div>
</form></td></tr></table></div></body></html>