包含的JavaScript代码段应该执行以下操作:
有人能告诉我一种方法吗?
当用户单击地图时,初始化headMarker并在其周围绘制一个圆形(多边形)
当用户在圆形内单击时,初始化tailMarker并在这两个标记之间绘制路径
function(overlay,point)
中,overlay
是非空的,而point
为空。因此,代码无法初始化tailMarker。有人能告诉我一种方法吗?
GEvent.addListener(map, "click", function(overlay,point) {
if (isCreateHeadPoint) {
// add the head marker
headMarker = new GMarker(point,{icon:redIcon,title:'0'});
map.addOverlay(headMarker);
isCreateHeadPoint = false;
// draw the circle
drawMapCircle(point.lat(),point.lng(),1,'#cc0000',2,0.8,'#0',0.1);
} else {
// add the tail marker
tailMarker = new GMarker(point,{icon:greenIcon,title:''});
map.addOverlay(tailMarker);
isCreateHeadPoint = true;
// load thes path from head to tail
direction.load("from:" + headMarker.getPoint().lat()+ ", " +
headMarker.getPoint().lng()+ " " +
"to:" + tailMarker.getPoint().lat() + "," +
tailMarker.getPoint().lng(),
{getPolyline:true});
}
});
clickable: false
,您告诉 API,发生在多边形上的点击应该被处理为对地图的点击,而不是对多边形的点击。 - Daniel Vassallo