我已经找到了使用以下内容设置标记可见性的方法:
// create the marker
blueMarker = new google.maps.Marker({
position: new google.maps.LatLng(33.514428, -112.29056534285377),
draggable: true,
raiseOnDrag: false,
icon: './Images/blue3Marker.png',
shapeType: 'BuyersEdgeArea',
shapeID: '3'
});
// set the marker on the map
blueMarker.setMap(map);然后我使用blueMarker.setVisible(false)或blueMarker.setVisible(true)使其可见/不可见。
但是如何对多边形执行相同的操作呢?
下面是我如何设置我的多边形:
BuyersEdge3 = new google.maps.Polygon({
clickable: true,
paths: BuyersEdgePath3,
strokeColor: '#000000',
strokeOpacity: 1,
strokeWeight: 2,
fillColor: ' #810541 ',
fillOpacity: 0.35
});
// set the shape on the map
BuyersEdge3.setMap(map);现在我该如何使这个形状不可见呢?
我的情况是,我有一个复选框,用户可以在其中检查是否看到多边形。第一次检查时,我将创建多边形,但随后,我只想使多边形形状可见或不可见。
我正在转换一个虚拟地球应用程序,在那里我可以只“显示”或“隐藏”一个带有多边形的图层,但我找不到一些东西来使用JavaScript为Google API版本3做这件事。
发布于 2015-05-27 15:01:21
if (BuyersEdge3.map)
{
BuyersEdge3.setMap(null);
} else {
BuyersEdge3.setMap(map);
}https://stackoverflow.com/questions/8334197
复制相似问题