diff --git a/src/c3nav/editor/forms.py b/src/c3nav/editor/forms.py index 984b9377..fa002845 100644 --- a/src/c3nav/editor/forms.py +++ b/src/c3nav/editor/forms.py @@ -268,6 +268,7 @@ class EditorFormBase(I18nModelFormMixin, ModelForm): def create_editor_form(editor_model): possible_fields = ['slug', 'name', 'title', 'title_plural', 'help_text', 'icon', 'join_edges', 'up_separate', 'walk', 'ordering', 'category', 'width', 'groups', 'color', 'priority', 'hierarchy', 'icon_name', + 'show_labels', 'show_label', 'base_altitude', 'waytype', 'access_restriction', 'height', 'default_height', 'door_height', 'outside', 'can_search', 'can_describe', 'geometry', 'single', 'altitude', 'short_label', 'origin_space', 'target_space', 'data', 'comment', 'slow_down_factor', diff --git a/src/c3nav/mapdata/migrations/0074_show_labels.py b/src/c3nav/mapdata/migrations/0074_show_labels.py new file mode 100644 index 00000000..8721a25d --- /dev/null +++ b/src/c3nav/mapdata/migrations/0074_show_labels.py @@ -0,0 +1,38 @@ +# Generated by Django 2.2.8 on 2019-12-21 21:47 + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('mapdata', '0073_locationgroup_hierarchy'), + ] + + operations = [ + migrations.AddField( + model_name='area', + name='show_label', + field=models.CharField(choices=[('inherit', 'inherit from groups (default)'), ('show_text', 'yes, show the title'), ('no', "don't show")], default='inherit', max_length=16, verbose_name='show label'), + ), + migrations.AddField( + model_name='level', + name='show_label', + field=models.CharField(choices=[('inherit', 'inherit from groups (default)'), ('show_text', 'yes, show the title'), ('no', "don't show")], default='inherit', max_length=16, verbose_name='show label'), + ), + migrations.AddField( + model_name='locationgroup', + name='show_labels', + field=models.CharField(choices=[('no', 'no (default)'), ('show_text', 'yes, show the title')], default='no', help_text='unless location specifies otherwise', max_length=16, verbose_name='show labels'), + ), + migrations.AddField( + model_name='poi', + name='show_label', + field=models.CharField(choices=[('inherit', 'inherit from groups (default)'), ('show_text', 'yes, show the title'), ('no', "don't show")], default='inherit', max_length=16, verbose_name='show label'), + ), + migrations.AddField( + model_name='space', + name='show_label', + field=models.CharField(choices=[('inherit', 'inherit from groups (default)'), ('show_text', 'yes, show the title'), ('no', "don't show")], default='inherit', max_length=16, verbose_name='show label'), + ), + ] diff --git a/src/c3nav/mapdata/models/locations.py b/src/c3nav/mapdata/models/locations.py index 2d430aef..ec4567b5 100644 --- a/src/c3nav/mapdata/models/locations.py +++ b/src/c3nav/mapdata/models/locations.py @@ -103,7 +103,7 @@ class Location(LocationSlug, AccessRestrictionMixin, TitledMixin, models.Model): result = super().serialize(detailed=detailed, **kwargs) if not detailed: fields = ('id', 'type', 'slug', 'title', 'subtitle', 'icon', 'point', 'bounds', 'grid_square', - 'locations', 'on_top_of') + 'locations', 'on_top_of', 'show_label') result = {name: result[name] for name in fields if name in result} return result @@ -158,7 +158,14 @@ class Location(LocationSlug, AccessRestrictionMixin, TitledMixin, models.Model): class SpecificLocation(Location, models.Model): + SHOW_LABEL_OPTIONS = ( + ('inherit', _('inherit from groups (default)')), + ('show_text', _('yes, show the title')), + ('no', _('don\'t show')), + ) + groups = models.ManyToManyField('mapdata.LocationGroup', verbose_name=_('Location Groups'), blank=True) + show_label = models.CharField(_('show label'), max_length=16, default='inherit', choices=SHOW_LABEL_OPTIONS) class Meta: abstract = True @@ -177,8 +184,19 @@ class SpecificLocation(Location, models.Model): for category, items in groups.items() if getattr(category, 'allow_'+self.__class__._meta.default_related_name)} result['groups'] = groups + result['show_label'] = self.get_show_label() return result + def get_show_label(self): + if self.show_label == 'inherit': + for group in self.groups.all(): + if group.show_labels != 'no': + return group.show_labels + return None + if self.show_label == 'no': + return None + return self.show_label + def details_display(self, **kwargs): result = super().details_display(**kwargs) @@ -286,10 +304,17 @@ class LocationGroupManager(models.Manager): class LocationGroup(Location, models.Model): + SHOW_LABELS_OPTIONS = ( + ('no', _('no (default)')), + ('show_text', _('yes, show the title')), + ) + category = models.ForeignKey(LocationGroupCategory, related_name='groups', on_delete=models.PROTECT, verbose_name=_('Category')) priority = models.IntegerField(default=0, db_index=True) hierarchy = models.IntegerField(default=0, db_index=True, verbose_name=_('hierarchy')) + show_labels = models.CharField(_('show labels'), max_length=16, default='no', choices=SHOW_LABELS_OPTIONS, + help_text=_('unless location specifies otherwise')) color = models.CharField(null=True, blank=True, max_length=32, verbose_name=_('background color')) objects = LocationGroupManager() diff --git a/src/c3nav/site/static/site/js/c3nav.js b/src/c3nav/site/static/site/js/c3nav.js index 04a5d60d..fe3829ce 100644 --- a/src/c3nav/site/static/site/js/c3nav.js +++ b/src/c3nav/site/static/site/js/c3nav.js @@ -108,7 +108,7 @@ c3nav = { location.match = ' ' + location.title_words.join(' ') + ' ' + location.subtitle_words.join(' ') + ' ' + location.slug; locations.push(location); locations_by_id[location.id] = location; - if (location.point ) { + if (location.point && location.show_label) { location.label = c3nav._build_location_label(location); if (!(location.point[0] in labels)) labels[location.point[0]] = []; labels[location.point[0]].push(location); @@ -302,10 +302,14 @@ c3nav = { update_location_labels: function() { c3nav._labelLayer.clearLayers(); - var labels = c3nav.labels[c3nav._levelControl.currentLevel]; + var labels = c3nav.labels[c3nav._levelControl.currentLevel], + bounds = c3nav.map.getBounds(); if (!labels) return; + for (var location of labels) { - c3nav._labelLayer._maybeAddLayerToRBush(location.label); + if (bounds.contains(location.label.getLatLng())) { + c3nav._labelLayer._maybeAddLayerToRBush(location.label); + } } },