Skip to content

Commit

Permalink
Signage and infrastructure on PDF
Browse files Browse the repository at this point in the history
  • Loading branch information
Gaël UTARD committed Nov 23, 2018
1 parent 4a31d8d commit 8ef1a18
Show file tree
Hide file tree
Showing 18 changed files with 191 additions and 15 deletions.
4 changes: 4 additions & 0 deletions docs/changelog.rst
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,10 @@ CHANGELOG
2.21.2.dev0
-------------------

**New features**

- Allow to publish signage and infrastructure

**Bug fixes**

- Fix a clash between current url and SYNC_RANDO_OPTIONS
Expand Down
4 changes: 2 additions & 2 deletions geotrek/infrastructure/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,8 @@ def save_model(self, request, obj, form, change):

def get_list_display(self, request):
if not request.user.has_perm('authent.can_bypass_structure'):
return ('label', 'type')
return ('label', 'type', 'structure')
return ('label', 'type', 'pictogram_img')
return ('label', 'type', 'structure', 'pictogram_img')

def get_list_filter(self, request):
if not request.user.has_perm('authent.can_bypass_structure'):
Expand Down
3 changes: 2 additions & 1 deletion geotrek/infrastructure/fixtures/basic.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@
"model": "infrastructure.infrastructuretype",
"fields": {
"type": "A",
"label": "Aire de stationnement"
"label": "Aire de stationnement",
"pictogram": "upload/infra-parking.png"
}
},
{
Expand Down
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,6 @@ class Migration(migrations.Migration):
migrations.AddField(
model_name='infrastructuretype',
name='pictogram',
field=models.FileField(db_column=b'picto', max_length=512, null=True, upload_to=b'upload', verbose_name='Pictogram'),
field=models.FileField(blank=True, db_column=b'picto', max_length=512, null=True, upload_to=b'upload', verbose_name='Pictogram'),
),
]
4 changes: 2 additions & 2 deletions geotrek/infrastructure/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
from geotrek.common.utils import classproperty
from geotrek.core.models import Topology, Path
from geotrek.authent.models import StructureRelatedManager, StructureRelated, StructureOrNoneRelated
from geotrek.common.mixins import BasePublishableMixin, PictogramMixin
from geotrek.common.mixins import BasePublishableMixin, OptionalPictogramMixin


