From 901b87fbf5dc70c8808ee3b1d733a8020469046b Mon Sep 17 00:00:00 2001 From: Theo Satabin Date: Tue, 26 Nov 2024 10:53:12 +0100 Subject: [PATCH] =?UTF-8?q?Gestion=20d'un=20style=20par=20d=C3=A9faut?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ### [Added] * `Layer` : rétablissement d'un style par défaut au chargement de la couche. L'identifiant de ce style par défaut peut être fourni via le champ `default_style` dans le fichier de configuration des services, à la racine (optionnel, `normal` par défaut) --- CHANGELOG.md | 6 ++++++ config/services.json | 1 + config/services.schema.json | 5 +++++ src/configurations/Layer.cpp | 12 ++++++++++-- src/configurations/Metadata.h | 2 +- src/configurations/Services.cpp | 12 ++++++++++++ src/configurations/Services.h | 4 ++++ 7 files changed, 39 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 68e32fe..5c47c16 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,9 @@ +## 6.1.2 + +### [Added] + +* `Layer` : rétablissement d'un style par défaut au chargement de la couche. L'identifiant de ce style par défaut peut être fourni via le champ `default_style` dans le fichier de configuration des services, à la racine (optionnel, `normal` par défaut) + ## 6.1.1 ### [Fixed] diff --git a/config/services.json b/config/services.json index a4c6532..3677090 100644 --- a/config/services.json +++ b/config/services.json @@ -17,6 +17,7 @@ "email": "" }, "crs_equivalences": "/etc/rok4/equals_crs.json", + "default_style": "normal", "admin": { "enabled": true }, diff --git a/config/services.schema.json b/config/services.schema.json index 893bc70..bc8c2ba 100644 --- a/config/services.schema.json +++ b/config/services.schema.json @@ -27,6 +27,11 @@ "type": "string", "description": "Path to JSON file with identical CRS (to avoid useless tranformation)" }, + "default_style": { + "type": "string", + "description": "Default style internal identifier", + "default": "normal" + }, "contact": { "type": "object", "additionalProperties": false, diff --git a/src/configurations/Layer.cpp b/src/configurations/Layer.cpp index 38a7777..8ac33ce 100644 --- a/src/configurations/Layer.cpp +++ b/src/configurations/Layer.cpp @@ -348,8 +348,16 @@ bool Layer::parse(json11::Json& doc, ServicesConfiguration* services) { } if ( available_styles.size() == 0 ) { - error_message = "No provided valid style, the layer is not valid" ; - return false; + Style* sty = StyleBook::get_style(services->get_default_style_id()); + if ( sty == NULL ) { + error_message = "No valid style (even the default one), the layer is not valid" ; + return false; + } + if ( ! is_style_handled(sty) ) { + error_message = "No valid style (even the default one), the layer is not valid" ; + return false; + } + available_styles.push_back ( sty ); } // Configuration des reprojections possibles diff --git a/src/configurations/Metadata.h b/src/configurations/Metadata.h index 885aa06..d4b863b 100644 --- a/src/configurations/Metadata.h +++ b/src/configurations/Metadata.h @@ -179,7 +179,7 @@ class Metadata : public ResourceLocator { void add_node_tms(ptree& parent) { ptree& node = parent.add("Metadata", ""); node.add(".type", type); - node.add(".mime-type", "text/xml"); + node.add(".mime-type", format); node.add(".href", href); } diff --git a/src/configurations/Services.cpp b/src/configurations/Services.cpp index 556d683..0fd67c6 100644 --- a/src/configurations/Services.cpp +++ b/src/configurations/Services.cpp @@ -49,6 +49,7 @@ bool ServicesConfiguration::parse(json11::Json& doc) { fee=""; access_constraint=""; provider_site=""; + default_style="normal"; // ----------------------- Global @@ -90,6 +91,13 @@ bool ServicesConfiguration::parse(json11::Json& doc) { return false; } + if (doc["default_style"].is_string()) { + default_style = doc["default_style"].string_value(); + } else if (! doc["default_style"].is_null()) { + error_message = "default_style have to be a string"; + return false; + } + // ----------------------- Contact json11::Json contact_section = doc["contact"]; @@ -313,6 +321,10 @@ bool ServicesConfiguration::are_crs_equals( std::string crs1, std::string crs2 ) return false; } +std::string ServicesConfiguration::get_default_style_id() { + return default_style; +} + ServicesConfiguration::~ServicesConfiguration(){ delete common_service; delete tms_service; diff --git a/src/configurations/Services.h b/src/configurations/Services.h index b3f0dd4..cc68568 100644 --- a/src/configurations/Services.h +++ b/src/configurations/Services.h @@ -103,6 +103,8 @@ class ServicesConfiguration : public Configuration }; bool are_crs_equals( std::string crs1, std::string crs2 ); + std::string get_default_style_id(); + /** * \~french * \brief Supprime les réponses cachées @@ -122,6 +124,8 @@ class ServicesConfiguration : public Configuration Contact* contact; + std::string default_style; + private: /**