colored obstacles – the future is (almost) here!

This commit is contained in:
Laura Klünder 2019-12-22 19:28:55 +01:00
parent 80abc62825
commit eed1856353
4 changed files with 73 additions and 4 deletions

View file

@ -306,8 +306,8 @@ class EditorViewSet(EditorViewSetMixin, ViewSet):
space.holes.all().only('geometry', 'space'),
space.stairs.all().only('geometry', 'space'),
space.ramps.all().only('geometry', 'space'),
space.obstacles.all().only('geometry', 'space'),
space.lineobstacles.all().only('geometry', 'width', 'space'),
space.obstacles.all().only('geometry', 'space', 'color'),
space.lineobstacles.all().only('geometry', 'width', 'space', 'color'),
space.columns.all().only('geometry', 'space'),
space.altitudemarkers.all().only('geometry', 'space'),
space.wifi_measurements.all().only('geometry', 'space'),

View file

@ -278,8 +278,8 @@ 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',
'base_altitude', 'waytype', 'access_restriction', 'height', 'default_height', 'door_height',
'walk', 'ordering', 'category', 'width', 'groups', 'height', 'color', 'priority', 'hierarchy',
'icon_name', 'base_altitude', 'waytype', 'access_restriction', 'default_height', 'door_height',
'outside', 'can_search', 'can_describe', 'geometry', 'single', 'altitude', 'short_label',
'origin_space', 'target_space', 'data', 'comment', 'slow_down_factor',
'extra_seconds', 'speed', 'description', 'speed_up', 'description_up', 'enter_description',

View file

@ -0,0 +1,53 @@
# Generated by Django 2.2.8 on 2019-12-22 18:12
from django.db import migrations, models
import django.db.models.deletion
class Migration(migrations.Migration):
dependencies = [
('mapdata', '0075_label_settings'),
]
operations = [
migrations.AlterModelOptions(
name='labelsettings',
options={'default_related_name': 'labelsettings', 'ordering': ('min_zoom', '-font_size'), 'verbose_name': 'Label Settings', 'verbose_name_plural': 'Label Settings'},
),
migrations.AddField(
model_name='lineobstacle',
name='color',
field=models.CharField(blank=True, max_length=32, null=True, verbose_name='color (optional)'),
),
migrations.AddField(
model_name='obstacle',
name='color',
field=models.CharField(blank=True, max_length=32, null=True, verbose_name='color (optional)'),
),
migrations.AlterField(
model_name='area',
name='label_settings',
field=models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.PROTECT, related_name='areas', to='mapdata.LabelSettings', verbose_name='label settings'),
),
migrations.AlterField(
model_name='level',
name='label_settings',
field=models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.PROTECT, related_name='levels', to='mapdata.LabelSettings', verbose_name='label settings'),
),
migrations.AlterField(
model_name='locationgroup',
name='label_settings',
field=models.ForeignKey(blank=True, help_text='unless location specifies otherwise', null=True, on_delete=django.db.models.deletion.PROTECT, related_name='locationgroups', to='mapdata.LabelSettings', verbose_name='label settings'),
),
migrations.AlterField(
model_name='poi',
name='label_settings',
field=models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.PROTECT, related_name='pois', to='mapdata.LabelSettings', verbose_name='label settings'),
),
migrations.AlterField(
model_name='space',
name='label_settings',
field=models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.PROTECT, related_name='spaces', to='mapdata.LabelSettings', verbose_name='label settings'),
),
]

View file

@ -170,15 +170,23 @@ class Obstacle(SpaceGeometryMixin, models.Model):
geometry = GeometryField('polygon')
height = models.DecimalField(_('height'), max_digits=6, decimal_places=2, default=0.8,
validators=[MinValueValidator(Decimal('0'))])
color = models.CharField(null=True, blank=True, max_length=32, verbose_name=_('color (optional)'))
class Meta:
verbose_name = _('Obstacle')
verbose_name_plural = _('Obstacles')
default_related_name = 'obstacles'
def get_geojson_properties(self, *args, instance=None, **kwargs) -> dict:
result = super().get_geojson_properties(*args, **kwargs)
if self.color:
result['color'] = self.color
return result
def _serialize(self, geometry=True, **kwargs):
result = super()._serialize(geometry=geometry, **kwargs)
result['height'] = float(str(self.height))
result['color'] = self.color
return result
@ -190,16 +198,24 @@ class LineObstacle(SpaceGeometryMixin, models.Model):
width = models.DecimalField(_('width'), max_digits=4, decimal_places=2, default=0.15)
height = models.DecimalField(_('height'), max_digits=6, decimal_places=2, default=0.8,
validators=[MinValueValidator(Decimal('0'))])
color = models.CharField(null=True, blank=True, max_length=32, verbose_name=_('color (optional)'))
class Meta:
verbose_name = _('Line Obstacle')
verbose_name_plural = _('Line Obstacles')
default_related_name = 'lineobstacles'
def get_geojson_properties(self, *args, instance=None, **kwargs) -> dict:
result = super().get_geojson_properties(*args, **kwargs)
if self.color:
result['color'] = self.color
return result
def _serialize(self, geometry=True, **kwargs):
result = super()._serialize(geometry=geometry, **kwargs)
result['width'] = float(str(self.width))
result['height'] = float(str(self.height))
result['color'] = self.color
if geometry:
result['buffered_geometry'] = format_geojson(mapping(self.buffered_geometry))
return result