我已经设法在地图上放置一个圆圈并使其可编辑:
var circle = new google.maps.Circle({
map: map,
radius: 1609.344, // 1 mile
editable: true,
fillOpacity: 0.25
});
circle.bindTo('center', marker, 'position');
然而,这使得半径和中心都可以编辑。我只希望半径可以编辑。我看不出有什么办法可以通过google.maps.Circle
.
我所追求的几乎就是这里的内容:
http://www.freemaptools.com/radius-around-point.htm
但是我看不出它是如何完成的,因为他们的代码看起来很混乱。
您可以尝试监听 center_changed 事件,并在它触发时重新定位中心,例如:
全局变量:
var centerPoint = new G.LatLng(45.5, -100.5);
var ignore = false;
var poly;
//position the map where the circle is so we can see it.
map.setCenter(centerPoint);
map.setZoom(11);
进而:
poly = new google.maps.Circle({
map: map,
center:centerPoint,
radius: 1609.344, // 1 mile
editable: true,
fillOpacity: 0.25
});
G.event.addListener(poly,'center_changed',function(){
if (ignore){
ignore = false;
return;
}
poly.setEditable(false);
ignore = true;
poly.setCenter(centerPoint);
poly.setEditable(true);
});
唯一的问题是中心标记可能会误导用户。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)