/// <summary> /// Converts any <see cref=GisSharpBlog.NetTopologySuite.Geometries.Geometry"/> to the correspondant /// <see cref="SharpMap.Geometries.Geometry"/>. /// </summary> /// <param name="geometry"></param> /// <returns></returns> public static GisSharpBlog.NetTopologySuite.Geometries.Geometry ToNTSGeometry(SharpMap.Geometries.Geometry geometry, GisSharpBlog.NetTopologySuite.Geometries.GeometryFactory factory) { if (geometry == null) throw new NullReferenceException("geometry"); if (geometry.GetType() == typeof(SharpMap.Geometries.Point)) return ToNTSPoint(geometry as SharpMap.Geometries.Point, factory); else if (geometry.GetType() == typeof(SharpMap.Geometries.LineString)) return ToNTSLineString(geometry as SharpMap.Geometries.LineString, factory); else if (geometry.GetType() == typeof(SharpMap.Geometries.Polygon)) return ToNTSPolygon(geometry as SharpMap.Geometries.Polygon, factory); else if (geometry.GetType() == typeof(SharpMap.Geometries.MultiPoint)) return ToNTSMultiPoint(geometry as SharpMap.Geometries.MultiPoint, factory); else if (geometry.GetType() == typeof(SharpMap.Geometries.MultiLineString)) return ToNTSMultiLineString(geometry as SharpMap.Geometries.MultiLineString, factory); else if (geometry.GetType() == typeof(SharpMap.Geometries.MultiPolygon)) return ToNTSMultiPolygon(geometry as SharpMap.Geometries.MultiPolygon, factory); else if (geometry.GetType() == typeof(SharpMap.Geometries.GeometryCollection)) return ToNTSGeometryCollection(geometry as SharpMap.Geometries.GeometryCollection, factory); else throw new NotSupportedException("Type " + geometry.GetType().FullName + " not supported"); }
protected override SharpMap.Rendering.Label CreateLabel(SharpMap.Geometries.Geometry feature, string text, float rotation, SharpMap.Styles.LabelStyle style, Map map, System.Drawing.Graphics g) { //System.Drawing.SizeF size = g.MeasureString(text, style.Font); System.Drawing.PointF position = map.WorldToImage(feature.GetBoundingBox().GetCentroid()); //position.X = position.X - size.Width * (short)style.HorizontalAlignment * 0.5f; //position.Y = position.Y - size.Height * (short)style.VerticalAlignment * 0.5f; if (position.X /*- size.Width*/ > map.Size.Width || position.X /*+ size.Width */< 0 || position.Y /*- size.Height*/ > map.Size.Height || position.Y /*+ size.Height*/ < 0) return null; else { SharpMap.Rendering.Label lbl; if (!style.CollisionDetection) lbl = new SharpMap.Rendering.Label(text, position, rotation, this.Priority, null, style); else { //Collision detection is enabled so we need to measure the size of the string lbl = new SharpMap.Rendering.Label(text, position, rotation, this.Priority, new SharpMap.Rendering.LabelBox(position.X /*- size.Width * 0.5f*/ - style.CollisionBuffer.Width, position.Y + /*size.Height * 0.5f*/ + style.CollisionBuffer.Height, /*size.Width +*/ 2f * style.CollisionBuffer.Width, /*size.Height +*/ style.CollisionBuffer.Height * 2f), style); } if (feature.GetType() == typeof(SharpMap.Geometries.LineString)) { SharpMap.Geometries.LineString line = feature as SharpMap.Geometries.LineString; if (line.Length / map.PixelSize > 40/*size.Width*/) //Only label feature if it is long enough CalculateLabelOnLinestring(line, ref lbl, map); else return null; } return lbl; } }
private static XmlNode GetWmsLayerNode(SharpMap.Layers.ILayer layer, XmlDocument doc) { XmlNode LayerNode = doc.CreateNode(XmlNodeType.Element, "Layer", wmsNamespaceURI); LayerNode.AppendChild(CreateElement("Name", layer.LayerName, doc, false, wmsNamespaceURI)); LayerNode.AppendChild(CreateElement("Title", layer.LayerName, doc, false, wmsNamespaceURI)); //If this is a grouplayer, add childlayers recursively if (layer.GetType() == typeof(SharpMap.Layers.LayerGroup)) foreach (SharpMap.Layers.Layer childlayer in ((SharpMap.Layers.LayerGroup)layer).Layers) LayerNode.AppendChild(GetWmsLayerNode(childlayer, doc)); LayerNode.AppendChild(GenerateBoundingBoxElement(layer.Envelope, layer.SRID, doc)); return LayerNode; }
private HtmlGenericControl LegendDiv(SharpMap.Layers.ILayer myLayer) { HtmlGenericControl legendDiv = new HtmlGenericControl("div"); legendDiv.Style.Add("width", "2em"); legendDiv.Style.Add("overflow", "hidden"); legendDiv.Style.Add("position", "absolute"); legendDiv.Style.Add("margin-left", "0.5em"); legendDiv.Style.Add("margin-bottom", "0px"); if (myLayer.GetType() == typeof(SharpMap.Layers.VectorLayer)) { SharpMap.Layers.VectorLayer myVectorLayer = (myLayer as SharpMap.Layers.VectorLayer); SharpMap.Styles.VectorStyle myStyle = new SharpMap.Styles.VectorStyle(); if (myVectorLayer.Theme != null) { if (myVectorLayer.Theme.GetType() == typeof(SharpMap.Rendering.Thematics.CustomTheme)) { SharpMap.Rendering.Thematics.CustomTheme myTheme = (myVectorLayer.Theme as SharpMap.Rendering.Thematics.CustomTheme); myStyle = (myTheme.DefaultStyle as SharpMap.Styles.VectorStyle); } else if (myVectorLayer.Theme.GetType() == typeof(SharpMap.Rendering.Thematics.GradientTheme)) { SharpMap.Rendering.Thematics.GradientTheme myTheme = (myVectorLayer.Theme as SharpMap.Rendering.Thematics.GradientTheme); myStyle = (myTheme.MinStyle as SharpMap.Styles.VectorStyle); } } else myStyle = myVectorLayer.Style; if (myStyle.Outline.Color.Name.ToString() != "Black") { string lineStyle = (myStyle.Outline.DashStyle.ToString() == "Dash") ? "dotted" : "solid"; legendDiv.Style.Add("border", lineStyle + " " + myStyle.Outline.Width.ToString() + "px " + ColorToHex(myStyle.Outline.Color)); legendDiv.Style.Add("height", "1em"); } else { string lineStyle = (myStyle.Line.DashStyle.ToString() == "Dash") ? "dotted" : "solid"; legendDiv.Style.Add("border-bottom", lineStyle + " " + myStyle.Line.Width.ToString() + "px " + ColorToHex(myStyle.Line.Color)); legendDiv.Style.Add("height", "0.8em"); } System.Drawing.SolidBrush fillBrush = (myVectorLayer.Style.Fill as System.Drawing.SolidBrush); if (fillBrush.Color.Name.ToString() != "Black") { HtmlGenericControl fillDiv = new HtmlGenericControl("div"); fillDiv.Style.Add("border-left", "solid 2em " + ColorToHex(fillBrush.Color)); fillDiv.Style.Add("height", "1.2em"); fillDiv.Style.Add("overflow", "hidden"); fillDiv.Style.Add("opacity ", ColorAlpha(fillBrush.Color) + "%"); fillDiv.Style.Add("filter", "ALPHA(opacity=" + ColorAlpha(fillBrush.Color) + ")"); legendDiv.Controls.Add(fillDiv); } } return legendDiv; }