test/apps/main/models/model_static_layer.py
2025-03-03 12:28:12 +07:00

65 lines
2.1 KiB
Python
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

from django.db import models
def get_style_template() -> dict:
return {
# Заливка
'fill-color': 'rgba(255, 0, 0, 0.5)',
'fill-opacity': 1,
# Линия
'stroke-color': 'blue',
'stroke-width': 2,
'stroke-opacity': 1,
# # Круг (для точек. Потом на иконки заменить)
# 'circle-radius': 10,
# 'circle-fill-color': 'green',
# 'circle-stroke-color': 'black',
# 'circle-stroke-width': 1,
#
# # Текст
# 'text-value': 'Hello, OpenLayers!',
# 'text-font': '14px Calibri,sans-serif',
# 'text-color': 'white',
# 'text-offset-x': 0,
# 'text-offset-y': -20,
# 'text-align': 'center',
# 'text-baseline': 'middle',
}
class StaticLayer(models.Model):
"""
Модель слоев
Типы слоев: Tile (плитки), Vector (точки, линии, полигоны)
"""
name = models.CharField(max_length=255, verbose_name="Название слоя")
file = models.FileField(
upload_to="layers/", verbose_name="Файл слоя", null=True, blank=True
)
url = models.CharField(
max_length=255,
blank=True,
null=True,
verbose_name="Каталог (для растровых слоев)",
)
layer_type = models.CharField(
max_length=50, verbose_name="Тип слоя", default="Vector"
)
is_visible = models.BooleanField(default=True,
verbose_name="Видимость слоя")
layer_style = models.JSONField(blank=True, null=True,
default=get_style_template)
order = models.IntegerField(default=0, verbose_name="Порядок отображения")
def __str__(self):
return self.name
class Meta: # отображение в админики
verbose_name = "Статический слой"
verbose_name_plural = "Статические слои"
indexes = [models.Index(fields=["name"]),
models.Index(fields=["is_visible"])]