Skip to content

Commit

Permalink
Gestion d'un style par défaut
Browse files Browse the repository at this point in the history
### [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)
  • Loading branch information
Dolite committed Nov 26, 2024
1 parent 5f18cec commit 901b87f
Show file tree
Hide file tree
Showing 7 changed files with 39 additions and 3 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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]
Expand Down
1 change: 1 addition & 0 deletions config/services.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
"email": ""
},
"crs_equivalences": "/etc/rok4/equals_crs.json",
"default_style": "normal",
"admin": {
"enabled": true
},
Expand Down
5 changes: 5 additions & 0 deletions config/services.schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
12 changes: 10 additions & 2 deletions src/configurations/Layer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion src/configurations/Metadata.h
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,7 @@ class Metadata : public ResourceLocator {
void add_node_tms(ptree& parent) {
ptree& node = parent.add("Metadata", "");
node.add("<xmlattr>.type", type);
node.add("<xmlattr>.mime-type", "text/xml");
node.add("<xmlattr>.mime-type", format);
node.add("<xmlattr>.href", href);
}

Expand Down
12 changes: 12 additions & 0 deletions src/configurations/Services.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ bool ServicesConfiguration::parse(json11::Json& doc) {
fee="";
access_constraint="";
provider_site="";
default_style="normal";

// ----------------------- Global

Expand Down Expand Up @@ -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"];
Expand Down Expand Up @@ -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;
Expand Down
4 changes: 4 additions & 0 deletions src/configurations/Services.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -122,6 +124,8 @@ class ServicesConfiguration : public Configuration

Contact* contact;

std::string default_style;

private:

/**
Expand Down

0 comments on commit 901b87f

Please sign in to comment.