问题
I know you can toggle visibility of markers using google api, but is it possible to toggle the visibility of a polyline using an html checkbox?
Basically, I have a polyline and if the checkbox is checked, I want the polyline visible, and if it is unchecked, I want it hidden. Is this possible?
回答1:
You toggle the visibility of a polyline the same way you do a marker.
setMap(null)
To display it again, call the setMap method with a reference to your google.maps.Map object.
documentation
setMap(map:Map) - Renders this shape on the specified map. If map is set to null, the shape will be removed.
来源:https://stackoverflow.com/questions/13678041/toggle-visibility-of-polyline-using-google-api-v3