/
admin.py
61 lines (48 loc) · 1.78 KB
/
admin.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
from django.contrib.gis.admin import site, GeoModelAdmin
from django.conf import settings
from geoportal import utils
class GeoPortalAdmin(GeoModelAdmin):
"""A base model for displaying a GeoPortal admin map"""
##############
# Public API #
##############
map_width = utils.DEFAULT_WIDTH # Dimensions of the
map_height = utils.DEFAULT_HEIGHT # map (pixels)
max_zoom = 20 # Zoom levels: 20 = finest
min_zoom = 0 # 0 = world
point_zoom = utils.POINT_ZOOM # Default zoom level for a single point
default_zoom = 5 # display a whole country
default_lon = 2 # Default location
default_lat = 47 # is France
# Show map info or not
map_info = False
# Layers
layers = (
# ('code', opacity),
# Order matters, layers are added in this order.
#('photos', 1),
('maps', 1),
)
# Display the layer switcher
layerswitcher = True
###############
# Private API #
###############
map_template = 'gis/admin/geoportal.html'
wms_url = utils.WMS_URL
@property
def openlayers_url(self):
base_url = getattr(settings, 'GEOPORTAL_MEDIA_URL', utils.MEDIA_URL)
return base_url + 'GeoportalExtended.js'
# Mouse position: already displayed by Geoportail
mouse_position = False
# Same for scale
scale_text = False
def get_map_widget(self, db_field):
widget = super(GeoPortalAdmin, self).get_map_widget(db_field)
widget.params['map_info'] = self.map_info
widget.params['layers'] = utils.get_layers(self.layers)
widget.params['api_key'] = settings.GEOPORTAL_API_KEY
widget.params['feature_color'] = utils.DEFAULT_COLOR
widget.params['feature_opacity'] = utils.DEFAULT_OPACITY
return widget