Skip to content
Permalink
Browse files

Merge pull request #38332 from elpaso/server-landingpage-initial-extent

Server landingpage initial extent
  • Loading branch information
elpaso committed Aug 18, 2020
2 parents 29de71d + 01e7508 commit 6712278a42b0e665562abb6dcef746345a6f3fcb

This file was deleted.

@@ -1 +1 @@
<!DOCTYPE html><html lang=en><head><meta charset=utf-8><meta http-equiv=X-UA-Compatible content="IE=edge"><meta name=viewport content="width=device-width,initial-scale=1,shrink-to-fit=no"><link rel=icon href=/favicon.ico><title>app</title><link rel=stylesheet href="https://fonts.googleapis.com/css?family=Roboto:100,300,400,500,700,900"><link rel=stylesheet href=https://cdn.jsdelivr.net/npm/@mdi/font@latest/css/materialdesignicons.min.css><link href=/css/chunk-123bc409.8679d8ba.css rel=prefetch><link href=/css/chunk-144cd10c.61ac68ab.css rel=prefetch><link href=/css/chunk-4bb3b66a.82255eb1.css rel=prefetch><link href=/js/chunk-123bc409.ef3c4d35.js rel=prefetch><link href=/js/chunk-144cd10c.517e8bc2.js rel=prefetch><link href=/js/chunk-4bb3b66a.7a48f55d.js rel=prefetch><link href=/css/app.ca3f5643.css rel=preload as=style><link href=/css/chunk-vendors.a728f495.css rel=preload as=style><link href=/js/app.ca7d8a76.js rel=preload as=script><link href=/js/chunk-vendors.ebebb286.js rel=preload as=script><link href=/css/chunk-vendors.a728f495.css rel=stylesheet><link href=/css/app.ca3f5643.css rel=stylesheet></head><body><noscript><strong>We're sorry but app doesn't work properly without JavaScript enabled. Please enable it to continue.</strong></noscript><div id=app></div><script src=/js/chunk-vendors.ebebb286.js></script><script src=/js/app.ca7d8a76.js></script></body></html>
<!DOCTYPE html><html lang=en><head><meta charset=utf-8><meta http-equiv=X-UA-Compatible content="IE=edge"><meta name=viewport content="width=device-width,initial-scale=1,shrink-to-fit=no"><link rel=icon href=/favicon.ico><title>app</title><link rel=stylesheet href="https://fonts.googleapis.com/css?family=Roboto:100,300,400,500,700,900"><link rel=stylesheet href=https://cdn.jsdelivr.net/npm/@mdi/font@latest/css/materialdesignicons.min.css><link href=/css/chunk-123bc409.8679d8ba.css rel=prefetch><link href=/css/chunk-144cd10c.61ac68ab.css rel=prefetch><link href=/css/chunk-fd085c1c.a76e3223.css rel=prefetch><link href=/js/chunk-123bc409.ef3c4d35.js rel=prefetch><link href=/js/chunk-144cd10c.517e8bc2.js rel=prefetch><link href=/js/chunk-fd085c1c.83a1da86.js rel=prefetch><link href=/css/app.ca3f5643.css rel=preload as=style><link href=/css/chunk-vendors.a728f495.css rel=preload as=style><link href=/js/app.e63a21da.js rel=preload as=script><link href=/js/chunk-vendors.ebebb286.js rel=preload as=script><link href=/css/chunk-vendors.a728f495.css rel=stylesheet><link href=/css/app.ca3f5643.css rel=stylesheet></head><body><noscript><strong>We're sorry but app doesn't work properly without JavaScript enabled. Please enable it to continue.</strong></noscript><div id=app></div><script src=/js/chunk-vendors.ebebb286.js></script><script src=/js/app.e63a21da.js></script></body></html>

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

@@ -17,6 +17,8 @@
#include "qgsapplication.h"
#include "qgsprojectstorageregistry.h"
#include "qgsprojectstorage.h"
#include "qgsprojectviewsettings.h"
#include "qgsreferencedgeometry.h"
#include "qgslandingpageutils.h"
#include "qgsserverprojectutils.h"
#include "qgsmessagelog.h"
@@ -27,6 +29,7 @@
#include <mutex>
#include <QCryptographicHash>
#include <QFileSystemWatcher>
#include <QDomDocument>

const QRegularExpression QgsLandingPageUtils::PROJECT_HASH_RE { QStringLiteral( "/(?<projectHash>[a-f0-9]{32})" ) };
QMap<QString, QString> QgsLandingPageUtils::AVAILABLE_PROJECTS;
@@ -222,6 +225,55 @@ json QgsLandingPageUtils::projectInfo( const QString &projectUri )
json info = json::object();
info[ "id" ] = QCryptographicHash::hash( projectUri.toUtf8(), QCryptographicHash::Md5 ).toHex();
QgsProject p;