INFRASTRUCTURE_TYPES = Choices(
Expand Down Expand Up @@ -37,7 +37,7 @@ def for_infrastructures(self):
return self.get_queryset().for_infrastructures()


class InfrastructureType(StructureOrNoneRelated, PictogramMixin):
class InfrastructureType(StructureOrNoneRelated, OptionalPictogramMixin):
""" Types of infrastructures (bridge, WC, stairs, ...) """
label = models.CharField(db_column="nom", max_length=128)
type = models.CharField(db_column="type", max_length=1, choices=INFRASTRUCTURE_TYPES)
Expand Down
45 changes: 45 additions & 0 deletions geotrek/infrastructure/static/infrastructure/main.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
//
// Signage
//

$(window).on('entity:map', function (e, data) {
var map = data.map;

// Show signage layer in application maps
var layer = new L.ObjectsLayer(null, {
modelname: 'signage',
style: L.Util.extend(window.SETTINGS.map.styles['signage'] || {}, { clickable:false }),
pointToLayer: function (feature, latlng) {
return L.marker(latlng).bindLabel(feature.properties.name, { noHide: true });
}
});
var url = window.SETTINGS.urls['signage_layer'];
layer.load(url);
map.layerscontrol.addOverlay(layer, tr('Signage'), tr('Infrastructure'));
});


//
// Infrastructure
//

$(window).on('entity:map', function (e, data) {
var map = data.map;

// Show infrastructure layer in application maps
var layer = new L.ObjectsLayer(null, {
modelname: 'infrastructure',
style: L.Util.extend(window.SETTINGS.map.styles['infrastructure'] || {}, { clickable:false }),
pointToLayer: function (feature, latlng) {
var infrastructureIcon = L.icon({
iconUrl: feature.properties.type.pictogram,
iconSize: [18, 18],
iconAnchor: [9, 9],
});
return L.marker(latlng, {icon: infrastructureIcon});
}
});
var url = window.SETTINGS.urls['infrastructure_layer'];
layer.load(url);
map.layerscontrol.addOverlay(layer, tr('Infrastructure'), tr('Infrastructure'));
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{% load i18n %}

<script type="text/javascript">
MapEntity.i18n['Signages'] = "{% trans "Signages" %}";
MapEntity.i18n['Infrastructures'] = "{% trans "Infrastructures" %}";
</script>
8 changes: 8 additions & 0 deletions geotrek/settings/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -540,9 +540,17 @@ def gettext_noop(s):

TREK_ICON_SIZE_POI = 18
TREK_ICON_SIZE_SERVICE = 18
TREK_ICON_SIZE_SIGNAGE = 18
TREK_ICON_SIZE_INFRASTRUCTURE = 18
TREK_ICON_SIZE_PARKING = 18
TREK_ICON_SIZE_INFORMATION_DESK = 18

SHOW_SENSITIVE_AREAS_ON_MAP_SCREENSHOT = True
SHOW_POIS_ON_MAP_SCREENSHOT = True
SHOW_SERVICES_ON_MAP_SCREENSHOT = True
SHOW_SIGNAGES_ON_MAP_SCREENSHOT = True
SHOW_INFRASTRUCTURES_ON_MAP_SCREENSHOT = True

# Static offsets in projection units
TOPOLOGY_STATIC_OFFSETS = {'land': -5,
'physical': 0,
Expand Down
2 changes: 1 addition & 1 deletion geotrek/trekking/management/commands/sync_rando.py
Original file line number Diff line number Diff line change
Expand Up @@ -259,7 +259,7 @@ def sync_trek_infrastructures(self, lang, trek, zipfile=None):
def sync_trek_signages(self, lang, trek, zipfile=None):
params = {'format': 'geojson'}
view = TrekSignageViewSet.as_view({'get': 'list'})
name = os.path.join('api', lang, 'treks', str(trek.pk), 'infrastructures.geojson')
name = os.path.join('api', lang, 'treks', str(trek.pk), 'signages.geojson')
self.sync_view(lang, view, name, params=params, zipfile=zipfile, pk=trek.pk)

def sync_trek_pois(self, lang, trek, zipfile=None):
Expand Down
21 changes: 14 additions & 7 deletions geotrek/trekking/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -417,13 +417,20 @@ def meta_description(self):
return plain_text(self.ambiance or self.description_teaser or self.description)[:500]

def get_printcontext(self):
return {
"maplayers": [
ugettext(u"Sensitive area"),
ugettext(u"POIs"),
ugettext(u"services"),
settings.LEAFLET_CONFIG['TILES'][0][0],
]}
maplayers = [
settings.LEAFLET_CONFIG['TILES'][0][0],
]
if settings.SHOW_SENSITIVE_AREAS_ON_MAP_SCREENSHOT:
maplayers.append(ugettext(u"Sensitive area"))
if settings.SHOW_POIS_ON_MAP_SCREENSHOT:
maplayers.append(ugettext(u"POIs"))
if settings.SHOW_SERVICES_ON_MAP_SCREENSHOT:
maplayers.append(ugettext(u"Services"))
if settings.SHOW_SIGNAGES_ON_MAP_SCREENSHOT:
maplayers.append(ugettext(u"Signages"))
if settings.SHOW_INFRASTRUCTURES_ON_MAP_SCREENSHOT:
maplayers.append(ugettext(u"Infrastructures"))
return {"maplayers": maplayers}


Path.add_property('treks', Trek.path_treks, _(u"Treks"))
Expand Down
Binary file added geotrek/trekking/static/trekking/infrastructure.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
31 changes: 31 additions & 0 deletions geotrek/trekking/static/trekking/infrastructurelayer.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
var InfrastructuresLayer = L.GeoJSON.extend({

initialize: function (infrastructuresData, options) {
options = options || {};
options.pointToLayer = this.infrastructuresMarker.bind(this);
L.GeoJSON.prototype.initialize.call(this, infrastructuresData, options);
},

infrastructuresMarker: function(featureData, latlng) {
// Label
var category = featureData.properties.type.label,
name = featureData.properties.name,
infrastructureLabel = category + '&nbsp;: ' + name;
if (name.indexOf(category) === 0) { // startswith
infrastructureLabel = name;
}

var img = L.Util.template('<img src="{SRC}" title="{TITLE}">', {
SRC: featureData.properties.type.pictogram || '/static/trekking/infrastructure.png',
TITLE: infrastructureLabel
});

var infrastructureicon = new L.DivIcon({className: 'infrastructure-marker-icon',
iconSize: [this.options.iconSize, this.options.iconSize],
html: img}),
marker = L.marker(latlng, {icon: infrastructureicon});
marker.properties = featureData.properties;

return marker;
}
});
Binary file added geotrek/trekking/static/trekking/signage.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
29 changes: 29 additions & 0 deletions geotrek/trekking/static/trekking/signagelayer.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
var SignagesLayer = L.GeoJSON.extend({

initialize: function (signagesData, options) {
options = options || {};
options.pointToLayer = this.signagesMarker.bind(this);
L.GeoJSON.prototype.initialize.call(this, signagesData, options);
},

signagesMarker: function(featureData, latlng) {
// Label
var category = featureData.properties.type.label,
name = featureData.properties.name,
serviceLabel = category + '&nbsp;: ' + name;
if (name.indexOf(category) === 0) { // startswith
serviceLabel = name;
}

var img = L.Util.template('<img src="{SRC}" title="{TITLE}">', {
SRC: featureData.properties.type.pictogram || '/static/trekking/signage.png',
TITLE: serviceLabel
});

var serviceicon = new L.DivIcon({className: 'infrastructure-marker-icon',
iconSize: [this.options.iconSize, this.options.iconSize],
html: img});

return L.marker(latlng, {icon: serviceicon}).bindLabel(featureData.properties.name, {noHide: true});
}
});
40 changes: 39 additions & 1 deletion geotrek/trekking/templates/trekking/trek_detail.html
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@
{{ block.super }}
<script src="{% static "trekking/poilayer.js" %}"></script>
<script src="{% static "trekking/servicelayer.js" %}"></script>
<script src="{% static "trekking/signagelayer.js" %}"></script>
<script src="{% static "trekking/infrastructurelayer.js" %}"></script>
<script type="text/javascript">
$(window).on('detailmap:ready', function (e, data) {
var map = data.map;
Expand Down Expand Up @@ -89,11 +91,47 @@
window.location = serviceUrl.replace('0', layer.properties.pk);
});
});
map.layerscontrol.addOverlay(services, tr('services'), tr('Objects'));
map.layerscontrol.addOverlay(services, tr('Services'), tr('Objects'));
map.addLayer(services);
$('.map-panel').addClass('services_loaded');
});

