GeoServer配置图层按比例尺显示和隐藏

本文介绍如何在GeoServer中发布的图层如WMS图层按比例尺进行显示或隐藏,以及根据这个特性扩展进行不同比例尺下显示不用的样式的设置方法。


一、按比例尺进行显示或隐藏

GeoServer在发布图层的时候,没有直接的选项进行设置在哪个比例尺内可见。但可以通过样式文件进行配置。在样式文件sld(Styled Layer Descriptor)中通过相下面的节点进行配置:

<sld:MinScaleDenominator>1000sld:MinScaleDenominator
<sld:MaxScaleDenominator>6000sld:MaxScaleDenominator>

以上表示在比例尺为1000-6000范围时显示图层。

下面贴出一个完整的点在一定比例尺内可显示的配置示例:



    
        
            
        
        
            Default Styler
            1
            
                simple
                Feature
                generic:geometry
                simple
                
                    3000 
                    6000                  
                    
                        
                            SHAPE
                        
                        
                            
                                circle
                                
                                    #90FF90
                                
                                
                                    #00FF00
                                
                            
                            5.0
                        
                                        
                
            
        
    

GeoServer配置图层按比例尺显示和隐藏_第1张图片

一、图层在不同比例尺下显示不用的样式

基于这种思想我们可以实现不同比例尺显示不同样式。

1、创建多个样式,样式根据需要显示不同比例尺级别来设置,并设置显示比例尺

2、创建多个图层,分别选择上一步设置的不同样式。

3、创建一个图层组,将上一步创建的图层加入到图层组中。

4、前端调用加载上一步创建发布的图层组。

另外,还有另外一种增加规则标签的实现方法(http://blog.csdn.net/longshengguoji/article/details/51540312):

[html]  view plain  copy
 
  1. xml version="1.0" encoding="ISO-8859-1"?>  
  2. <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">  
  3.     <sld:UserLayer>  
  4.         <sld:LayerFeatureConstraints>  
  5.             <sld:FeatureTypeConstraint/>  
  6.         sld:LayerFeatureConstraints>  
  7.         <sld:UserStyle>  
  8.             <sld:Name>dianstylesld:Name>  
  9.             <sld:Title/>  
  10.             <sld:FeatureTypeStyle>  
  11.                 <sld:Name>group 0sld:Name>  
  12.                 <sld:FeatureTypeName>Featuresld:FeatureTypeName>  
  13.                 <sld:SemanticTypeIdentifier>generic:geometrysld:SemanticTypeIdentifier>  
  14.                 <sld:SemanticTypeIdentifier>colorbrewer:unique:pairedsld:SemanticTypeIdentifier>  
  15.                 <sld:Rule>  
  16.                     <sld:Name>电梯口bigsld:Name>  
  17.                     <sld:Title>diantikou1sld:Title>                                
  18.                     <ogc:Filter>  
  19.                         <ogc:PropertyIsEqualTo>  
  20.                                 <ogc:PropertyName>typeogc:PropertyName>  
  21.                                 <ogc:Literal>1ogc:Literal>  
  22.                         ogc:PropertyIsEqualTo>                              
  23.                     ogc:Filter>  
  24.                     <sld:MaxScaleDenominator>200.0sld:MaxScaleDenominator>           
  25.                     <sld:PointSymbolizer>  
  26.                         <sld:Graphic>  
  27.                             <sld:ExternalGraphic>  
  28.                               <sld:OnlineResource xmlns:xlink="http://www.w3.org/1999/xlink" xlink:type="simple" xlink:href="dianti.png"/>  
  29.                                 <sld:Format>image/pngsld:Format>  
  30.                             sld:ExternalGraphic>  
  31.                             <sld:Size>32sld:Size>  
  32.                         sld:Graphic>  
  33.                     sld:PointSymbolizer>  
  34.                 sld:Rule>  
  35.                 <sld:Rule>  
  36.                     <sld:Name>电梯口mediamsld:Name>  
  37.                     <sld:Title>diantikou2sld:Title>                                          
  38.                     <ogc:Filter>  
  39.                         <ogc:PropertyIsEqualTo>  
  40.                                 <ogc:PropertyName>typeogc:PropertyName>  
  41.                                 <ogc:Literal>1ogc:Literal>  
  42.                         ogc:PropertyIsEqualTo>                              
  43.                     ogc:Filter>  
  44.                     <sld:MinScaleDenominator>200.0sld:MinScaleDenominator>  
  45.                     <sld:MaxScaleDenominator>400.0sld:MaxScaleDenominator>       
  46.                     <sld:PointSymbolizer>  
  47.                         <sld:Graphic>  
  48.                             <sld:ExternalGraphic>  
  49.                               <sld:OnlineResource xmlns:xlink="http://www.w3.org/1999/xlink" xlink:type="simple" xlink:href="dianti.png"/>  
  50.                                 <sld:Format>image/pngsld:Format>  
  51.                             sld:ExternalGraphic>  
  52.                             <sld:Size>26sld:Size>  
  53.                         sld:Graphic>  
  54.                     sld:PointSymbolizer>  
  55.                 sld:Rule>  
  56.                 <sld:Rule>  
  57.                     <sld:Name>电梯口smallsld:Name>  
  58.                     <sld:Title>diantikou3sld:Title>                             
  59.                     <ogc:Filter>  
  60.                         <ogc:PropertyIsEqualTo>  
  61.                                 <ogc:PropertyName>typeogc:PropertyName>  
  62.                                 <ogc:Literal>1ogc:Literal>  
  63.                         ogc:PropertyIsEqualTo>                              
  64.                     ogc:Filter>  
  65.                      <sld:MinScaleDenominator>600.0sld:MinScaleDenominator>    
  66.                     <sld:PointSymbolizer>  
  67.                         <sld:Graphic>  
  68.                             <sld:ExternalGraphic>  
  69.                               <sld:OnlineResource xmlns:xlink="http://www.w3.org/1999/xlink" xlink:type="simple" xlink:href="dianti.png"/>  
  70.                                 <sld:Format>image/pngsld:Format>  
  71.                             sld:ExternalGraphic>  
  72.                             <sld:Size>20sld:Size>  
  73.                         sld:Graphic>  
  74.                     sld:PointSymbolizer>  
  75.                 sld:Rule>               
  76.            sld:FeatureTypeStyle>  
  77.         sld:UserStyle>  
  78.     sld:UserLayer>  
  79. sld:StyledLayerDescriptor>  

你可能感兴趣的:(GeoServer配置图层按比例尺显示和隐藏)