// Initial extent for map display, in 4326 CRS.
// Check view settings first, read map canvas extent from XML if it's not set
QgsProjectViewSettings *viewSettings { p.viewSettings() };
if ( viewSettings && ! viewSettings->defaultViewExtent().isEmpty() )
{
QgsRectangle extent { viewSettings->defaultViewExtent() };
// Need conversion?
if ( viewSettings->defaultViewExtent().crs().authid() != 4326 )
{
QgsCoordinateTransform ct { p.crs(), QgsCoordinateReferenceSystem::fromEpsgId( 4326 ), p.transformContext() };
extent = ct.transform( extent );
}
info[ "initial_extent" ] = json::array( { extent.xMinimum(), extent.yMinimum(), extent.xMaximum(), extent.yMaximum() } );
}
else // Read initial extent from map canvas
{
QObject::connect( &p, &QgsProject::readProject, qApp, [ & ]( const QDomDocument & projectDoc )
{
const QDomNodeList canvasElements { projectDoc.elementsByTagName( QStringLiteral( "mapcanvas" ) ) };
if ( ! canvasElements.isEmpty() )
{
const QDomNode canvasElement { canvasElements.item( 0 ).firstChildElement( QStringLiteral( "extent" ) ) };
if ( !canvasElement.isNull() &&
!canvasElement.firstChildElement( QStringLiteral( "xmin" ) ).isNull() &&
!canvasElement.firstChildElement( QStringLiteral( "ymin" ) ).isNull() &&
!canvasElement.firstChildElement( QStringLiteral( "xmax" ) ).isNull() &&
!canvasElement.firstChildElement( QStringLiteral( "ymax" ) ).isNull()
)
{
QgsRectangle extent
{
canvasElement.firstChildElement( QStringLiteral( "xmin" ) ).text().toDouble(),
canvasElement.firstChildElement( QStringLiteral( "ymin" ) ).text().toDouble(),
canvasElement.firstChildElement( QStringLiteral( "xmax" ) ).text().toDouble(),
canvasElement.firstChildElement( QStringLiteral( "ymax" ) ).text().toDouble(),
};
// Need conversion?
if ( p.crs().authid() != 4326 )
{
QgsCoordinateTransform ct { p.crs(), QgsCoordinateReferenceSystem::fromEpsgId( 4326 ), p.transformContext() };
extent = ct.transform( extent );
}
info[ "initial_extent" ] = json::array( { extent.xMinimum(), extent.yMinimum(), extent.xMaximum(), extent.yMaximum() } );
}
}
} );
}

if ( p.read( projectUri ) )
{
// Title
@@ -299,6 +351,7 @@ json QgsLandingPageUtils::projectInfo( const QString &projectUri )
geographicExtent = ct.transform( geographicExtent );
}
info["geographic_extent"] = json::array( { geographicExtent.xMinimum(), geographicExtent.yMinimum(), geographicExtent.xMaximum(), geographicExtent.yMaximum() } );

// Metadata
json metadata;
const QgsProjectMetadata &md { p.metadata() };
@@ -58,19 +58,18 @@ def setUpClass(cls):
cls.temp_dir = QtCore.QTemporaryDir()

temp_dir = cls.temp_dir.path()
cls.directories = [os.path.join(temp_dir, 'landingpage', 'projects'), os.path.join(temp_dir, 'landingpage', 'projects2')]
shutil.copytree(os.path.join(unitTestDataPath('qgis_server'), 'landingpage'), os.path.join(temp_dir, 'landingpage'))

directories = [os.path.join(temp_dir, 'landingpage', 'projects'), os.path.join(temp_dir, 'landingpage', 'projects2')]
os.environ['QGIS_SERVER_PROJECTS_DIRECTORIES'] = '||'.join(directories)

if not os.environ.get('TRAVIS', False):
os.environ['QGIS_SERVER_PROJECTS_PG_CONNECTIONS'] = "postgresql://localhost:5432?sslmode=disable&dbname=landing_page_test&schema=public"

def setUp(self):
"""Clean env"""
"""Setup env"""

super().setUp()
os.environ["QGIS_SERVER_DISABLED_APIS"] = ''
os.environ['QGIS_SERVER_PROJECTS_DIRECTORIES'] = '||'.join(self.directories)

if not os.environ.get('TRAVIS', False):
os.environ['QGIS_SERVER_PROJECTS_PG_CONNECTIONS'] = "postgresql://localhost:5432?sslmode=disable&dbname=landing_page_test&schema=public"

def test_landing_page_redirects(self):
"""Test landing page redirects"""
@@ -116,7 +115,7 @@ def compareProjects(self, actual, expected, expected_path):
print("Reference file %s regenerated!" % expected_path.encode('utf8'))

for title in expected_projects.keys():
self.assertEqual(actual_projects[title], expected_projects[title])
self.assertLinesEqual(json.dumps(actual_projects[title], indent=4), json.dumps(expected_projects[title], indent=4), expected_path.encode('utf8'))

def test_landing_page_json(self):
"""Test landing page in JSON format"""

0 comments on commit 6712278

Please sign in to comment.
You can’t perform that action at this time.