//
// Trek signage layer
$.getJSON('{% url 'infrastructure:trek_signage_geojson' LANGUAGE_CODE object.pk %}', function (data) {
var signages = new SignagesLayer(data, {
iconSize: {{ view.icon_sizes.signage }}
});

var signageUrl = "{% url 'infrastructure:signage_detail' 0 %}";
signages.eachLayer(function (layer) {
layer.on('dblclick', function (e) {
window.location = signageUrl.replace('0', layer.properties.pk);
});
});
map.layerscontrol.addOverlay(signages, tr('Signages'), tr('Objects'));
map.addLayer(signages);
$('.map-panel').addClass('signages_loaded');
});

//
// Trek infrastructure layer
$.getJSON('{% url 'infrastructure:trek_infrastructure_geojson' LANGUAGE_CODE object.pk %}', function (data) {
var infrastructures = new InfrastructuresLayer(data, {
iconSize: {{ view.icon_sizes.infrastructure }}
});

var infrastructureUrl = "{% url 'infrastructure:infrastructure_detail' 0 %}";
infrastructures.eachLayer(function (layer) {
layer.on('dblclick', function (e) {
window.location = infrastructureUrl.replace('0', layer.properties.pk);
});
});
map.layerscontrol.addOverlay(infrastructures, tr('Infrastructures'), tr('Objects'));
map.addLayer(infrastructures);
$('.map-panel').addClass('services_loaded');
});

//
// Trek information desks layer
$.getJSON('{% url 'tourism:trek_information_desk_geojson' pk=object.pk format='geojson' %}', function (data) {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{% load i18n %}

<script type="text/javascript">
MapEntity.i18n['Services'] = "{% trans "Services" %}";
</script>
2 changes: 2 additions & 0 deletions geotrek/trekking/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,8 @@ def icon_sizes(self):
return {
'POI': settings.TREK_ICON_SIZE_POI,
'service': settings.TREK_ICON_SIZE_SERVICE,
'signage': settings.TREK_ICON_SIZE_SIGNAGE,
'infrastructure': settings.TREK_ICON_SIZE_INFRASTRUCTURE,
'parking': settings.TREK_ICON_SIZE_PARKING,
'information_desk': settings.TREK_ICON_SIZE_INFORMATION_DESK
}
Expand Down

0 comments on commit 8ef1a18

Please sign in to comment.