Pie*_*ger 8 javascript google-maps google-maps-api-3
我有一张地图上有多个圆圈相互交叉(下面是一个只有两个圆圈的例子,但至少有100个圆圈).当它们交叉时,不透明度加倍,所以当我有一个5或6个圆圈之间的交叉时,它只会变成大约100%的不透明度.
有没有办法让第二个圆圈不显示"第一个圆圈"?实际上一个人不这么认为,但也许有人已经预料到这样的事......
左:我有什么--------------------------------------------- - 对:我想要的

以防万一你想玩: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);
Run Code Online (Sandbox Code Playgroud)
谢谢你的帮助 ;)
使用Polygon类可以使重叠不透明度变为单一.

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);
Run Code Online (Sandbox Code Playgroud)
使用多个路径绘制一个多边形----------绘制多个圆圈

@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;
}
Run Code Online (Sandbox Code Playgroud)
此函数返回路径,因此您可以使用它来建立一个路径数组,您将在构建单个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);
Run Code Online (Sandbox Code Playgroud)
这就是全部,你绘制了一个复杂但单一的多边形,可能更容易使用.
对我来说唯一的问题是检查这个单一多边形中包含的标记(使用google function containsLocation和github.com/tparkin/Google-Maps-Point-in-Polygon)效果不佳,所以我不得不继续使用我的倍数圆来检查标记是否在我的区域中.
感谢@david strachan的回答.
| 归档时间: |
|
| 查看次数: |
2870 次 |
| 最近记录: |