Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Maps Styles decoded for Google based on https://github.com/julienben/gmaps-apistyle-encoder
styleparse_types = {"all": "0", "administrative": "1", "administrative.country": "17",
"administrative.land_parcel": "21", "administrative.locality": "19",
"administrative.neighborhood": "20", "administrative.province": "18", "landscape": "5",
"landscape.man_made": "81", "landscape.natural": "82", "poi": "2", "poi.attraction": "37",
"poi.business": "33", "poi.government": "34", "poi.medical": "36", "poi.park": "40",
"poi.place_of_worship": "38", "poi.school": "35", "poi.sports_complex": "39", "road": "3",
"road.arterial": "50", "road.highway": "49", "road.local": "51", "transit": "4",
"transit.line": "65", "transit.station": "66", "water": "6"}
styleparse_elements = {"all": "a", "geometry": "g", "geometry.fill": "g.f", "geometry.stroke": "g.s", "labels": "l",
"labels.icon": "l.i", "labels.text": "l.t", "labels.text.fill": "l.t.f",
"labels.text.stroke": "l.t.s"}
styleparse_stylers = {"color": "p.c", "gamma": "p.g", "hue": "p.h", "invert_lightness": "p.il", "lightness": "p.l",
"saturation": "p.s", "visibility": "p.v", "weight": "p.w"}
def decode_style(styles: list) -> str:
parsed_style = ""
for style in styles:
if style.get('featureType'):
parsed_style += "s.t:" + styleparse_types[style.get("featureType")] + "|"
if style.get('elementType'):
parsed_style += "s.e:" + styleparse_elements[style.get("elementType")] + "|"
for styler in style.get("stylers"):
keys = []
for k in styler:
if k == "color" and len(styler[k]) == 7:
styler[k] = "#ff" + str(styler[k][1:])
parsed_style += styleparse_stylers[k] + ":" + str(styler[k]) + "|"
parsed_style += ","
from urllib.parse import quote
return quote(parsed_style)
if __name__ == '__main__':
styles = [
{
"elementType": "geometry",
"stylers": [
{
"color": "#1d2c4d"
}
]
},
{
"elementType": "labels",
"stylers": [
{
"visibility": "off"
}
]
},
{
"elementType": "labels.text.fill",
"stylers": [
{
"color": "#8ec3b9"
}
]
},
{
"elementType": "labels.text.stroke",
"stylers": [
{
"color": "#1a3646"
}
]
},
{
"featureType": "administrative.country",
"elementType": "geometry.stroke",
"stylers": [
{
"color": "#4b6878"
}
]
},
{
"featureType": "administrative.land_parcel",
"stylers": [
{
"visibility": "off"
}
]
},
{
"featureType": "administrative.land_parcel",
"elementType": "labels.text.fill",
"stylers": [
{
"color": "#64779e"
}
]
},
{
"featureType": "administrative.neighborhood",
"stylers": [
{
"visibility": "off"
}
]
},
{
"featureType": "administrative.province",
"elementType": "geometry.stroke",
"stylers": [
{
"color": "#4b6878"
}
]
},
{
"featureType": "landscape.man_made",
"elementType": "geometry.stroke",
"stylers": [
{
"color": "#334e87"
}
]
},
{
"featureType": "landscape.natural",
"elementType": "geometry",
"stylers": [
{
"color": "#023e58"
}
]
},
{
"featureType": "poi",
"elementType": "geometry",
"stylers": [
{
"color": "#283d6a"
}
]
},
{
"featureType": "poi",
"elementType": "labels.text.fill",
"stylers": [
{
"color": "#6f9ba5"
}
]
},
{
"featureType": "poi",
"elementType": "labels.text.stroke",
"stylers": [
{
"color": "#1d2c4d"
}
]
},
{
"featureType": "poi.park",
"elementType": "geometry.fill",
"stylers": [
{
"color": "#023e58"
}
]
},
{
"featureType": "poi.park",
"elementType": "labels.text.fill",
"stylers": [
{
"color": "#3C7680"
}
]
},
{
"featureType": "road",
"elementType": "geometry",
"stylers": [
{
"color": "#304a7d"
}
]
},
{
"featureType": "road",
"elementType": "labels.text.fill",
"stylers": [
{
"color": "#98a5be"
}
]
},
{
"featureType": "road",
"elementType": "labels.text.stroke",
"stylers": [
{
"color": "#1d2c4d"
}
]
},
{
"featureType": "road.highway",
"elementType": "geometry",
"stylers": [
{
"color": "#2c6675"
}
]
},
{
"featureType": "road.highway",
"elementType": "geometry.stroke",
"stylers": [
{
"color": "#255763"
}
]
},
{
"featureType": "road.highway",
"elementType": "labels.text.fill",
"stylers": [
{
"color": "#b0d5ce"
}
]
},
{
"featureType": "road.highway",
"elementType": "labels.text.stroke",
"stylers": [
{
"color": "#023e58"
}
]
},
{
"featureType": "transit",
"elementType": "labels.text.fill",
"stylers": [
{
"color": "#98a5be"
}
]
},
{
"featureType": "transit",
"elementType": "labels.text.stroke",
"stylers": [
{
"color": "#1d2c4d"
}
]
},
{
"featureType": "transit.line",
"elementType": "geometry.fill",
"stylers": [
{
"color": "#283d6a"
}
]
},
{
"featureType": "transit.station",
"elementType": "geometry",
"stylers": [
{
"color": "#3a4762"
}
]
},
{
"featureType": "water",
"elementType": "geometry",
"stylers": [
{
"color": "#0e1626"
}
]
},
{
"featureType": "water",
"elementType": "labels.text.fill",
"stylers": [
{
"color": "#4e6d70"
}
]
}
]
print(decode_style(styles))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment