Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Issues with layer style legends displayed when more than one style is selected #7236

Closed
afabiani opened this issue Apr 6, 2021 · 9 comments
Assignees
Labels
wontfix Stale Bot: Stale issue
Milestone

Comments

@afabiani
Copy link
Member

afabiani commented Apr 6, 2021

Expected Behavior

When adding more than one style to a layer, I can see the legend of the current selected style.

Actual Behavior

I see multiple legends. Moreover the title of the CSS ones report a long UUID as stated form this issue here

Steps to Reproduce the Problem

  1. Edit a Layer
  2. Add more than one style either from the map editor or "style manage" utility
  3. Go back to the layer detail page

grafik

Specifications

  • GeoNode version: 3.2.x
  • Installation method (manual, GeoNode Docker, SPCGeoNode Docker): any
  • Platform:
  • Additional details:
@afabiani afabiani added the regression Issues related to regressions. label Apr 6, 2021
@afabiani afabiani added this to the 3.2 milestone Apr 6, 2021
@simboss simboss added major A high priority issue which might affect a lot of people or large parts of the codebase backport 3.2.x PR should be backported to target version BackportNeeded labels Apr 6, 2021
afabiani added a commit that referenced this issue Apr 7, 2021
github-actions bot pushed a commit that referenced this issue Apr 8, 2021
afabiani pushed a commit that referenced this issue Apr 8, 2021
…n one style is selected (#7253) (#7256)

Co-authored-by: Alessio Fabiani <alessio.fabiani@geo-solutions.it>
afabiani pushed a commit that referenced this issue Apr 8, 2021
…n one style is selected (#7253)

(cherry picked from commit 8b0d629)

# Conflicts:
#	geonode/geoserver/views.py
afabiani pushed a commit that referenced this issue Apr 8, 2021
…n one style is selected (#7253) (#7257)

(cherry picked from commit 8b0d629)

# Conflicts:
#	geonode/geoserver/views.py
@gannebamm
Copy link
Contributor

gannebamm commented Apr 26, 2021

I still see the UUID in the legend title on master: https://master.demo.geonode.org/layers/geonode:background_layer_germany_epsg4326

Is this not yet backported? It should be part of 3.2 in my opionion.

@gannebamm gannebamm reopened this Apr 26, 2021
@giohappy
Copy link
Contributor

giohappy commented Apr 26, 2021

@gannebamm yes, this is quite problematic. I've spent some time to investigate it.

1 - When the Style Editor sends the first POST (through the geoserver_proxy view), GeoNode triggers the Geoserver post save signal

_s = save_style(alt_style, layer)

This is where the new style is retrieved from Geoserver and saved in GeoNode.

NOTE: The style editor POSTs using the name parameter to set the style name in Geoserver, the one with the hash. This is of course needed to avoid writing styles with the same name.

2 - The style information is obtained from the gs_restconfig parsing. Both with CSS and SLD styles it seems that gs_restconfig doesn't populate the sld_title property, becuase it uses the XML response from Geoserver REST config, which only includes the style name.

gs_layer = gs_catalog.get_layer(layer.name)

An example with a CSS style. Code posted by the Style Editor

"Lines 3"
@mode 'Flat';
@styleTitle 'Line 3';
@styleAbstract '';
 * {
	mark: symbol('shape://vertline');
	:mark { stroke: #ff338f; };
}

Output from Geoserver (/geoserver/rest/workspaces/geonode/styles/line_3___2964cfc0-a671-11eb-a607-47c492148453.sld)

<?xml version="1.0" encoding="UTF-8"?>
<sld:StyledLayerDescriptor xmlns:sld="http://www.opengis.net/sld" xmlns="http://www.opengis.net/sld" xmlns:gml="http://www.opengis.net/gml" xmlns:ogc="http://www.opengis.net/ogc" version="1.0.0">
   <sld:NamedLayer>
      <sld:Name>Default Styler</sld:Name>
      <sld:UserStyle>
         <sld:Name>Default Styler</sld:Name>
         <sld:Title>Line 3</sld:Title>
         <sld:FeatureTypeStyle>
            <sld:Name>name</sld:Name>
            <sld:Rule>
               <sld:PointSymbolizer>
                  <sld:Graphic>
                     <sld:Mark>
                        <sld:WellKnownName>shape://vertline</sld:WellKnownName>
                        <sld:Stroke>
                           <sld:CssParameter name="stroke">#ff338f</sld:CssParameter>
                        </sld:Stroke>
                     </sld:Mark>
                  </sld:Graphic>
               </sld:PointSymbolizer>
            </sld:Rule>
         </sld:FeatureTypeStyle>
      </sld:UserStyle>
   </sld:NamedLayer>
</sld:StyledLayerDescriptor>

gs_restconfig parsed information
image

where the style infor is obtained from/geoserver/rest/workspaces/geonode/styles/circle_2___b450e9a0-a678-11eb-a607-47c492148453.xml:

<?xml version="1.0" encoding="UTF-8"?>
<style>
   <name>circle_2___b450e9a0-a678-11eb-a607-47c492148453</name>
   <workspace>
      <name>geonode</name>
   </workspace>
   <format>css</format>
   <languageVersion>
      <version>1.0.0</version>
   </languageVersion>
   <filename>circle_2___b450e9a0-a678-11eb-a607-47c492148453.css</filename>
   <dateCreated>2021-04-26 10:18:12.62 UTC</dateCreated>
</style>

The same happens with an SLD

3 - In case of an SLD style it tries to parse the sld_title property if available, otherwise the style name is used. In case of a CSS it uses the style name directly

style.sld_title = gs_style.sld_title if gs_style.style_format != 'css' and gs_style.sld_title else sld_name

In both cases the end result is that the style name, the one with the hash, is used and stored.

In the end the problem is probably due to the an incomplete metadata information for the style returned by Geoserver REST API. I will ask the Geoserver team if / how the returned metadata can be extended with the title. I guess it's not that strighforwars, since an SLD can be used in library mode, so multiple styles could be stored inside it.

Otherwise we need to change the way we obtain style info from Geoserver.

@giohappy
Copy link
Contributor

giohappy commented Apr 26, 2021

It's confirmed that the solutions are two:

1 - Obtain the style from Geoserver REST API in SLD format and parse the title from the UserStyle.Title element. This works in all the practical cases, although a style could have in theory multiple User Styles. In these (rare!) cases we can decide to take the first UserStyle element.

2 - Use the style metadata info capacilities. If a PUT to Geoserver style REST API contains a metadata propert, this should be stored along with the style and be returned when requesting the XML for the style. In this case we could make the Style Editor send the title as a metadata info, and simply parse it inside geonode_restconfig (geosolutions-it/MapStore2#3750)

We'll discuss the two options internally.

@giohappy
Copy link
Contributor

The mid-term solution will probably be this: GeoNode/geonode-mapstore-client#144

@giohappy
Copy link
Contributor

This is the short-term solution: #7390

@marthamareal
Copy link
Contributor

@giohappy @afabiani On layers with no default style, multiple legends are displayed.
Example

admin

layer

This because the layer_detail template loops through all legends returned by the resource.get_legend

@giohappy
Copy link
Contributor

giohappy commented Apr 27, 2021

@marthamareal can you send a PR for this?

@afabiani afabiani removed backport 3.2.x PR should be backported to target version major A high priority issue which might affect a lot of people or large parts of the codebase labels Apr 27, 2021
@giohappy
Copy link
Contributor

giohappy commented Apr 27, 2021

so, in the end, the situation where we have the default style None and multiple legend links is something rare, if not impossible without manually messing inside the DB.
So I wouldn't consider the comment from @marthamareal for the moment.

@afabiani afabiani added wontfix Stale Bot: Stale issue and removed regression Issues related to regressions. labels Apr 27, 2021
@giohappy
Copy link
Contributor

Fixed through #7405

marthamareal added a commit to geosolutions-it/geonode that referenced this issue May 18, 2021
…ore than one style is selected (GeoNode#7253) (GeoNode#7256)

Co-authored-by: Alessio Fabiani <alessio.fabiani@geo-solutions.it>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
wontfix Stale Bot: Stale issue
Projects
None yet
Development

No branches or pull requests

5 participants