📄 map.cs
字号:
/// Rotate the map output 45 degrees around its center:
/// <code lang="C#">
/// System.Drawing.Drawing2D.Matrix maptransform = new System.Drawing.Drawing2D.Matrix(); //Create transformation matrix
/// maptransform.RotateAt(45,new PointF(myMap.Size.Width/2,myMap.Size.Height/2)); //Apply 45 degrees rotation around the center of the map
/// myMap.MapTransform = maptransform; //Apply transformation to map
/// </code>
/// </example>
public System.Drawing.Drawing2D.Matrix MapTransform
{
get { return _MapTransform; }
set
{
_MapTransform = value;
if (_MapTransform.IsInvertible)
{
MapTransformInverted = _MapTransform.Clone();
MapTransformInverted.Invert();
}
else
MapTransformInverted.Reset();
}
}
private List<SharpMap.Layers.ILayer> _Layers;
/// <summary>
/// A collection of layers. The first layer in the list is drawn first, the last one on top.
/// </summary>
public System.Collections.Generic.List<SharpMap.Layers.ILayer> Layers
{
get { return _Layers; }
set {
int iBefore = 0;
if (_Layers != null)
iBefore = _Layers.Count;
_Layers = value;
if (value != null)
{
if (LayersChanged != null) //Layers changed. Fire event
LayersChanged();
if (MapViewOnChange != null)
MapViewOnChange();
}
}
}
private System.Drawing.Color _BackgroundColor;
/// <summary>
/// Map background color (defaults to transparent)
/// </summary>
public System.Drawing.Color BackColor
{
get { return _BackgroundColor; }
set
{
_BackgroundColor = value;
if (MapViewOnChange != null)
MapViewOnChange();
}
}
private SharpMap.Geometries.Point _Center;
/// <summary>
/// Center of map in WCS
/// </summary>
public SharpMap.Geometries.Point Center
{
get { return _Center; }
set {
_Center = value;
if (MapViewOnChange != null)
MapViewOnChange();
}
}
private double _Zoom;
/// <summary>
/// Gets or sets the zoom level of map.
/// </summary>
/// <remarks>
/// <para>The zoom level corresponds to the width of the map in WCS units.</para>
/// <para>A zoomlevel of 0 will result in an empty map being rendered, but will not throw an exception</para>
/// </remarks>
public double Zoom
{
get { return _Zoom; }
set {
if (value < _MinimumZoom)
_Zoom = _MinimumZoom;
else if (value > _MaximumZoom)
_Zoom = _MaximumZoom;
else
_Zoom = value;
if (MapViewOnChange != null)
MapViewOnChange();
}
}
/// <summary>
/// Gets the extents of the map based on the extents of all the layers in the layers collection
/// </summary>
/// <returns>Full map extents</returns>
public SharpMap.Geometries.BoundingBox GetExtents()
{
if (this.Layers == null || this.Layers.Count == 0)
throw (new InvalidOperationException("No layers to zoom to"));
SharpMap.Geometries.BoundingBox bbox = null;
for (int i = 0; i < this.Layers.Count; i++)
{
if (bbox == null)
bbox = this.Layers[i].Envelope;
else
bbox = bbox.Join(this.Layers[i].Envelope);
}
return bbox;
}
/// <summary>
/// Returns the size of a pixel in world coordinate units
/// </summary>
public double PixelSize
{
get { return this.Zoom / this.Size.Width; }
}
/// <summary>
/// Returns the width of a pixel in world coordinate units.
/// </summary>
/// <remarks>The value returned is the same as <see cref="PixelSize"/>.</remarks>
public double PixelWidth
{
get { return PixelSize; }
}
/// <summary>
/// Returns the height of a pixel in world coordinate units.
/// </summary>
/// <remarks>The value returned is the same as <see cref="PixelSize"/> unless <see cref="PixelAspectRatio"/> is different from 1.</remarks>
public double PixelHeight
{
get { return PixelSize * _PixelAspectRatio; }
}
private double _PixelAspectRatio = 1.0;
/// <summary>
/// Gets or sets the aspect-ratio of the pixel scales. A value less than
/// 1 will make the map streach upwards, and larger than 1 will make it smaller.
/// </summary>
/// <exception cref="ArgumentException">Throws an argument exception when value is 0 or less.</exception>
public double PixelAspectRatio
{
get { return _PixelAspectRatio; }
set {
if (_PixelAspectRatio <= 0)
throw new ArgumentException("Invalid Pixel Aspect Ratio");
_PixelAspectRatio = value; }
}
/// <summary>
/// Height of map in world units
/// </summary>
/// <returns></returns>
public double MapHeight
{
get { return (this.Zoom * this.Size.Height) / this.Size.Width * this.PixelAspectRatio; }
}
private System.Drawing.Size _Size;
/// <summary>
/// Size of output map
/// </summary>
public System.Drawing.Size Size
{
get { return _Size; }
set { _Size = value; }
}
private double _MinimumZoom;
/// <summary>
/// Minimum zoom amount allowed
/// </summary>
public double MinimumZoom
{
get { return _MinimumZoom; }
set {
if (value < 0)
throw (new ArgumentException("Minimum zoom must be 0 or more"));
_MinimumZoom = value;
}
}
private double _MaximumZoom;
/// <summary>
/// Maximum zoom amount allowed
/// </summary>
public double MaximumZoom
{
get { return _MaximumZoom; }
set {
if (value <= 0)
throw (new ArgumentException("Maximum zoom must larger than 0"));
_MaximumZoom = value;
}
}
#endregion
//#region ISerializable Members
///// <summary>
///// Populates a SerializationInfo with the data needed to serialize the target object.
///// </summary>
///// <param name="info"></param>
///// <param name="context"></param>
//public void GetObjectData(System.Runtime.Serialization.SerializationInfo info, System.Runtime.Serialization.StreamingContext context)
//{
// System.Runtime.Serialization.SurrogateSelector ss = SharpMap.Utilities.Surrogates.GetSurrogateSelectors();
// info.AddValue("BackgroundColor", this._BackgroundColor);
// info.AddValue("Center", this._Center);
// info.AddValue("Layers", this._Layers);
// info.AddValue("MapTransform", this._MapTransform);
// info.AddValue("MaximumZoom", this._MaximumZoom);
// info.AddValue("MinimumZoom", this._MinimumZoom);
// info.AddValue("Size", this._Size);
// info.AddValue("Zoom", this._Zoom);
//}
///// <summary>
///// Deserialization constructor.
///// </summary>
///// <param name="info"></param>
///// <param name="ctxt"></param>
//internal Map(System.Runtime.Serialization.SerializationInfo info, System.Runtime.Serialization.StreamingContext ctxt)
//{
// this._BackgroundColor = (System.Drawing.Color)info.GetValue("BackgroundColor", typeof(System.Drawing.Color));
// this._Center = (SharpMap.Geometries.Point)info.GetValue("Center", typeof(SharpMap.Geometries.Point));
// this._Layers = (List<SharpMap.Layers.ILayer>)info.GetValue("Layers", typeof(List<SharpMap.Layers.ILayer>));
// this._MapTransform = (System.Drawing.Drawing2D.Matrix)info.GetValue("MapTransform", typeof(System.Drawing.Drawing2D.Matrix));
// this._MaximumZoom = info.GetDouble("MaximumZoom");
// this._MinimumZoom = info.GetDouble("MinimumZoom");
// this._Size = (System.Drawing.Size)info.GetValue("Size", typeof(System.Drawing.Size));
// this._Zoom = info.GetDouble("Zoom");
//}
//#endregion
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -