[OpenLayers-Users] HELP!!! How implement Filter in WMS Layer

Andreas Hocevar ahocevar at opengeo.org
Sat Sep 12 03:21:16 EDT 2009


fsalas wrote:
> Andreas, Thanks , but I am beginner and don't have information about
> this topic.
>
> Can you send me illustrative example or information.
>
> I using GeoServer and I like obtain dynamic maps with some condition.
>
> I try with this code but don't change the maps.
>
> ....................
>
> mapa = new OpenLayers.Map('map', options);
>
>           // setup tiled layer  SLD: "http://deltha:8080/SLD/mapa.sld",
>
>            faro= new OpenLayers.Layer.WMS(
>                "topp:mapacuba - Tiled",
> "http://deltha:8080/geoserver/wms",
>                {
>                    layers: 'topp:faro,
>                    styles: '',
>                    height: '300',
>                    width: '800',
>                    srs: 'EPSG:4267',
>                    format: 'image/png',
>                    tiled: 'true',
>                  tilesOrigin : "-85.49711392680179,19.65266328193469"
>                },
>             {buffer: 0}
>            );
>
>            map.addLayers([faro]);
>
> and after that........
>
> mapa.mergeNewParams({sld:'http://localhost:8080/SLD/faros.sld'});
> mapa.redraw();

This won't work. The WMS request requires *either* LAYERS and STYLES,
*or* just SLD or SLD_BODY. You can have a look at the Sample requests
page in your GeoServer admin frontend. There you will find the following
request:

http://localhost:8080/geoserver/wms?bbox=-130,24,-66,50&Format=image/png&request=GetMap&width=550&height=250&srs=EPSG:4326&SLD_BODY=%3CStyledLayerDescriptor%20version%3D%221.0.0%22%3E%3CUserLayer%3E%3CName%3Etopp:states%3C/Name%3E%3CUserStyle%3E%3CName%3EUserSelection%3C/Name%3E%3CFeatureTypeStyle%3E%3CRule%3E%3CFilter%20xmlns:gml%3D%22http://www.opengis.net/gml%22%3E%3CPropertyIsEqualTo%3E%3CPropertyName%3ESTATE_NAME%3C/PropertyName%3E%3CLiteral%3EIllinois%3C/Literal%3E%3C/PropertyIsEqualTo%3E%3C/Filter%3E%3CPolygonSymbolizer%3E%3CFill%3E%3CCssParameter%20name%3D%22fill%22%3E%23FF0000%3C/CssParameter%3E%3C/Fill%3E%3C/PolygonSymbolizer%3E%3C/Rule%3E%3CRule%3E%3CLineSymbolizer%3E%3CStroke/%3E%3C/LineSymbolizer%3E%3C/Rule%3E%3C/FeatureTypeStyle%3E%3C/UserStyle%3E%3C/UserLayer%3E%3C/StyledLayerDescriptor%3E

In your snippet, this would look as follows:

           faro= new OpenLayers.Layer.WMS(
               "topp:mapacuba - Tiled", "http://deltha:8080/geoserver/wms",
               {
                   //layers: 'topp:faro,
                   //styles: '',
                   sld_body:
'%3CStyledLayerDescriptor%20version%3D%221.0.0%22%3E%3CUserLayer%3E%3CName%3Etopp:faro%3C/Name%3E%3CUserStyle%3E%3CName%3EUserSelection%3C/Name%3E%3CFeatureTypeStyle%3E%3CRule%3E%3CFilter%20xmlns:gml%3D%22http://www.opengis.net/gml%22%3E%3CPropertyIsEqualTo%3E%3CPropertyName%3ESTATE_NAME%3C/PropertyName%3E%3CLiteral%3EIllinois%3C/Literal%3E%3C/PropertyIsEqualTo%3E%3C/Filter%3E%3CPolygonSymbolizer%3E%3CFill%3E%3CCssParameter%20name%3D%22fill%22%3E%23FF0000%3C/CssParameter%3E%3C/Fill%3E%3C/PolygonSymbolizer%3E%3C/Rule%3E%3CRule%3E%3CLineSymbolizer%3E%3CStroke/%3E%3C/LineSymbolizer%3E%3C/Rule%3E%3C/FeatureTypeStyle%3E%3C/UserStyle%3E%3C/UserLayer%3E%3C/StyledLayerDescriptor%3E',
                   height: '300',
                   width: '800',
                   srs: 'EPSG:4267',
                   format: 'image/png',
                   tiled: 'true',
                 tilesOrigin : "-85.49711392680179,19.65266328193469"
               },
            {buffer: 0}
           );

           map.addLayers([faro]);

If you have the contents of sld_body in an external sld file, you just
need to replace sld_body with sld, and the value with the url of the sld
file (from the perspective of your geoserver instance).

Regards,
Andreas.

>
> Best reggards,
> Salas
>
> ----- Original Message ----- From: "Andreas Hocevar"
> <ahocevar at opengeo.org>
> To: "fsalas" <fsalas at geocuba.cu>
> Cc: <users at openlayers.org>
> Sent: Thursday, September 10, 2009 1:42 PM
> Subject: Re: [OpenLayers-Users] HELP!!! How implement Filter in WMS Layer
>
>
>> fsalas wrote:
>>>
>>> In this time , I have openlayer 2.8 and be studying the filter.html
>>> example.
>>>
>>> my question is
>>>
>>> 1. ¿ How I can use the WMS Layer with filter?
>>>
>>
>> If you want to do it the OGC way, you have to add a SLD_BODY param
>> with an SLD that contains the filter and the symbology you want.
>>
>> If you are using GeoServer, you can also use the FILTER param directly.
>> In that case, you may want to have a look at the CQL_FILTER param
>> which provides a more compact filter language.
>>
>> Regards,
>> Andreas.
>>
>> -- 
>> Andreas Hocevar
>> OpenGeo - http://opengeo.org/
>> Expert service straight from the developers.
>>
>>
>
>
> ___________________________________
> Dirección de Comunicaciones
> Grupo Empresarial GEOCUBA
> Este mensaje esta libre de virus. Revisado por Kaspersky Antivirus
> ----------------------------------------------------------------------
> Definition count:  2526893
> Definition date:  9/11/2009
> SecurityPlus version: 3.0.5
>
>
>


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




More information about the Users mailing list