show_label logic
This commit is contained in:
parent
49317c13c2
commit
fcf8867cbf
4 changed files with 72 additions and 4 deletions
|
@ -268,6 +268,7 @@ class EditorFormBase(I18nModelFormMixin, ModelForm):
|
||||||
def create_editor_form(editor_model):
|
def create_editor_form(editor_model):
|
||||||
possible_fields = ['slug', 'name', 'title', 'title_plural', 'help_text', 'icon', 'join_edges', 'up_separate',
|
possible_fields = ['slug', 'name', 'title', 'title_plural', 'help_text', 'icon', 'join_edges', 'up_separate',
|
||||||
'walk', 'ordering', 'category', 'width', 'groups', 'color', 'priority', 'hierarchy', 'icon_name',
|
'walk', 'ordering', 'category', 'width', 'groups', 'color', 'priority', 'hierarchy', 'icon_name',
|
||||||
|
'show_labels', 'show_label',
|
||||||
'base_altitude', 'waytype', 'access_restriction', 'height', 'default_height', 'door_height',
|
'base_altitude', 'waytype', 'access_restriction', 'height', 'default_height', 'door_height',
|
||||||
'outside', 'can_search', 'can_describe', 'geometry', 'single', 'altitude', 'short_label',
|
'outside', 'can_search', 'can_describe', 'geometry', 'single', 'altitude', 'short_label',
|
||||||
'origin_space', 'target_space', 'data', 'comment', 'slow_down_factor',
|
'origin_space', 'target_space', 'data', 'comment', 'slow_down_factor',
|
||||||
|
|
38
src/c3nav/mapdata/migrations/0074_show_labels.py
Normal file
38
src/c3nav/mapdata/migrations/0074_show_labels.py
Normal file
|
@ -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'),
|
||||||
|
),
|
||||||
|
]
|
|
@ -103,7 +103,7 @@ class Location(LocationSlug, AccessRestrictionMixin, TitledMixin, models.Model):
|
||||||
result = super().serialize(detailed=detailed, **kwargs)
|
result = super().serialize(detailed=detailed, **kwargs)
|
||||||
if not detailed:
|
if not detailed:
|
||||||
fields = ('id', 'type', 'slug', 'title', 'subtitle', 'icon', 'point', 'bounds', 'grid_square',
|
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}
|
result = {name: result[name] for name in fields if name in result}
|
||||||
return result
|
return result
|
||||||
|
|
||||||
|
@ -158,7 +158,14 @@ class Location(LocationSlug, AccessRestrictionMixin, TitledMixin, models.Model):
|
||||||
|
|
||||||
|
|
||||||
class SpecificLocation(Location, 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)
|
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:
|
class Meta:
|
||||||
abstract = True
|
abstract = True
|
||||||
|
@ -177,8 +184,19 @@ class SpecificLocation(Location, models.Model):
|
||||||
for category, items in groups.items()
|
for category, items in groups.items()
|
||||||
if getattr(category, 'allow_'+self.__class__._meta.default_related_name)}
|
if getattr(category, 'allow_'+self.__class__._meta.default_related_name)}
|
||||||
result['groups'] = groups
|
result['groups'] = groups
|
||||||
|
result['show_label'] = self.get_show_label()
|
||||||
return result
|
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):
|
def details_display(self, **kwargs):
|
||||||
result = super().details_display(**kwargs)
|
result = super().details_display(**kwargs)
|
||||||
|
|
||||||
|
@ -286,10 +304,17 @@ class LocationGroupManager(models.Manager):
|
||||||
|
|
||||||
|
|
||||||
class LocationGroup(Location, models.Model):
|
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,
|
category = models.ForeignKey(LocationGroupCategory, related_name='groups', on_delete=models.PROTECT,
|
||||||
verbose_name=_('Category'))
|
verbose_name=_('Category'))
|
||||||
priority = models.IntegerField(default=0, db_index=True)
|
priority = models.IntegerField(default=0, db_index=True)
|
||||||
hierarchy = models.IntegerField(default=0, db_index=True, verbose_name=_('hierarchy'))
|
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'))
|
color = models.CharField(null=True, blank=True, max_length=32, verbose_name=_('background color'))
|
||||||
|
|
||||||
objects = LocationGroupManager()
|
objects = LocationGroupManager()
|
||||||
|
|
|
@ -108,7 +108,7 @@ c3nav = {
|
||||||
location.match = ' ' + location.title_words.join(' ') + ' ' + location.subtitle_words.join(' ') + ' ' + location.slug;
|
location.match = ' ' + location.title_words.join(' ') + ' ' + location.subtitle_words.join(' ') + ' ' + location.slug;
|
||||||
locations.push(location);
|
locations.push(location);
|
||||||
locations_by_id[location.id] = location;
|
locations_by_id[location.id] = location;
|
||||||
if (location.point ) {
|
if (location.point && location.show_label) {
|
||||||
location.label = c3nav._build_location_label(location);
|
location.label = c3nav._build_location_label(location);
|
||||||
if (!(location.point[0] in labels)) labels[location.point[0]] = [];
|
if (!(location.point[0] in labels)) labels[location.point[0]] = [];
|
||||||
labels[location.point[0]].push(location);
|
labels[location.point[0]].push(location);
|
||||||
|
@ -302,10 +302,14 @@ c3nav = {
|
||||||
|
|
||||||
update_location_labels: function() {
|
update_location_labels: function() {
|
||||||
c3nav._labelLayer.clearLayers();
|
c3nav._labelLayer.clearLayers();
|
||||||
var labels = c3nav.labels[c3nav._levelControl.currentLevel];
|
var labels = c3nav.labels[c3nav._levelControl.currentLevel],
|
||||||
|
bounds = c3nav.map.getBounds();
|
||||||
if (!labels) return;
|
if (!labels) return;
|
||||||
|
|
||||||
for (var location of labels) {
|
for (var location of labels) {
|
||||||
c3nav._labelLayer._maybeAddLayerToRBush(location.label);
|
if (bounds.contains(location.label.getLatLng())) {
|
||||||
|
c3nav._labelLayer._maybeAddLayerToRBush(location.label);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue