@@ -114,6 +114,7 @@ public enum MultipartGeometryBehaviourEnum
114114 private GetLabelMethod _getLabelMethod ;
115115 private GetPriorityMethod _getPriorityMethod ;
116116 private GetLocationMethod _getLocationMethod ;
117+ private Envelope _envelope ;
117118
118119 /// <summary>
119120 /// Name of the column that holds the value for the label.
@@ -198,7 +199,11 @@ public TextRenderingHint TextRenderingHint
198199 public IProvider DataSource
199200 {
200201 get { return _dataSource ; }
201- set { _dataSource = value ; }
202+ set
203+ {
204+ _dataSource = value ;
205+ _envelope = null ;
206+ }
202207 }
203208
204209 /// <summary>
@@ -334,16 +339,36 @@ public override Envelope Envelope
334339 {
335340 get
336341 {
342+ if ( DataSource == null )
343+ throw ( new ApplicationException ( "DataSource property not set on layer '" + LayerName + "'" ) ) ;
344+
345+ if ( _envelope != null && CacheExtent )
346+ return ToTarget ( _envelope . Clone ( ) ) ;
347+
337348 var wasOpen = DataSource . IsOpen ;
338349 if ( ! wasOpen )
339350 DataSource . Open ( ) ;
340351 var box = DataSource . GetExtents ( ) ;
341352 if ( ! wasOpen ) //Restore state
342353 DataSource . Close ( ) ;
354+
355+ if ( CacheExtent )
356+ _envelope = box ;
357+
343358 return ToTarget ( box ) ;
344359 }
345360 }
346361
362+ /// <summary>
363+ /// Gets or sets a value indicating whether the layer envelope should be treated as static or not.
364+ /// </summary>
365+ /// <remarks>
366+ /// When CacheExtent is enabled the layer Envelope will be calculated only once from DataSource, this
367+ /// helps to speed up the Envelope calculation with some DataProviders. Default is false for backward
368+ /// compatibility.
369+ /// </remarks>
370+ public virtual bool CacheExtent { get ; set ; }
371+
347372 /// <summary>
348373 /// Gets or sets the SRID of this VectorLayer's data source
349374 /// </summary>
@@ -404,29 +429,19 @@ public override void Render(Graphics g, Map map)
404429 //Initialize label collection
405430 var labels = new List < BaseLabel > ( ) ;
406431
407- // Get the compare value for min/max visible. We assume the theme has the same visibility units as the main style
408- var compareValue = Style . VisibilityUnits == VisibilityUnits . ZoomLevel ? map . Zoom : map . MapScale ;
409-
410- // Set the style to use
411- var style = Style ;
412-
432+ //List<System.Drawing.Rectangle> LabelBoxes; //Used for collision detection
413433 //Render labels
434+
414435 for ( int i = 0 ; i < features . Count ; i ++ )
415436 {
416437 var feature = features [ i ] ;
438+ feature . Geometry = ToTarget ( feature . Geometry ) ;
417439
418- // Thematics?
419- if ( Theme != null )
420- {
421- //If thematics is enabled, lets override the style
440+ LabelStyle style ;
441+ if ( Theme != null ) //If thematics is enabled, lets override the style
422442 style = Theme . GetStyle ( feature ) as LabelStyle ;
423- // Check if this style is to be rendered at all
424- if ( style == null ) { continue ; }
425- if ( ! ( style . Enabled && style . MaxVisible >= compareValue && Style . MinVisible < compareValue ) ) continue ;
426- }
427-
428- // Transform the geometry for the target
429- feature . Geometry = ToTarget ( feature . Geometry ) ;
443+ else
444+ style = Style ;
430445
431446 float rotationStyle = style != null ? style . Rotation : 0f ;
432447 float rotationColumn = 0f ;
@@ -580,7 +595,6 @@ public override void Render(Graphics g, Map map)
580595 lblStyle . GetStringFormat ( ) , lblStyle . IgnoreLength , plbl . Location ) ;
581596 }
582597 }
583-
584598 }
585599 base . Render ( g , map ) ;
586600 }
@@ -664,12 +678,9 @@ private static BaseLabel CreateLabel(FeatureDataRow fdr, IGeometry feature, stri
664678 lbl = new Label ( text , location , rotation , priority ,
665679 new LabelBox ( location . X - style . CollisionBuffer . Width ,
666680 location . Y - style . CollisionBuffer . Height ,
667- size . Width + 2f * style . CollisionBuffer . Width ,
668- size . Height + 2f * style . CollisionBuffer . Height ) , style )
669- {
670- LabelPoint = position ,
671- Priority = priority ,
672- } ;
681+ size . Width + 2f * style . CollisionBuffer . Width ,
682+ size . Height + 2f * style . CollisionBuffer . Height ) , style )
683+ { LabelPoint = position } ;
673684 }
674685
675686 /*
0 commit comments