[OpenLayers-Users] mergeNewParams + Legend

Andreas Hocevar ahocevar at opengeo.org
Fri Aug 6 10:25:02 EDT 2010


Hi,

I see you don't use SLD_BODY any more. So you don't need the whole workaround, and also don't need Layer.WMS.POST. This is good - using SLD instead of SLD_BODY is the preferred option.

Regards,
Andreas.

On Aug 6, 2010, at 16:22 , Sascha Müller wrote:

> 
> 
> Hi,
> 
> Ok, I've got it a little bit.
> 
> 1) I changed in VectorLegend.js
> GeoExt.VectorLegend.supports = function(layerRecord) {
> -    return layerRecord.get("layer") instanceof OpenLayers.Layer.Vector;
> +   return layerRecord.get("layer").styleMap;
> };
> 
> 2) I add
> "preferredTypes: ["gx_vectorlegend"]" to my LegendPanel.
> 
> 3) I load a WMS-Layer with a SLD_Body:
> var ub = new OpenLayers.Layer.WMS.Post("U-Bahn Test",
>                 "http://localhost:8081/geoserver/wms/",
>                 {
>                     layers: "WL:UBahn",
>                     transparent: true,
>                     format: 'image/jpeg',
>                     sld    : 
> "http://localhost:8081/geoserver/styles/myStyle.sld"
>                 },
>                 {
>                     isBaseLayer: false
>                 }
>             );
>             map.addLayer(ub);
> 
> 4) But, how do I give the WMS layer a styleMap?
> 
> var myStyles = new OpenLayers.StyleMap({
>         "default": new OpenLayers.Style({
>             fillColor: "#ffcc66",
>             strokeColor: "#ff9933",
>             strokeWidth: 2,
>             graphicZIndex: 1
>         })
>     });
> 
> ???
> 
> 4) Do mergeNewParams()
> 
> 
> 
> Maybe this is an own thread:
> After this works, is there a way, to get the properties out of the sld 
> and wrire it in the styleMap? similiar to this thread
> http://osgeo-org.1803224.n2.nabble.com/StyleMap-and-dynamic-loaded-styles-td4961340.html#a4961340
> The difference is, I got a XML (SLD) back. If not, I have to parse the 
> whole SLd and get all the properties and mut them into the styleMap.
> 
> 
> regards,
> 
> Sascha
> 
> 
>> Hi,
>> 
>> On Aug 6, 2010, at 12:23 , Sascha Müller wrote:
>> 
>> 
>>> Do I understand it right, for every layer (WMS) I create, I have to
>>> give the WMS layer a StyleMap with a "default" render intent? Because I
>>> use a VectorLegend?
>>> 
>> No. The VectorLegend will only be used *if* the WMS layer has a StyleMap. It will still use WMSLegend for other layers
>> 
>> 
>>> I have in my App, depending on the customer, a different number of
>>> layers. This sounds like a lot of work for me.
>>> Or I have to create a VectorLegend specially for the layer with the
>>> large SLD?
>>> 
>> Yes, just for that layer. Only WMS layers that have a styleMap property will get a VectorLegend if you follow my suggestion.
>> 
>> Regards,
>> Andreas.
>> 
>> 
>>> 
>>>>> This will tell VectorLegend that it supports all layers that have a
>>>>> 
>>> styleMap.>>  Does it mean, that the Legend accept ONLY layer that have a
>>> styleMap or accept ALSO layer that have a styleMap?
>>> 
>>> Another approaches:
>>> - If I change from SLD_BODY to SLD (with the URL of the SLD) in
>>> mergeNewParams(), prevents this a too long URI?
>>> - Is there a way to use 'POST' with GetLegendGraphic?
>>> 
>>> regards,
>>> 
>>> Sascha
>>> 
>>> 
>>> 
>>>> Hi,
>>>> 
>>>> I am pretty sure that the request URI is too long. What you could do is reconfigure the legend type selection sequence, so a VectorLegend rather than a WMSLegend is created. A prerequisite is this non-API hack though:
>>>> 
>>>> GeoExt.VectorLegend.supports = function(layerRecord) {
>>>>     return layerRecord.get("layer").styleMap;
>>>> };
>>>> 
>>>> This will tell VectorLegend that it supports all layers that have a styleMap.
>>>> 
>>>> Now you can go ahead and create your legendPanel like this:
>>>> 
>>>> var legendPanel = new GeoExt.LegendPanel({
>>>>     preferredTypes: ["gx_vectorlegend"]
>>>> });
>>>> 
>>>> Finally, when creating your WMS layer with the SLD_BODY (and before you do mergeNewParams), you have to give the WMS layer a StyleMap with a "default" render intent, which you have to give the style object of your SLD.
>>>> 
>>>> Regards,
>>>> Andreas.
>>>> 
>>>> On Aug 5, 2010, at 17:45 , Sascha Müller wrote:
>>>> 
>>>> 
>>>> 
>>>>> Hi,
>>>>> 
>>>>> I tried this SLD with only two instead of five rules. It works.
>>>>> Could it be, that the request 'GetLegendGraphic' is too long with the
>>>>> SLD inside?
>>>>> Like mergeNewParams() without 'Post'  in 'OpenLayers.Layer.WMS'.
>>>>> 
>>>>> Is there a way to implement it?
>>>>> Or is this more a GeoServer thing?
>>>>> 
>>>>> Sascha
>>>>> 
>>>>> 
>>>>> 
>>>>> 
>>>>>> Hi,
>>>>>> 
>>>>>> I use:
>>>>>> 
>>>>>> GeoExt: trunk (Revision: 2257)
>>>>>> OpenLayers: 2.9
>>>>>> GeoExt: 3.2.1
>>>>>> GeoServer: 1.7.7
>>>>>> 
>>>>>> 
>>>>>> I use mergeNewParams() to change the Style of a layer. This approach
>>>>>> works except for one layer.
>>>>>> This layer contains five rules with filter. The map changes after
>>>>>> mergeNewParams(), the legend not.
>>>>>> The layername is still there, the images of the five rules are gone.
>>>>>> 
>>>>>> If I use this SLD (see below) for the layer with the GeoServer from
>>>>>> start, the layer appears in map and legend. only after
>>>>>> mergenewParams() the layer appears not in the legend.
>>>>>> 
>>>>>> The layer uses this:  var addlayer = new OpenLayers.Layer.WMS.Post()
>>>>>> 
>>>>>> SLD
>>>>>> ===
>>>>>> <?xml version="1.0" encoding="UTF-8"?>
>>>>>> <sld:StyledLayerDescriptor xmlns="http://www.opengis.net/sld"
>>>>>> xmlns:sld="http://www.opengis.net/sld"
>>>>>> xmlns:ogc="http://www.opengis.net/ogc"
>>>>>> xmlns:gml="http://www.opengis.net/gml" version="1.0.0">
>>>>>> <sld:NamedLayer>
>>>>>> <Name>WL:UBahn</Name>
>>>>>> <sld:UserStyle>
>>>>>> <sld:Name>Default Styler</sld:Name>
>>>>>> <sld:Title/>
>>>>>> <sld:FeatureTypeStyle>
>>>>>> <sld:Name>name</sld:Name>
>>>>>> <sld:FeatureTypeName>Feature</sld:FeatureTypeName>
>>>>>> <sld:SemanticTypeIdentifier>generic:geometry</sld:SemanticTypeIdentifier>
>>>>>> <sld:SemanticTypeIdentifier>colorbrewer:unique:oranges</sld:SemanticTypeIdentifier>
>>>>>> <sld:Rule>
>>>>>> <sld:MinScaleDenominator>0</sld:MinScaleDenominator>
>>>>>> <sld:MaxScaleDenominator>100000000</sld:MaxScaleDenominator>
>>>>>> <sld:Name>rule01</sld:Name>
>>>>>> <sld:Title>U1</sld:Title>
>>>>>> <Filter>
>>>>>> <PropertyIsEqualTo>
>>>>>> <PropertyName>LINIE</PropertyName>
>>>>>> <Literal>U1</Literal>
>>>>>> </PropertyIsEqualTo>
>>>>>> </Filter>
>>>>>> <sld:LineSymbolizer>
>>>>>> <sld:Stroke>
>>>>>> <sld:CssParameter name="stroke">
>>>>>> <Literal>#FEEDDE</Literal>
>>>>>> </sld:CssParameter>
>>>>>> <sld:CssParameter name="stroke-linecap">
>>>>>> <Literal>butt</Literal>
>>>>>> </sld:CssParameter>
>>>>>> <sld:CssParameter name="stroke-linejoin">
>>>>>> <Literal>miter</Literal>
>>>>>> </sld:CssParameter>
>>>>>> <sld:CssParameter name="stroke-opacity">1</sld:CssParameter>
>>>>>> <sld:CssParameter name="stroke-width">3</sld:CssParameter>
>>>>>> <sld:CssParameter name="stroke-dashoffset">
>>>>>> <Literal>0</Literal>
>>>>>> </sld:CssParameter>
>>>>>> </sld:Stroke>
>>>>>> </sld:LineSymbolizer>
>>>>>> </sld:Rule>
>>>>>> 
>>>>>> <!-- The other RULSs looks the same like the one above -->
>>>>>> 
>>>>>> </sld:FeatureTypeStyle>
>>>>>> </sld:UserStyle>
>>>>>> </sld:NamedLayer>
>>>>>> </sld:StyledLayerDescriptor>
>>>>>> 
>>>>>> Is there something wrong with the SLD? Do I have something to consider
>>>>>> if I use mergeNewParams(), or something with the Legend?
>>>>>> 
>>>>>> Thanks
>>>>>> 
>>>>>> Sascha
>>>>>> 
>>>>>> 
>>>>>> _______________________________________________
>>>>>> Users mailing list
>>>>>> Users at openlayers.org
>>>>>> http://openlayers.org/mailman/listinfo/users
>>>>>> 
>>>>>> 
>>>>>> 
>>>>>> 
>>>>>> 
>>>>> _______________________________________________
>>>>> Users mailing list
>>>>> Users at openlayers.org
>>>>> http://openlayers.org/mailman/listinfo/users
>>>>> 
>>>>> 
>>>> 
>>>> 
>>>> 
>>> 
>>> _______________________________________________
>>> Users mailing list
>>> Users at openlayers.org
>>> http://openlayers.org/mailman/listinfo/users
>>> 
>> 
> 
> 
> _______________________________________________
> Users mailing list
> Users at openlayers.org
> http://openlayers.org/mailman/listinfo/users

-- 
Andreas Hocevar
OpenGeo - http://opengeo.org/
Expert service straight from the developers.




More information about the Users mailing list