Skip to content

Commit

Permalink
fix corrispondenza tra finestra sx e dx e le versioni
Browse files Browse the repository at this point in the history
  • Loading branch information
enricofer committed Jun 13, 2024
1 parent c3c7a21 commit 57ff016
Show file tree
Hide file tree
Showing 7 changed files with 85 additions and 16 deletions.
5 changes: 3 additions & 2 deletions webapp/djakart/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
from datetime import datetime
import xml.etree.ElementTree as ET

from .models import version, can_modify, modelli
from .models import version, can_modify, modelli, basemap
from .kart_api import (
crea_nuova_versione,
elimina_versione,
Expand Down Expand Up @@ -534,4 +534,5 @@ def esporta_gdb(self, request, obj):


admin.site.register(version, versioniAdmin)
admin.site.register(modelli)
admin.site.register(modelli)
admin.site.register(basemap)
28 changes: 28 additions & 0 deletions webapp/djakart/migrations/0002_basemap.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
# Generated by Django 5.0.6 on 2024-06-13 15:57

from django.db import migrations, models


class Migration(migrations.Migration):

dependencies = [
('djakart', '0001_initial'),
]

operations = [
migrations.CreateModel(
name='basemap',
fields=[
('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('name', models.CharField(max_length=20)),
('oltype', models.CharField(choices=[('WMS', 'WMS'), ('WMS', 'XYZ')], default='WMS', max_length=4)),
('url', models.CharField(max_length=200)),
('service_params', models.JSONField(blank=True, default={}, null=True)),
('request_params', models.JSONField(blank=True, default={'CRS': 'EPSG:3003', 'DPI': 150, 'LAYERS': ''}, null=True)),
],
options={
'verbose_name': 'Basemap',
'verbose_name_plural': 'Basemaps',
},
),
]
31 changes: 28 additions & 3 deletions webapp/djakart/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -474,6 +474,7 @@ class basemap(models.Model):

REQUEST_PARAMS_DEFAULT = {
"CRS": SRID,
"DPI": 150,
"LAYERS": ""
}

Expand All @@ -482,7 +483,31 @@ class Meta:
verbose_name = "Basemap"

name = models.CharField(max_length=20)
oltype = models.CharField(max_length=4, choices=OLTYPE_CHOICES)
oltype = models.CharField(max_length=4, choices=OLTYPE_CHOICES, default="WMS")
url = models.CharField(max_length=200)
service_params = JSONField(default={},blank=True, null=True)
request_params = JSONField(default={"LAYERS":{}},blank=True, null=True)
service_params = JSONField(default=SERVICE_PARAMS_DEFAULT,blank=True, null=True)
request_params = JSONField(default=REQUEST_PARAMS_DEFAULT,blank=True, null=True)

def __str__(self):
return self.name

@property
def oldef(self):
lyr_template = """
new ol.layer.Tile({
title: '%s',
basemap: true,
source: new ol.source.TileWMS({
url: '%s',
params: %s,
projection: '%s'
})
})"""

return lyr_template % (
self.name,
self.url,
str(self.request_params),
SRID,
)

17 changes: 11 additions & 6 deletions webapp/djakart/static/djakart/versioni_finestramappa.js
Original file line number Diff line number Diff line change
Expand Up @@ -339,8 +339,13 @@ function loadFinestraMappa( polyWKT) {
}
}

let lyrssx = getLyrs()
let lyrsdx = getLyrs()
let lyrs = [currentOverlay, versionOverlay].concat(lyrssx).concat(lyrsdx)
console.log("lyrs", lyrs)

map_glob = new ol.Map({
layers: [currentOverlay, dbtOverlaySx, polyOverlaysx, versionOverlay, dbtOverlayDx ,polyOverlaydx ],
layers: lyrs,
controls: ol.control.defaults({
attribution: false
}).extend([
Expand Down Expand Up @@ -371,20 +376,20 @@ function loadFinestraMappa( polyWKT) {

var currentOverlaySX_control = new comboversioni(versioni_wms,1,"SX")
if (base_wms == "") {
currentOverlaySX_control = new comboversioni([versioni_wms[1]],0,"SX")
currentOverlaySX_control = new comboversioni([versioni_wms[1]],1,"SX")
}
map_glob.addControl(currentOverlaySX_control);
var currentOverlayDX_control = new comboversioni(versioni_wms,0,"DX")
map_glob.addControl(currentOverlayDX_control);

// Set stamen on left
ctrl.addLayer(currentOverlay);
ctrl.addLayer(dbtOverlaySx);
ctrl.addLayer(polyOverlaysx);
ctrl.addLayer(lyrssx[0]);
ctrl.addLayer(lyrssx[1]);
// OSM on right
ctrl.addLayer(versionOverlay, true);
ctrl.addLayer(dbtOverlayDx, true);
ctrl.addLayer(polyOverlaydx, true);
ctrl.addLayer(lyrsdx[0], true);
ctrl.addLayer(lyrsdx[1], true);

map_glob.getView().on('propertychange', function(e) {
switch (e.key) {
Expand Down
8 changes: 4 additions & 4 deletions webapp/djakart/templates/admin/djakart/change_form.html
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<link rel="stylesheet" href="https://rawgit.com/walkermatt/ol3-layerswitcher/master/src/ol3-layerswitcher.css" />
<link rel="stylesheet" href="https://cdn.rawgit.com/Viglino/ol-ext/master/dist/ol-ext.min.css" />
<!-- URB PD -->
<link rel="stylesheet" href="/static/djakart/versioni_finestramappa.css?id=12323300233" />
<link rel="stylesheet" href="/static/djakart/versioni_finestramappa.css?id=123236600233" />
<script
src="https://code.jquery.com/jquery-3.7.1.slim.min.js"
integrity="sha256-kmHvs0B+OpCW5GVHUNjv9rOmY0IvSIRcf7zGUDTDQM8="
Expand All @@ -17,10 +17,10 @@
<script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/proj4js/2.2.1/proj4.js"></script>
<!-- DJAKART -->
<script type="text/javascript" src="https://epsg.io/{{ crs }}.js"></script>
<script type="text/javascript">var CRSID = "EPSG:{{ crs }}"; var CRSCODE = {{ code }};</script>
<script type="text/javascript">var CRSID = "EPSG:{{ crs }}"; var CRSCODE = {{ crs }};</script>
<script type="text/javascript" src="/djakart/basemaps/"></script>
<script type="text/javascript" src="/djakart/vlist/{{ object_id }}/"></script>
<script type="text/javascript" src="/static/djakart/versioni_finestramappa.js?id=5593470634"></script>
<script type="text/javascript" src="/static/repertorio/mappeDiBase.js?id=23909384485"></script>
<script type="text/javascript" src="/static/djakart/versioni_finestramappa.js?id=811423452"></script>
<script type="text/javascript" src="/static/admin/js/calendar.js"></script>
<script type="text/javascript" src="/static/admin/js/admin/DateTimeShortcuts.js"></script>
<script type="text/javascript">
Expand Down
1 change: 1 addition & 0 deletions webapp/djakart/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
re_path(r'^vlist/(\d+)/$', views.vlist, name='vlist'),
re_path(r'^show/(\w+)/$', views.show, name='status'),
re_path(r'^qgs/(\w+)/$', views.QGS_progetto, name='qgs'),
re_path(r'^basemaps/$', views.basemaps_js, name='basemaps'),
re_path(r'^diff-view/(\w+)/$', views.diff_view, name='diffview'),
re_path(r'^diff\/(?P<versione>\w+)\/(?P<hash>\w+)\/((?P<parent_hash>\w+)?\/)?$', views.diff, name='diff'),
#url(r'^diff/(?P<versione>\w+)/(?P<parent_hash>\w+)/(?P<parent_hash>\w+)/$', views.diff, name='diff'),
Expand Down
11 changes: 10 additions & 1 deletion webapp/djakart/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
from django.conf import settings
from django.contrib.auth.decorators import login_required, user_passes_test, permission_required

from .models import version, writeQgs
from .models import version, writeQgs,basemap

from .kart_api import (
log_versione,
Expand Down Expand Up @@ -76,6 +76,15 @@ def QGS_progetto(request,versione):
response['Content-Disposition'] = 'attachment; filename="%s.qgs"' % versione
return response

def basemaps_js(request):
lyrsdef = "function getLyrs() {return ["
for bm in basemap.objects.all():
lyrsdef += bm.oldef
lyrsdef += ',\n'
lyrsdef += ']}\n'
return HttpResponse(lyrsdef, content_type="text/javascript; charset=utf-8")


def vlist(request,versione_id):
obj = version.objects.get(pk=versione_id)
if obj.pk:
Expand Down

0 comments on commit 57ff016

Please sign in to comment.