loko/loko/common/migrations/0016_mapbackground.py

145 lines
7.3 KiB
Python

# Generated manually for dynamic MapBackgrounds
from django.db import migrations, models
def seed_map_backgrounds(apps, schema_editor):
MapBackground = apps.get_model('common', 'MapBackground')
initial_data = [
{
'identifier': 'ortho_wallonie',
'name_fr': 'Ortho Wallonie (SPW)',
'name_nl': 'Ortho Wallonië (SPW)',
'service_type': 'wms',
'url': 'https://geoservices.wallonie.be/arcgis/services/IMAGERIE/ORTHO_LAST/MapServer/WMSServer?service=WMS&version=1.3.0&request=GetMap&layers=0&styles=&format=image/jpeg&crs=EPSG:3857&bbox={bbox-epsg-3857}&width=256&height=256',
'layers': '0',
'format': 'image/jpeg',
'attribution': '© SPW - Orthophoto Wallonie',
'region': 'WAL',
'category': 'ortho',
'tile_size': 256,
'min_zoom': 0,
'max_zoom': 21,
'order': 10,
'is_active': True,
'is_default': False,
},
{
'identifier': 'urbis_ortho',
'name_fr': 'Urbis Ortho (Bruxelles)',
'name_nl': 'Urbis Ortho (Brussel)',
'service_type': 'wms',
'url': 'https://geoservices-urbis.irisnet.be/geoserver/urbisgrid/wms?service=WMS&version=1.3.0&request=GetMap&layers=Ortho&styles=&format=image/png&transparent=true&width=256&height=256&crs=EPSG:3857&bbox={bbox-epsg-3857}',
'layers': 'Ortho',
'format': 'image/png',
'attribution': '© Brussels UrbIS',
'region': 'BRU',
'category': 'ortho',
'tile_size': 256,
'min_zoom': 0,
'max_zoom': 21,
'order': 20,
'is_active': True,
'is_default': False,
},
{
'identifier': 'ortho_vlaanderen',
'name_fr': 'Ortho Vlaanderen',
'name_nl': 'Ortho Vlaanderen',
'service_type': 'wmts',
'url': 'https://geo.api.vlaanderen.be/OMW/wmts?SERVICE=WMTS&REQUEST=GetTile&VERSION=1.0.0&LAYER=omwrgb23vl&STYLE=&FORMAT=image/png&TILEMATRIXSET=GoogleMapsVL&TILEMATRIX={z}&TILEROW={y}&TILECOL={x}',
'layers': 'omwrgb23vl',
'format': 'image/png',
'attribution': '© Digitaal Vlaanderen',
'region': 'VLG',
'category': 'ortho',
'tile_size': 256,
'min_zoom': 0,
'max_zoom': 21,
'order': 30,
'is_active': True,
'is_default': False,
},
{
'identifier': 'plan_wallonie_spw',
'name_fr': 'Plan de base Wallonie (SPW)',
'name_nl': 'Basiskaart Wallonië (SPW)',
'service_type': 'arcgis_rest',
'url': 'https://geoservices.wallonie.be/arcgis/rest/services/DONNEES_BASE/FDC_SPW/MapServer/export?bbox={bbox-epsg-3857}&bboxSR=3857&imageSR=3857&size=256,256&format=png&f=image',
'layers': '',
'format': 'image/png',
'attribution': '© SPW - Fond de plan Wallonie',
'region': 'WAL',
'category': 'plan',
'tile_size': 256,
'min_zoom': 0,
'max_zoom': 21,
'order': 40,
'is_active': True,
'is_default': False,
},
{
'identifier': 'plan_leger_wallonie_spw',
'name_fr': 'Plan léger Wallonie (SPW)',
'name_nl': 'Lichte basiskaart Wallonië (SPW)',
'service_type': 'arcgis_rest',
'url': 'https://geoservices.wallonie.be/arcgis/rest/services/DONNEES_BASE/FDC_SPW_LEGER/MapServer/export?bbox={bbox-epsg-3857}&bboxSR=3857&imageSR=3857&size=256,256&format=png&f=image',
'layers': '',
'format': 'image/png',
'attribution': '© SPW - Fond de plan léger',
'region': 'WAL',
'category': 'plan',
'tile_size': 256,
'min_zoom': 0,
'max_zoom': 21,
'order': 50,
'is_active': True,
'is_default': False,
},
]
for item in initial_data:
MapBackground.objects.get_or_create(identifier=item['identifier'], defaults=item)
def rollback_seed(apps, schema_editor):
MapBackground = apps.get_model('common', 'MapBackground')
MapBackground.objects.filter(identifier__in=[
'ortho_wallonie', 'urbis_ortho', 'ortho_vlaanderen', 'plan_wallonie_spw', 'plan_leger_wallonie_spw'
]).delete()
class Migration(migrations.Migration):
dependencies = [
('common', '0015_remove_obsolete_schools_appview'),
]
operations = [
migrations.CreateModel(
name='MapBackground',
fields=[
('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('identifier', models.SlugField(help_text='Ex: urbis_ortho, ortho_vlaanderen, ortho_wallonie', unique=True, verbose_name='Identifiant unique')),
('name_fr', models.CharField(max_length=150, verbose_name='Nom FR')),
('name_nl', models.CharField(max_length=150, verbose_name='Nom NL')),
('service_type', models.CharField(choices=[('wms', 'WMS (Web Map Service)'), ('wmts', 'WMTS (Web Map Tile Service)'), ('xyz', 'XYZ / Tuiles standard'), ('arcgis_rest', 'ArcGIS REST Export')], default='wms', max_length=20, verbose_name='Type de service')),
('url', models.TextField(help_text='Supporte {bbox-epsg-3857} pour WMS/Export, et {z}/{x}/{y} pour WMTS/XYZ.', verbose_name='URL du flux')),
('layers', models.CharField(blank=True, help_text='Nom de couche WMS si applicable (ex: Ortho, 0, ORTHO_LAST)', max_length=255, verbose_name='Couche(s)')),
('format', models.CharField(default='image/jpeg', help_text='ex: image/jpeg, image/png', max_length=50, verbose_name="Format d'image")),
('attribution', models.CharField(blank=True, help_text='ex: © SPW - Orthophoto Wallonie', max_length=255, verbose_name='Attribution / Copyright')),
('region', models.CharField(choices=[('ALL', 'Toutes régions (National / Global)'), ('BRU', 'Bruxelles (StreetUp)'), ('WAL', 'Wallonie'), ('VLG', 'Flandre')], default='ALL', max_length=10, verbose_name='Région')),
('category', models.CharField(choices=[('ortho', 'Orthophoto / Vue aérienne'), ('plan', 'Plan de base / Topographique'), ('cadastre', 'Cadastre / Parcellaire'), ('other', 'Autre')], default='ortho', max_length=20, verbose_name='Catégorie')),
('tile_size', models.PositiveIntegerField(default=256, verbose_name='Taille des tuiles (px)')),
('min_zoom', models.PositiveIntegerField(default=0, verbose_name='Zoom minimum')),
('max_zoom', models.PositiveIntegerField(default=21, verbose_name='Zoom maximum')),
('order', models.PositiveIntegerField(default=0, verbose_name="Ordre d'affichage")),
('is_active', models.BooleanField(default=True, verbose_name='Actif')),
('is_default', models.BooleanField(default=False, verbose_name='Sélectionné par défaut')),
],
options={
'verbose_name': 'Fond de plan',
'verbose_name_plural': 'Fonds de plan',
'ordering': ['order', 'name_fr'],
},
),
migrations.RunPython(seed_map_backgrounds, rollback_seed),
]