-
Notifications
You must be signed in to change notification settings - Fork 305
Expand file tree
/
Copy pathILayer.cs
More file actions
162 lines (132 loc) · 5.3 KB
/
ILayer.cs
File metadata and controls
162 lines (132 loc) · 5.3 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
// Copyright 2005, 2006 - Morten Nielsen (www.iter.dk)
//
// This file is part of SharpMap.
// SharpMap is free software; you can redistribute it and/or modify
// it under the terms of the GNU Lesser General Public License as published by
// the Free Software Foundation; either version 2 of the License, or
// (at your option) any later version.
//
// SharpMap is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU Lesser General Public License for more details.
// You should have received a copy of the GNU Lesser General Public License
// along with SharpMap; if not, write to the Free Software
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
using System;
using System.Drawing;
using GeoAPI.Geometries;
namespace SharpMap.Layers
{
/// <summary>
/// Interface for map layers
/// </summary>
public interface ILayer
{
/// <summary>
/// Minimum visible zoom level
/// </summary>
double MinVisible { get; set; }
/// <summary>
/// Minimum visible zoom level
/// </summary>
double MaxVisible { get; set; }
/// <summary>
/// Gets or Sets what level-reference the Min/Max values are defined in
/// </summary>
Styles.VisibilityUnits VisibilityUnits { get; set; }
/// <summary>
/// Specifies whether this layer should be rendered or not
/// </summary>
bool Enabled { get; set; }
/// <summary>
/// Name of layer
/// </summary>
string LayerName { get; set; }
/// <summary>
/// Optional title of layer. It will be used for services like WMS where both Name and Title are supported.
/// </summary>
string LayerTitle { get; set; }
/// <summary>
/// Gets the boundingbox of the entire layer
/// </summary>
Envelope Envelope { get; }
/// <summary>
/// The spatial reference ID (CRS)
/// </summary>
int SRID { get; set; }
/// <summary>
/// The spatial reference ID (CRS) that can be exposed externally.
/// </summary>
/// <remarks>
/// TODO: explain better why I need this property
/// </remarks>
int TargetSRID { get; }
/// <summary>
/// Proj4 String Projection
/// </summary>
string Proj4Projection { get; set; }
/// <summary>
/// Renders the layer
/// </summary>
/// <param name="g">Graphics object reference</param>
/// <param name="map">Map which is rendered</param>
[Obsolete("Use Render(Graphics, MapViewport)")]
void Render(Graphics g, Map map);
/// <summary>
/// Renders the layer using the current viewport
/// </summary>
/// <param name="g">Graphics object reference</param>
/// <param name="map">Map which is rendered</param>
void Render(Graphics g, MapViewport map);
//SharpMap.CoordinateSystems.CoordinateSystem CoordinateSystem { get; set; }
}
internal static class LayerExtensions
{
public static bool DoRender(this ILayer self, Graphics g, Map map )
{
// Is the layer enabled for rendering at all
if (!self.Enabled)
return false;
// Get the compare value, zoom or scale
var compare = self.VisibilityUnits == Styles.VisibilityUnits.ZoomLevel
? map.Zoom
: map.GetMapScale((int) g.DpiX);
// Is the layer enabled for the current scale
if (self.MinVisible <= compare || compare <= self.MaxVisible)
return false;
// Does the layer intersect the viewport at all
if (!self.Envelope.Intersects(map.Envelope))
return false;
return true;
}
public static bool DoRender(this ILayer self, Graphics g, MapViewport map)
{
// Is the layer enabled for rendering at all
if (!self.Enabled)
return false;
// Get the compare value, zoom or scale
var compare = self.VisibilityUnits == Styles.VisibilityUnits.ZoomLevel
? map.Zoom
: map.GetMapScale((int)g.DpiX);
// Is the layer enabled for the current scale
if (self.MinVisible <= compare || compare <= self.MaxVisible)
return false;
// Does the layer intersect the viewport at all
if (!self.Envelope.Intersects(map.Envelope))
return false;
return true;
}
public static bool DoRender(this Styles.IStyle self, Graphics g, Map map)
{
if (!self.Enabled)
return false;
var compare = self.VisibilityUnits == Styles.VisibilityUnits.ZoomLevel
? map.Zoom
: map.GetMapScale((int)g.DpiX);
if (self.MinVisible <= compare || compare <= self.MaxVisible)
return false;
return true;
}
}
}