So I can't find an answer to this, but I know it's possible, because I've seen it.
I'm trying to toggle specific style options on my custom styled map without having to reinitialize the map and losing any pins dropped, or locations searched.
For example, turning off and on road labels. I have accomplished this in a hacky way where I've created two complete style objects, and I switch between them with map.setMapTypeId
.
The problem with this is that a) it's very repetitive, and b) I have a lot of options I want to be able to toggle, so having to make styled sheets for every single variation of my toggle-able options is not realistic.
The realistic solution is to be able to concat objects on to my style options without undoing the previous style options entirely.
e.g.
{
'featureType': 'landscape',
'elementType': 'geometry',
'stylers': [{'color': '#eaeaea'}]
}
then concatenating this style:
{
'featureType': 'all',
'elementType': 'labels',
'stylers': [{'visibility': 'off'}]
}
I can't just alter the original object because the styles won't take until the map is reloaded, causing me to lose my markers and map position.
I need it to function something like map.setMapTypeId('styled_map', 'styled_map_2');
where my styles are just compiled.
Hopefully I've made the dilemma clear.
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…