I am using the Google Maps API data layer, and I have the following function that I would be grateful for some help with.
The problem is with the "if" statement. I cannot work out how to format it correctly, to check if datalayer1 is visible. This is due to my lack of recent use of Javascript! Even when the layer is visible, the if statement is satisfied, and thinks the layer is NOT visible, when it is.
This is what I see in console.log: https://imgur.com/a/BAJyvto
function toggleDataLayer1() {
console.log(datalayer1.getStyle())
if (datalayer1.getStyle({visible: false})) {
datalayer1.setStyle({
icon: icon,
clickable: true,
visible: true
});
} else {
datalayer1.setStyle({visible: false});
}
}
question from:
https://stackoverflow.com/questions/65949174/how-to-check-if-data-layer-is-visible-google-maps-api 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…