2

How can I apply two styles (NamedStyle and UserStyle). When executing a query, only the top one is applied. How can I apply both styles?

This sld_body:

 <?xml version="1.0" encoding="UTF-8"?>
        <StyledLayerDescriptor version="1.0.0" xsi:schemaLocation="http://www.opengis.net/sld StyledLayerDescriptor.xsd" xmlns:gml="http://www.opengis.net/gml/3.2.1" xmlns="http://www.opengis.net/sld" xmlns:ogc="http://www.opengis.net/ogc" xmlns:xlink="http://www.w3.org/1999/xlink" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"> 
           <NamedLayer>
              <Name>${this.selectedValue.name}</Name>
              <NamedStyle>
                <Name>sld_well_o</Name>
              </NamedStyle>
              <UserStyle>
                 <Title>Heatmap</Title>
                 <Abstract>A heatmap surface showing GLOB distribution</Abstract>
                 <FeatureTypeStyle>
                    <Transformation>
                       <ogc:Function name="vec:Heatmap">
                          <ogc:Function name="parameter">
                             <ogc:Literal>data</ogc:Literal>
                          </ogc:Function>
                          <ogc:Function name="parameter">
                             <ogc:Literal>weightAttr</ogc:Literal>
                             <ogc:Literal>${selectedField.name}</ogc:Literal>
                          </ogc:Function>
                          <ogc:Function name="parameter">
                             <ogc:Literal>radiusPixels</ogc:Literal>
                             <ogc:Function name="env">
                                <ogc:Literal>radius</ogc:Literal>
                                <ogc:Literal>${radius}</ogc:Literal>
                             </ogc:Function>
                          </ogc:Function>
                          <ogc:Function name="parameter">
                             <ogc:Literal>pixelsPerCell</ogc:Literal>
                             <ogc:Literal>10</ogc:Literal>
                          </ogc:Function>
                          <ogc:Function name="parameter">
                             <ogc:Literal>outputBBOX</ogc:Literal>
                             <ogc:Function name="env">
                                <ogc:Literal>wms_bbox</ogc:Literal>
                             </ogc:Function>
                          </ogc:Function>
                          <ogc:Function name="parameter">
                             <ogc:Literal>outputWidth</ogc:Literal>
                             <ogc:Function name="env">
                                <ogc:Literal>wms_width</ogc:Literal>
                             </ogc:Function>
                          </ogc:Function>
                          <ogc:Function name="parameter">
                             <ogc:Literal>outputHeight</ogc:Literal>
                             <ogc:Function name="env">
                                <ogc:Literal>wms_height</ogc:Literal>
                             </ogc:Function>
                          </ogc:Function>
                       </ogc:Function>
                    </Transformation>
                    <Rule>
                       <RasterSymbolizer>
                          <Geometry>
                             <ogc:PropertyName>geom</ogc:PropertyName>
                          </Geometry>
                          <Opacity>${opacity}</Opacity>
                          <ColorMap type="ramp">
                             <ColorMapEntry color="#70ff00" quantity="0.0" label="nodata" opacity="0" />
                             <ColorMapEntry color="#8b8b8b" quantity="0.001" label="minValue" opacity="0" />
                             <ColorMapEntry color="${colorStart}" quantity=".1" label="start" />
                             <ColorMapEntry color="${colorEnd}" quantity="1.0" label="end" />
                          </ColorMap>
                       </RasterSymbolizer>
                    </Rule>
                 </FeatureTypeStyle>
              </UserStyle>
           </NamedLayer> 
        </StyledLayerDescriptor>

call WMS:

let sldBody = xmlRequest.replace(/\s\s+/gm, '');
this.heatMapLayer = (L as any).nonTiledLayer.wms(`${this.selectedValue.source.url}/wms`, {
  tileSize: L.point(map.getSize().x, map.getSize().y),
  format: 'image/png',
  sld_body: sldBody,
  version: '1.3.0',
  transparent: true,
  layers: this.selectedValue.name,
  cql_filter: `${selectedField.name} > 0`
});

Version GeoServer 2.15.0 I am using Lealflet

  • individually styles are applied – miroshido Apr 25 at 5:38
  • how are you calling the WMS? – Ian Turton Apr 25 at 6:56
  • @IanTurton edited question – miroshido Apr 25 at 7:28
0

You can only apply one style per layer in a WMS request so you will need to request the layer twice with the two styles.

So something like:

let sldBody1 = xmlRequest1.replace(/\s\s+/gm, '');
let sldBody2 = xmlRequest2.replace(/\s\s+/gm, '');
this.heatMapLayer = (L as any).nonTiledLayer.wms(`${this.selectedValue.source.url}/wms`, {
  tileSize: L.point(map.getSize().x, map.getSize().y),
  format: 'image/png',
  sld_body: sldBody1,sldBody2,
  version: '1.3.0',
  transparent: true,
  layers: this.selectedValue.name,this.selectedValue.name,
  cql_filter: `${selectedField.name} > 0`, `${selectedField.name} > 0`
});
  • only the first specified sldBody works – miroshido Apr 25 at 8:51
  • if this is set (sld_body: sldBody2, sldBody1,), then it activates only sldBody2 and vice versa – miroshido Apr 25 at 8:56
  • did you split the sld between the 2 variables? – Ian Turton Apr 25 at 8:59
  • yes let xmlRequestOriginLayer = <?xml version="1.0" encoding="UTF-8"?> <StyledLayerDescriptor version="1.0.0" xsi:schemaLocation="http://www.opengis.net/sld StyledLayerDescriptor.xsd" xmlns:gml="http://www.opengis.net/gml/3.2.1" xmlns="http://www.opengis.net/sld" xmlns:ogc="http://www.opengis.net/ogc" xmlns:xlink="http://www.w3.org/1999/xlink" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"> <NamedLayer> <Name>${this.selectedValue.name}</Name> <NamedStyle> <Name>sld_well_o</Name> </NamedStyle> </NamedLayer> </StyledLayerDescriptor> ; – miroshido Apr 25 at 9:01
  • and the first without this part <NamedStyle> <Name> sld_well_o </ Name> </ NamedStyle> – miroshido Apr 25 at 9:07

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.