ThinkGeo Cloud
ThinkGeo UI Controls
ThinkGeo Open Source
Help and Support
External Resources
ThinkGeo Cloud
ThinkGeo UI Controls
ThinkGeo Open Source
Help and Support
External Resources
using System; using System.Collections.Generic; using System.Linq; using System.Windows.Forms; namespace WorldSizedImageStyle { static class Program { /// <summary> /// The main entry point for the application. /// </summary> [STAThread] static void Main() { Application.EnableVisualStyles(); Application.SetCompatibleTextRenderingDefault(false); Application.Run(new TestForm()); } } }
using System; using System.Collections.ObjectModel; using System.Drawing; using System.Windows.Forms; using ThinkGeo.MapSuite.Core; namespace WorldSizedImageStyle { public partial class TestForm : Form { private MapEngine mapEngine = new MapEngine(); private Bitmap bitmap = null; public TestForm() { InitializeComponent(); } private void TestForm_Load(object sender, EventArgs e) { // Set the extent and the background color mapEngine.CurrentExtent = ExtentHelper.GetDrawingExtent(new RectangleShape(-80.1732,25.7736,-80.1568,25.7643), Map.Width, Map.Height); mapEngine.BackgroundFillBrush = new GeoSolidBrush(GeoColor.GeographicColors.ShallowOcean); //Displays the World Map Kit as a background. ThinkGeo.MapSuite.Core.WorldMapKitLayer worldMapKitLayer = new ThinkGeo.MapSuite.Core.WorldMapKitLayer(); mapEngine.StaticLayers.Add(worldMapKitLayer); //Adds the InMemoryFeatureLayer for dsiplaying real world sized ship. InMemoryFeatureLayer shipInMemoryFeatureLayer = new InMemoryFeatureLayer(); GeoImage geoImage = new GeoImage(@"..\..\data\cruiseship2.png"); //Creates WorldSizedImageStyle for displaying a ship of the dimension of 300 by 90 meters at an angle of 335 degrees. WorldSizedImageStyle worldSizedImageStyle = new WorldSizedImageStyle(geoImage,GeographyUnit.DecimalDegree, 300, 90, DistanceUnit.Meter, 335); shipInMemoryFeatureLayer.ZoomLevelSet.ZoomLevel01.CustomStyles.Clear(); shipInMemoryFeatureLayer.ZoomLevelSet.ZoomLevel01.CustomStyles.Add(worldSizedImageStyle); shipInMemoryFeatureLayer.ZoomLevelSet.ZoomLevel01.ApplyUntilZoomLevel = ApplyUntilZoomLevel.Level20; shipInMemoryFeatureLayer.InternalFeatures.Add(new Feature(new PointShape(-80.1666,25.7688))); mapEngine.DynamicLayers.Add(shipInMemoryFeatureLayer); //Adds a ScaleBarAdornmentLayer to the map to have a distance reference. ScaleBarAdornmentLayer scaleBarAdornmentLayer = new ScaleBarAdornmentLayer(); scaleBarAdornmentLayer.Location = AdornmentLocation.LowerLeft; scaleBarAdornmentLayer.UnitFamily = UnitSystem.Metric; mapEngine.AdornmentLayers.Add(scaleBarAdornmentLayer); DrawImage(); } private void DrawImage() { if (bitmap != null) { bitmap.Dispose(); } bitmap = new Bitmap(Map.Width, Map.Height); mapEngine.OpenAllLayers(); mapEngine.DrawStaticLayers(bitmap, GeographyUnit.DecimalDegree); mapEngine.DrawDynamicLayers(bitmap, GeographyUnit.DecimalDegree); mapEngine.DrawAdornmentLayers(bitmap, GeographyUnit.DecimalDegree); mapEngine.CloseAllLayers(); Map.Image = bitmap; } private void ToolBar_ButtonClick(object sender, ToolBarButtonClickEventArgs e) { switch (e.Button.Tag.ToString()) { case "Zoom In": mapEngine.CurrentExtent.ScaleDown(50); break; case "Zoom Out": mapEngine.CurrentExtent.ScaleUp(50); break; case "Full Extent": mapEngine.CurrentExtent = ExtentHelper.GetDrawingExtent(new RectangleShape(-180.0, 83.0, 180.0, -90.0), Map.Width, Map.Height); break; case "Pan Left": mapEngine.CurrentExtent = ExtentHelper.Pan(mapEngine.CurrentExtent, PanDirection.Left, 20); break; case "Pan Right": mapEngine.CurrentExtent = ExtentHelper.Pan(mapEngine.CurrentExtent, PanDirection.Right, 20); break; case "Pan Up": mapEngine.CurrentExtent = ExtentHelper.Pan(mapEngine.CurrentExtent, PanDirection.Up, 20); break; case "Pan Down": mapEngine.CurrentExtent = ExtentHelper.Pan(mapEngine.CurrentExtent, PanDirection.Down, 20); break; default: break; } DrawImage(); } private void btnClose_Click(object sender, EventArgs e) { this.Close(); } private void Map_MouseMove(object sender, MouseEventArgs e) { //Displays the X and Y in screen coordinates. statusStrip1.Items["toolStripStatusLabelScreen"].Text = "X:" + e.X + " Y:" + e.Y; //Gets the PointShape in world coordinates from screen coordinates. PointShape pointShape = ExtentHelper.ToWorldCoordinate(mapEngine.CurrentExtent, new ScreenPointF(e.X, e.Y), Map.Width, Map.Height); //Displays world coordinates. statusStrip1.Items["toolStripStatusLabelWorld"].Text = "(world) X:" + Math.Round(pointShape.X, 4) + " Y:" + Math.Round(pointShape.Y, 4); } } }
using System.Collections.Generic; using System.Collections.ObjectModel; using ThinkGeo.MapSuite.Core; namespace WorldSizedImageStyle { class WorldSizedImageStyle : Style { private GeoImage image = null; private GeographyUnit mapUnit; private DistanceUnit imageUnit; private double imageWorldWidth; private double imageWorldHeight; private float rotateAngle; public WorldSizedImageStyle() : this(null,GeographyUnit.DecimalDegree, 500, 500,DistanceUnit.Meter,0) { } public WorldSizedImageStyle(GeoImage geoImage, GeographyUnit MapUnit, double ImageWorldWidth, double ImageWorldHeight, DistanceUnit ImageUnit,float RotateAngle) { this.image = geoImage; this.mapUnit = MapUnit; this.imageWorldWidth = ImageWorldWidth; this.imageWorldHeight = ImageWorldHeight; this.imageUnit = ImageUnit; this.rotateAngle = RotateAngle; } public GeographyUnit MapUnit { get { return mapUnit; } set { mapUnit = value; } } public double ImageWorldWidth { get { return imageWorldWidth; } set { imageWorldWidth = value; } } public double ImageWorldHeight { get { return imageWorldHeight; } set { imageWorldHeight = value; } } public DistanceUnit ImageUnit { get { return imageUnit; } set { imageUnit = value; } } public GeoImage Image { get { return image; } set { image = value; } } public float RotateAngle { get { return rotateAngle; } set { rotateAngle = value; } } protected override void DrawCore(IEnumerable<Feature> features, GeoCanvas canvas, Collection<SimpleCandidate> labelsInThisLayer, Collection<SimpleCandidate> labelsInAllLayers) { // First let's make sure the image isn't null. if (image != null) { //Gets the proper image width and height size according to the current extent height. (meter is used as base unit) double canvasWidthMeter; double canvasHeightMeter; double imageWidthMeter = Conversion.ConvertMeasureUnits(imageWorldWidth, imageUnit, DistanceUnit.Meter); double imageHeightMeter = Conversion.ConvertMeasureUnits(imageWorldHeight, imageUnit, DistanceUnit.Meter); //if the mapunit is in Decimal Degrees, it uses a different logic than with other mapunits such as meters and feet. if (mapUnit == GeographyUnit.DecimalDegree) { try { canvasWidthMeter = DecimalDegreesHelper.GetDistanceFromDecimalDegrees(canvas.CurrentWorldExtent.UpperLeftPoint.X, canvas.CurrentWorldExtent.UpperLeftPoint.Y, canvas.CurrentWorldExtent.UpperRightPoint.X, canvas.CurrentWorldExtent.UpperRightPoint.Y, DistanceUnit.Meter); canvasHeightMeter = DecimalDegreesHelper.GetDistanceFromDecimalDegrees(canvas.CurrentWorldExtent.UpperLeftPoint.X, canvas.CurrentWorldExtent.UpperLeftPoint.Y, canvas.CurrentWorldExtent.LowerLeftPoint.X, canvas.CurrentWorldExtent.LowerLeftPoint.Y, DistanceUnit.Meter); } catch { canvasWidthMeter = DecimalDegreesHelper.GetDistanceFromDecimalDegrees(180, 90, -180, 90, DistanceUnit.Meter); canvasHeightMeter = DecimalDegreesHelper.GetDistanceFromDecimalDegrees(180, 90, 180, -90, DistanceUnit.Meter); } finally { } } else { DistanceUnit fromUnit = DistanceUnit.Meter; if (mapUnit == GeographyUnit.Feet) fromUnit = DistanceUnit.Feet; canvasWidthMeter = Conversion.ConvertMeasureUnits(canvas.CurrentWorldExtent.Width, fromUnit, DistanceUnit.Meter); canvasHeightMeter = Conversion.ConvertMeasureUnits(canvas.CurrentWorldExtent.Height, fromUnit, DistanceUnit.Meter); } float widthSize = (float)((imageWidthMeter * canvas.Width) / canvasWidthMeter); //fontSize float heightSize = (float)((imageHeightMeter * canvas.Height) / canvasHeightMeter); //fontSize // Loop through all of the features being passed in to draw. foreach (Feature feature in features) { // Let's make sure the features being passed in are points or multi points. WellKnownType shapeWellKnownType = feature.GetWellKnownType(); if (shapeWellKnownType == WellKnownType.Point || shapeWellKnownType == WellKnownType.Multipoint) { // Call the canvas method to draw the image scaled. PointShape point = new PointShape(feature.GetWellKnownBinary()); canvas.DrawWorldImage(image, point.X, point.Y, widthSize, heightSize, DrawingLevel.LevelOne, 0, 0, rotateAngle); } } } } } }