qgis-server-getlegendgraphic-scale.patch

Implementing SCALE parameter in GetLegendGraphic - René-Luc ReLuc, 2012-04-13 05:07 AM

Download (1.77 KB)

View differences:

src/mapserver/qgswmsserver.cpp
299 299

  
300 300
  QgsCoordinateReferenceSystem dummyCRS;
301 301
  QStringList layerIds = layerSet( layersList, stylesList, dummyCRS );
302

  
303
  //read SCALE
304
  QMap<QString, QString>::const_iterator scale_it = mParameterMap.find( "SCALE" );
305
  if ( scale_it != mParameterMap.end() )
306
  {
307
    //converting SCALE
308
    bool conversionSuccess;
309
    bool scaleOk = true;
310
    double scaleValue = scale_it.value().toDouble( &conversionSuccess );
311
    if ( !conversionSuccess )
312
      scaleOk = false;
313

  
314
    //reducing layerIds stringList
315
    if ( scaleOk )
316
    {
317
      QMap<QString, QgsMapLayer*>& layerMap = QgsMapLayerRegistry::instance()->mapLayers();
318
      QStringList newLayerIds;
319

  
320
      foreach( QString id, layerIds )
321
      {
322
        QgsMapLayer *layer = layerMap.value( id, 0 );
323
        if ( layer->hasScaleBasedVisibility() ) {
324
          if ( layer->minimumScale() <= scaleValue &&
325
               layer->maximumScale() >= scaleValue )
326
            newLayerIds.push_front( layer->id() );
327
        } else {
328
          newLayerIds.push_front( layer->id() );
329
        }
330
      }
331
      layerIds = newLayerIds;
332
    }
333
  }
334

  
335

  
302 336
  QgsLegendModel legendModel;
303 337
  legendModel.setLayerSet( layerIds );
304 338

  
305
-