0001-maps-display-marker-data-in-popup-21034.patch
combo/apps/maps/migrations/0005_auto_20180213_1611.py | ||
---|---|---|
1 |
# -*- coding: utf-8 -*- |
|
2 |
from __future__ import unicode_literals |
|
3 | ||
4 |
from django.db import migrations, models |
|
5 | ||
6 | ||
7 |
class Migration(migrations.Migration): |
|
8 | ||
9 |
dependencies = [ |
|
10 |
('maps', '0004_map_initial_state'), |
|
11 |
] |
|
12 | ||
13 |
operations = [ |
|
14 |
migrations.AddField( |
|
15 |
model_name='map', |
|
16 |
name='display_marker_data', |
|
17 |
field=models.BooleanField(default=False, verbose_name='Display marker data'), |
|
18 |
), |
|
19 |
migrations.AlterField( |
|
20 |
model_name='maplayer', |
|
21 |
name='icon', |
|
22 |
field=models.CharField(blank=True, max_length=32, null=True, verbose_name='Marker icon', choices=[(b'ambulance', 'Ambulance'), (b'asterisk', 'Asterisk'), (b'bell', 'Bell'), (b'bicycle', 'Bicycle'), (b'book', 'Book'), (b'broken_chain', 'Broken chain'), (b'building', 'Building'), (b'bus', 'Bus'), (b'car', 'Car'), (b'checkmark', 'Checkmark'), (b'cube', 'Cube'), (b'drop', 'Drop'), (b'eye', 'Eye'), (b'flag', 'Flag'), (b'gavel', 'Gavel'), (b'hospital', 'Hospital'), (b'house', 'House'), (b'lightbulb', 'Lightbulb'), (b'map_signs', 'Map signs'), (b'motorcycle', 'Motorcycle'), (b'paint_brush', 'Paint brush'), (b'paw', 'Paw'), (b'recycle', 'Recycle'), (b'road', 'Road'), (b'shower', 'Shower'), (b'star', 'Star'), (b'subway', 'Subway'), (b'taxi', 'Taxi'), (b'train', 'Train'), (b'trash', 'Trash'), (b'tree', 'Tree'), (b'truck', 'Truck'), (b'university', 'University'), (b'warning', 'Warning'), (b'wheelchair', 'Wheelchair')]), |
|
23 |
), |
|
24 |
] |
combo/apps/maps/models.py | ||
---|---|---|
200 | 200 |
choices=ZOOM_LEVELS, default='0') |
201 | 201 |
max_zoom = models.CharField(_('Maximal zoom level'), max_length=2, |
202 | 202 |
choices=ZOOM_LEVELS, default=19) |
203 |
display_marker_data = models.BooleanField(default=False, verbose_name=_('Display marker data')) |
|
203 | 204 |
layers = models.ManyToManyField(MapLayer, verbose_name=_('Layers'), blank=True) |
204 | 205 | |
205 | 206 |
template_name = 'maps/map_cell.html' |
... | ... | |
216 | 217 | |
217 | 218 |
def get_default_form_class(self): |
218 | 219 |
fields = ('title', 'initial_state', 'initial_zoom', 'min_zoom', |
219 |
'max_zoom', 'layers') |
|
220 |
'max_zoom', 'display_marker_data', 'layers')
|
|
220 | 221 |
widgets = {'layers': forms.widgets.CheckboxSelectMultiple} |
221 | 222 |
return forms.models.modelform_factory(self.__class__, fields=fields, |
222 | 223 |
widgets=widgets) |
... | ... | |
245 | 246 |
ctx['tile_urltemplate'] = settings.COMBO_MAP_TILE_URLTEMPLATE |
246 | 247 |
ctx['map_attribution'] = settings.COMBO_MAP_ATTRIBUTION |
247 | 248 |
ctx['max_bounds'] = settings.COMBO_MAP_MAX_BOUNDS |
249 |
ctx['display_marker_data'] = self.display_marker_data |
|
248 | 250 |
return ctx |
combo/apps/maps/static/js/combo.map.js | ||
---|---|---|
12 | 12 |
var geo_json = L.geoJson(data, { |
13 | 13 |
onEachFeature: function(feature, layer) { |
14 | 14 |
$(cell).trigger('combo:map-feature-prepare', {'feature': feature, 'layer': layer}); |
15 |
var display_marker_data = $map_widget.data('display-marker-properties'); |
|
16 |
if (display_marker_data){ |
|
17 |
var popup = ''; |
|
18 |
if (feature.properties.display_fields) { |
|
19 |
$.each(feature.properties.display_fields, function(key, value) { |
|
20 |
popup += '<p class="popup-field"><span class="field-label">' + value[0] + '</span>'; |
|
21 |
popup += '<span class="field-value">' + value[1] + '</span></p>'; |
|
22 |
}); |
|
23 |
} else { |
|
24 |
$.each(feature.properties, function(key, value){ |
|
25 |
// exclude object type properties |
|
26 |
if (typeof(value) !== 'object'){ |
|
27 |
popup += '<p class="popup-field"><span class="field-label">' + key + '</span>' + '</p>'; |
|
28 |
popup += '<span class="field-value">' + value + '</span></p>'; |
|
29 |
} |
|
30 |
}); |
|
31 |
} |
|
32 |
layer.bindPopup(popup); |
|
33 |
} |
|
15 | 34 |
}, |
16 | 35 |
pointToLayer: function (feature, latlng) { |
17 | 36 |
var markerStyles = "background-color: " + feature.properties.layer.colour + ";"; |
combo/apps/maps/templates/maps/map_cell.html | ||
---|---|---|
6 | 6 |
data-max-zoom="{{ max_zoom }}" data-init-lat="{{ init_lat }}" |
7 | 7 |
data-init-lng="{{ init_lng }}" data-geojson-url="{{ geojson_url }}" |
8 | 8 |
data-tile-urltemplate="{{ tile_urltemplate}}" data-map-attribution="{{ map_attribution}}" |
9 |
{% if cell.display_marker_data %} |
|
10 |
data-display-marker-properties="{{ cell.display_marker_data }}" |
|
11 |
{% endif %} |
|
9 | 12 |
{% if max_bounds.corner1.lat %} |
10 | 13 |
data-max-bounds-lat1="{{ max_bounds.corner1.lat }}" |
11 | 14 |
data-max-bounds-lng1="{{ max_bounds.corner1.lng }}" |
12 |
- |