Skip to content

Commit 7912d85

Browse files
committed
Used template for legend.
1 parent 4757bf0 commit 7912d85

4 files changed

Lines changed: 23 additions & 10 deletions

File tree

users/static/js/user-map-component.js

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -186,7 +186,7 @@ function createUserMenuControl(options) {
186186
*
187187
* @returns {object} control
188188
*/
189-
function createLegendControl(user_icon_path, trainer_icon_path, developer_icon_path){
189+
function createLegendControl(){
190190
var control;
191191
control = L.Control.extend({
192192
options: {
@@ -195,10 +195,7 @@ function createLegendControl(user_icon_path, trainer_icon_path, developer_icon_p
195195
onAdd: function () {
196196
var legend_container = L.DomUtil.create('div',
197197
'info legend');
198-
legend_container.innerHTML += "<h4>Legend</h4>";
199-
legend_container.innerHTML += "<img height='25' width='20' src='" +user_icon_path + "'>" + " User<br>";
200-
legend_container.innerHTML += "<img height='25' width='20' src='" +trainer_icon_path + "'>" + " Trainer<br>";
201-
legend_container.innerHTML += "<img height='25' width='20' src='" +developer_icon_path + "'>" + " Developer";
198+
legend_container.innerHTML += $("#legend").html();
202199

203200
//Prevent firing drag and onClickMap event when clicking this control
204201
var stop = L.DomEvent.stopPropagation;

users/templates/html/base.html

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@
4747
{{ user_menu_button | safe }}
4848
{{ information_modal | safe }}
4949
{{ data_privacy_content | safe }}
50+
{{ legend | safe }}
5051
{{ user_form_template | safe }}
5152
<!-- endblock of all the template -->
5253

@@ -95,11 +96,7 @@
9596
container: 'body'});
9697

9798
// Create Legend Control:
98-
legend_control = createLegendControl(
99-
'{{ user_icons.user }}',
100-
'{{ user_icons.trainer }}',
101-
'{{ user_icons.developer }}'
102-
)
99+
legend_control = createLegendControl();
103100
map.addControl(new legend_control);
104101
</script>
105102

users/templates/html/legend.html

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
<script id="legend" type="text/template">
2+
<h4>Legend</h4>
3+
<img height='25' width='20' src='{{ user_icons.user }}'> User<br>
4+
<img height='25' width='20' src='{{ user_icons.trainer }}'> Trainer<br>
5+
<img height='25' width='20' src='{{ user_icons.developer }}'> Developer
6+
</script>
7+

users/views.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,11 @@ def map_view():
3535
#noinspection PyUnresolvedReferences
3636
data_privacy_content = render_template('html/data_privacy.html')
3737
#noinspection PyUnresolvedReferences
38+
legend = render_template(
39+
'html/legend.html',
40+
user_icons=APP.config['USER_ICONS']
41+
)
42+
#noinspection PyUnresolvedReferences
3843
user_form_template = render_template('html/user_form.html')
3944
user_menu = dict(
4045
add_user=True,
@@ -56,6 +61,7 @@ def map_view():
5661
user_icons=APP.config['USER_ICONS'],
5762
information_modal=information_modal,
5863
data_privacy_content=data_privacy_content,
64+
legend=legend,
5965
user_form_template=user_form_template,
6066
user_menu=user_menu,
6167
user_menu_button=user_menu_button
@@ -198,6 +204,11 @@ def edit_user_view(guid):
198204
#noinspection PyUnresolvedReferences
199205
data_privacy_content = render_template('html/data_privacy.html')
200206
#noinspection PyUnresolvedReferences
207+
legend = render_template(
208+
'html/legend.html',
209+
user_icons=APP.config['USER_ICONS']
210+
)
211+
#noinspection PyUnresolvedReferences
201212
user_form_template = render_template('html/user_form.html')
202213
user_menu = dict(
203214
edit_user=True,
@@ -221,6 +232,7 @@ def edit_user_view(guid):
221232
edited_user_popup_content=user_popup_content,
222233
information_modal=information_modal,
223234
data_privacy_content=data_privacy_content,
235+
legend=legend,
224236
user_form_template=user_form_template,
225237
user_menu=user_menu,
226238
user_menu_button=user_menu_button

0 commit comments

Comments
 (0)