Skip to content

Commit f6e653d

Browse files
committed
Icon class implementation
1 parent 3f0ae48 commit f6e653d

File tree

1 file changed

+77
-0
lines changed

1 file changed

+77
-0
lines changed

pymaps/icon.py

Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
from PIL import Image
2+
import requests
3+
from io import BytesIO
4+
5+
colors = {
6+
'amber' : ('FFC107', 'FF6F00'),
7+
'blakwhite' : ('000000', 'FFFFFF'),
8+
'blue' : ('2196F3', '0D47A1'),
9+
'bluewhite' : ('0277BD', 'FFFFFF'),
10+
'cyan' : ('00BCD4', '006064'),
11+
'deeppurple': ('673AB7', '311B92'),
12+
'deeporange': ('FF5722', 'BF360C'),
13+
'gray' : ('9E9E9E', '212121'),
14+
'green' : ('4CAF50', '1B5E20'),
15+
'indigo' : ('3F51B5', '1A237E'),
16+
'lightblue' : ('03A9F4', '01579B'),
17+
'lightgreen': ('8BC34A', '33691E'),
18+
'lime' : ('CDDC39', '827717'),
19+
'orange' : ('FF9800', 'E65100'),
20+
'pink' : ('E91E63', '880E4F'),
21+
'purple' : ('9C27B0', '4A148C'),
22+
'red' : ('ea4335', '960a0a'),
23+
'teal' : ('009688', '004D40'),
24+
'yellow' : ('FFEB3B', 'F57F17'),
25+
}
26+
27+
google = 'http://www.google.com/maps/vt/icon/name=assets/icons'
28+
pinlet = '/poi/tactile/pinlet_shadow-1-small.png,assets/icons/poi/tactile/pinlet-1-small.png,assets/icons/poi/quantum/pinlet/'
29+
30+
31+
icons = {
32+
'pin': google + '/spotlight/spotlight_pin_v2_shadow-1-small.png,assets/icons/spotlight/spotlight_pin_v2-1-small.png,assets/icons/spotlight/spotlight_pin_v2_dot-1-small.png,assets/icons/spotlight/spotlight_pin_v2_accent-1-small.png&highlight=FF00FF,{},{},FF00FF&color=FF00FF?scale={}',
33+
'airport': google + pinlet + 'airport_pinlet-1-small.png&highlight=ff000000,{},{}&color=ff000000?scale={}',
34+
'hospital': google + pinlet + 'hospital_H_pinlet-1-small.png&highlight=ff000000,{},{}&color=ff000000?scale={}',
35+
'home': google + pinlet + 'home_pinlet-1-small.png&highlight=ffffff,{},{}&color=ff000000?scale={}',
36+
'dot': google + pinlet + 'dot_pinlet-1-small.png&highlight=ff000000,{},{}&color=ff000000?scale={}',
37+
'start': google + pinlet + 'constellation_star_pinlet-1-small.png&highlight=ff000000,{},{},ffffff&color=ff000000?scale={}',
38+
'heart': google + pinlet + 'heart_pinlet-1-small.png&highlight=ff000000,{},{},ffffff&color=ff000000?scale={}',
39+
'flag': google + pinlet + 'nickname_pinlet-1-small.png&highlight=ff000000,{},{},ffffff&color=ff000000?scale={}'
40+
}
41+
42+
43+
def color_picker(color, shape):
44+
if color is None:
45+
if shape == 'pin':
46+
pick = colors['red']
47+
else:
48+
pick = colors['bluewhite']
49+
else:
50+
if isinstance(color, (list, tuple)):
51+
pick = [i.replace('#', '') for i in color]
52+
else:
53+
pick = colors.get(color, colors['red'])
54+
return pick
55+
56+
57+
class Icon():
58+
def __init__(self, shape='pin', color=None, size=1):
59+
self.shape = shape
60+
self.color = color_picker(color, shape)
61+
self.size = size
62+
63+
@property
64+
def url(self):
65+
url = icons.get(self.shape, icons['pin'])
66+
return url.format(*self.color, self.size)
67+
68+
for shape, url in icons.items():
69+
for color in colors:
70+
for size in range(1, 5):
71+
i = Icon(shape=shape, color=color, size=size)
72+
print(i.url)
73+
im = requests.get(i.url, timeout=1)
74+
im.status_code
75+
im = BytesIO(im.content)
76+
im = Image.open(im)
77+
im.save(shape + color + size + '.png')

0 commit comments

Comments
 (0)