Skip to content

Instantly share code, notes, and snippets.

@samuelcolvin
Last active September 20, 2016 12:19
Show Gist options
  • Save samuelcolvin/c732cbb470654262a15eb3e6734ade82 to your computer and use it in GitHub Desktop.
Save samuelcolvin/c732cbb470654262a15eb3e6734ade82 to your computer and use it in GitHub Desktop.
[
{
"featureType": "landscape",
"elementType": "all",
"stylers": [
{
"hue": "#FFBB00"
},
{
"saturation": 43.4
},
{
"lightness": 37.6
},
{
"gamma": 1
}
]
},
{
"featureType": "poi",
"elementType": "all",
"stylers": [
{
"hue": "#00FF6A"
},
{
"saturation": -1.10
},
{
"lightness": 11.2
},
{
"gamma": 1
}
]
},
{
"featureType": "road.highway",
"elementType": "all",
"stylers": [
{
"hue": "#FFC200"
},
{
"saturation": -61.8
},
{
"lightness": 45.6
},
{
"gamma": 1
}
]
},
{
"featureType": "road.arterial",
"elementType": "all",
"stylers": [
{
"hue": "#FF0300"
},
{
"saturation": -100
},
{
"lightness": 51.2
},
{
"gamma": 1
}
]
},
{
"featureType": "road.local",
"elementType": "all",
"stylers": [
{
"hue": "#FF0300"
},
{
"saturation": -100
},
{
"lightness": 52
},
{
"gamma": 1
}
]
},
{
"featureType": "water",
"elementType": "all",
"stylers": [
{
"color": "#016997"
}
]
}
]
import json
import sys
from pprint import pprint
# data direct from https://snazzymaps.com map editor
with open(sys.argv[1]) as f:
style_info = json.load(f)
def get_style(stylers, key):
return next((v[key] for v in stylers if key in v), None)
def map_style(style):
parts = []
if style['featureType'] != 'all':
parts.append('feature:{featureType}'.format(**style))
if style['elementType'] != 'all':
parts.append('element:{elementType}'.format(**style))
stylers = style.get('stylers', {})
visibility = get_style(stylers, 'visibility')
if visibility != 'off':
color = get_style(stylers, 'color')
if color:
parts.append('color:{}'.format(color.replace('#', '0x')))
lightness = get_style(stylers, 'lightness')
if lightness:
parts.append('lightness:{}'.format(lightness))
saturation = get_style(stylers, 'saturation')
if saturation:
parts.append('saturation:{}'.format(saturation))
gamma = get_style(stylers, 'gamma')
if gamma:
parts.append('gamma:{}'.format(gamma))
if visibility:
parts.append('visibility:{}'.format(visibility))
return 'style', '|'.join(parts)
pprint([map_style(s) for s in style_info])
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment