我找到了使用以下方法设置标记可见性的方法:
// 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);
Run Code Online (Sandbox Code Playgroud)
然后我使用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);
Run Code Online (Sandbox Code Playgroud)
现在我怎么能让这个形状不可见?
我的情况是我有一个复选框,用户检查是否看到多边形.第一次检查时,我将创建多边形,但随后的时间,我只想让多边形形状可见或不可见.
我正在转换一个虚拟地球应用程序,我可以在其中"显示"或"隐藏"包含多边形的图层,但我无法使用JavaScript找到针对Google API第3版的诀窍.