[OpenLayers-Users] Share created function about SLD Filters
fsalas
fsalas at geocuba.cu
Wed Oct 14 12:01:18 EDT 2009
Hi ,
We have been at work with the filters of layers and we like tho share the created functions. We hoped that help to them.
***********************************************************
//Function for apply filters on WMS Layers using selecting value, the main objetive of this function is make one sld and then //apply to point layers, although with some simple modification is extensive to another layers Ej. Polygon.....
//***** Function for make one filter of point layer ***********//
function Crear_PropertyIsEqualTo(pPropertyName,pLiteral)
{
var PropertyIsEqualTo = '<PropertyIsEqualTo>';
PropertyIsEqualTo += '<PropertyName>'+pPropertyName+'</PropertyName>';
PropertyIsEqualTo += '<Literal>'+pLiteral+'</Literal>';
PropertyIsEqualTo += '</PropertyIsEqualTo>';
return PropertyIsEqualTo;
}
// this function make one properties for filters
function Crear_PropertyIsLessThanOrEqualTo(pPropertyName,pLiteral)
{
var PropertyIsLessThanOrEqualTo = '<PropertyIsLessThanOrEqualTo>';
PropertyIsLessThanOrEqualTo += '<PropertyName>'+pPropertyName+'</PropertyName>';
PropertyIsLessThanOrEqualTo += '<Literal>'+pLiteral+'</Literal>';
PropertyIsLessThanOrEqualTo += '</PropertyIsLessThanOrEqualTo>';
return PropertyIsLessThanOrEqualTo;
}
function Crear_PropertyIsGreaterThanOrEqualTo(pPropertyName,pLiteral)
{
var PropertyIsGreaterThanOrEqualTo = '<PropertyIsGreaterThanOrEqualTo>';
PropertyIsGreaterThanOrEqualTo += '<PropertyName>'+pPropertyName+'</PropertyName>';
PropertyIsGreaterThanOrEqualTo += '<Literal>'+pLiteral+'</Literal>';
PropertyIsGreaterThanOrEqualTo += '</PropertyIsGreaterThanOrEqualTo>';
return PropertyIsGreaterThanOrEqualTo;
}
// thsi function make one filters for inside SLD using the propperties list meke before
function Crear_Filter(Lista_Propertys,Cantidad)
{
var Filter = '<Filter xmlns:gml="http://www.opengis.net/gml">';
if(Cantidad == 0)
{
Filter = '';
}
else if(Cantidad == 1)
{
Filter += Lista_Propertys;
Filter += '</Filter>';
}
else
{
Filter += '<And>';
for( var i = 0;i < Cantidad ;i++)
{
Filter += Lista_Propertys[i];
}
Filter += '</And>';
Filter += '</Filter>';
}
return Filter;
}
// This function return the image name that wil be show in the SLD simbology
function GetImagen()
{
if(document.getElementById('tipo_anav').value != "-1")
{
if(document.getElementById('tipo_anav').value == "FV")
return "FV.gif";
if(document.getElementById('tipo_anav').value == "FA")
return "FA.gif";
if(document.getElementById('tipo_anav').value == "BY")
return "BY.gif";
if(document.getElementById('tipo_anav').value == "BZ")
return "BZ.gif";
if(document.getElementById('tipo_anav').value == "ENF")
return "ENF.gif";
}
else
return "FV.gif";
}
// This function create the Rule contained into the SLD
function Crear_Rule(pFilter)
{
var Rule ='<Rule>';
if(pFilter != '')
Rule += pFilter;
Rule +='<PointSymbolizer><Graphic><ExternalGraphic><OnlineResource xmlns:xlink="http://www.w3.org/1999/xlink" xlink:type="simple" xlink:href="file:/D:/AppServ/www/SIGANAV/images/'+GetImagen()+'"/><Format>image/gif</Format></ExternalGraphic><Opacity><Literal>1.0</Literal></Opacity><Size><Literal>20.0</Literal></Size><Rotation><Literal>0.0</Literal></Rotation></Graphic></PointSymbolizer>';
Rule +='</Rule>';
return Rule;
}
// This function create the SLD using the rule
function Crear_StyledLayerDescriptor(pRule)
{
var StyledLayerDescriptor;
StyledLayerDescriptor ='<StyledLayerDescriptor version="1.0.0"><UserLayer><Name>topp:sennal</Name><UserStyle><Name>UserSelection</Name><FeatureTypeStyle>'+pRule+'</FeatureTypeStyle></UserStyle></UserLayer></StyledLayerDescriptor>';
return StyledLayerDescriptor;
}
// This function is one example tha How filter the layer using the selecting elements
function FiltrarCapa()
{
var listaPropiedades = new Array();
var Cant = 0;
if(document.getElementById('emp').value != "-1")
{
listaPropiedades[Cant++] = Crear_PropertyIsEqualTo('empresa',document.getElementById('emp').value );
}
if(document.getElementById('est').value != "-1")
{
listaPropiedades[Cant++] = Crear_PropertyIsEqualTo('estacion',document.getElementById('est').value );
}
if(document.getElementById('tipo_anav').value != "-1")
{
listaPropiedades[Cant++] = Crear_PropertyIsEqualTo('tipo_senal',document.getElementById('tipo_anav').value );
}
if(document.getElementById('categoria').value != "-1")
{
listaPropiedades[Cant++] = Crear_PropertyIsEqualTo('categoria',document.getElementById('categoria').value );
}
if(document.getElementById('ciega').checked == true)
{
listaPropiedades[Cant++] = Crear_PropertyIsEqualTo('ciega_luminica','C');
}
if(document.getElementById('luminica').checked == true)
{
listaPropiedades[Cant++] = Crear_PropertyIsEqualTo('ciega_luminica','L');
}
if(document.getElementById('sennal_fuera_serv').checked == true)
{
var valor = "true";
listaPropiedades[Cant++] = Crear_PropertyIsEqualTo('fuera_servicio',valor);
if(document.getElementById('fecha_ini').value != "")
{
listaPropiedades[Cant++] = Crear_PropertyIsLessThanOrEqualTo('fecha_falla',document.getElementById('fecha_ini').value );
}
if(document.getElementById('fecha_fin').value != "")
{
listaPropiedades[Cant++] = Crear_PropertyIsGreaterThanOrEqualTo('fecha_falla',document.getElementById('fecha_fin').value );
}
if(document.getElementById('tipo_falla').value != "-1")
{
listaPropiedades[Cant++] = Crear_PropertyIsEqualTo('tipo_falla',document.getElementById('tipo_falla').value );
}
if(document.getElementById('origen_falla').value != "-1")
{
listaPropiedades[Cant++] = Crear_PropertyIsEqualTo('origen_falla',document.getElementById('origen_falla').value );
}
}
if(document.getElementById('mant_plan').checked == true)
{
if(document.getElementById('fecha_ini').value != "-1")
{
listaPropiedades[Cant++] = Crear_PropertyIsLessThanOrEqualTo('fecha_mant_planificado',document.getElementById('fecha_ini').value );
}
if(document.getElementById('fecha_fin').value != "-1")
{
listaPropiedades[Cant++] = Crear_PropertyIsGreaterThanOrEqualTo('fecha_mant_planificado',document.getElementById('fecha_fin').value );
}
if(document.getElementById('tipo_mant').value != "-1")
{
listaPropiedades[Cant++] = Crear_PropertyIsEqualTo('tipo_mant_realizado',document.getElementById('tipo_mant').value );
}
}
if(document.getElementById('mant_ejec').checked == true)
{
if(document.getElementById('fecha_ini').value != "-1")
{
listaPropiedades[Cant++] = Crear_PropertyIsLessThanOrEqualTo('fecha_mant_realizado',document.getElementById('fecha_ini').value );
}
if(document.getElementById('fecha_fin').value != "-1")
{
listaPropiedades[Cant++] = Crear_PropertyIsGreaterThanOrEqualTo('fecha_mant_realizado',document.getElementById('fecha_fin').value );
}
if(document.getElementById('tipo_mant').value != "-1")
{
listaPropiedades[Cant++] = Crear_PropertyIsEqualTo('tipo_mant_realizado',document.getElementById('tipo_mant').value );
}
}
//********************** Example of Call this functions ************************//
var Filtro = Crear_Filter(listaPropiedades,Cant);
var Regla = Crear_Rule(Filtro);
var StyledLayerDescriptor = Crear_StyledLayerDescriptor(Regla);
map.layers[2].mergeNewParams({SLD_BODY:StyledLayerDescriptor});
}
************************************************************
Best Regards , Salas
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.osgeo.org/pipermail/openlayers-users/attachments/20091014/f34b998a/attachment.html
More information about the Users
mailing list