我正在使用以下函数在地图上设置折线样式:
countyLayer.addListener('click', function(event) {
countyLayer.overrideStyle(event.feature, {strokeWeight: 8});
});
Run Code Online (Sandbox Code Playgroud)
现在我想在点击折线时删除样式,如果之前已设置样式.
我试过这个:
countyLayer.addListener('click', function(event) {
if (feature.strokeWeight == 8){ //problem is here I think ?
countyLayer.overrideStyle(event.feature, {strokeWeight: 2});
}
else {
countyLayer.overrideStyle(event.feature, {strokeWeight: 8});
}
});
Run Code Online (Sandbox Code Playgroud)
我试着在这里获得一些帮助:https://developers.google.com/maps/documentation/javascript/examples/layer-data-dynamic 但他没有解释如何删除点击样式
谢谢你的帮助