1 | from django.core.exceptions import ImproperlyConfigured
|
---|
2 | from django.conf import settings
|
---|
3 | OPAQUE = 255
|
---|
4 | TRANSPARENT = 0
|
---|
5 |
|
---|
6 |
|
---|
7 | def _build_zoom_mapping(MAX_ZOOM=31):
|
---|
8 | """Build and return the zoom_to_opacity mapping
|
---|
9 | """
|
---|
10 | if MAX_ZOOM is None:
|
---|
11 | from gheat import MAX_ZOOM # won't use these in testing
|
---|
12 | from django.conf import settings
|
---|
13 |
|
---|
14 | zoom_opaque = getattr(settings, 'GHEAT_ZOOM_OPAQUE', -15)
|
---|
15 |
|
---|
16 | try:
|
---|
17 | zoom_opaque = int(zoom_opaque)
|
---|
18 | except ValueError:
|
---|
19 | raise ImproperlyConfigured("zoom_opaque must be an integer.")
|
---|
20 |
|
---|
21 | zoom_transparent = getattr(settings, 'GHEAT_ZOOM_TRANSPARENT', 15)
|
---|
22 | try:
|
---|
23 | zoom_transparent = int(zoom_transparent)
|
---|
24 | except ValueError:
|
---|
25 | raise ImproperlyConfigured("zoom_transparent must be an integer.")
|
---|
26 |
|
---|
27 | num_opacity_steps = zoom_transparent - zoom_opaque
|
---|
28 | zoom_to_opacity = dict()
|
---|
29 | if num_opacity_steps < 1: # don't want general fade
|
---|
30 | for zoom in range(0, MAX_ZOOM + 1):
|
---|
31 | zoom_to_opacity[zoom] = None
|
---|
32 | else: # want general fade
|
---|
33 | opacity_step = OPAQUE / float(num_opacity_steps) # chunk of opacity
|
---|
34 | for zoom in range(0, MAX_ZOOM + 1):
|
---|
35 | if zoom <= zoom_opaque:
|
---|
36 | opacity = OPAQUE
|
---|
37 | elif zoom >= zoom_transparent:
|
---|
38 | opacity = TRANSPARENT
|
---|
39 | else:
|
---|
40 | opacity = int(OPAQUE - ((zoom - zoom_opaque) * opacity_step))
|
---|
41 | zoom_to_opacity[zoom] = opacity
|
---|
42 |
|
---|
43 | return zoom_to_opacity
|
---|
44 |
|
---|
45 | def _opaque_zoom_mapping(settings=None, MAX_ZOOM=31):
|
---|
46 | """Build and return the zoom_to_opacity mapping
|
---|
47 | """
|
---|
48 | if MAX_ZOOM is None:
|
---|
49 | from gheat import MAX_ZOOM # won't use these in testing
|
---|
50 |
|
---|
51 | zoom_to_opacity = dict()
|
---|
52 | for zoom in range(0, MAX_ZOOM + 1):
|
---|
53 | zoom_to_opacity[zoom] = OPAQUE
|
---|
54 |
|
---|
55 | return zoom_to_opacity
|
---|
56 |
|
---|
57 | full_opaque = getattr(settings, 'GHEAT_FULL_OPAQUE', True)
|
---|
58 |
|
---|
59 | if full_opaque:
|
---|
60 | zoom_to_opacity = _opaque_zoom_mapping()
|
---|
61 | else:
|
---|
62 | zoom_to_opacity = _build_zoom_mapping()
|
---|
63 |
|
---|