source: src/django_gheat/gheat/opacity.py@ 9563

Last change on this file since 9563 was 9006, checked in by dennisw, 14 years ago

django_gheat - versie van gheat die gebruik maakt van django framework, ondersteunt SQL connecties in tegenstelling tot gheat dat gebruik maakt van sqlite

File size: 2.1 KB
Line 
1from django.core.exceptions import ImproperlyConfigured
2from django.conf import settings
3OPAQUE = 255
4TRANSPARENT = 0
5
6
7def _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
45def _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
57full_opaque = getattr(settings, 'GHEAT_FULL_OPAQUE', True)
58
59if full_opaque:
60 zoom_to_opacity = _opaque_zoom_mapping()
61else:
62 zoom_to_opacity = _build_zoom_mapping()
63
Note: See TracBrowser for help on using the repository browser.