I was looking at the examples, but I could not find one that shows how to draw static circles and/or lines. For instance, I want to draw a circle on the map window that does not change when panning or zooming. Think of it as a crosshair in the middle of the map. Can someone point me in the right direction?... Thanks!
Draw Static Circle and Cross Hairs on Map
Michael,
We have AdormentLayers for the purpose of drawing things on the map that are not going to change position as you pan or zoom. I have an example where I draw a cross hair in the middle of the map. The cross hair is an image. If you want to be able to actually draw programatically with vectors for the adornments, let us know and we will point you how to accomplish that with some sample codes. But for now, I want to check with you if what is currently presented to you is in the right direction. Thank you.
GeoImage geoImage = new GeoImage(@"C:\ThinkGeo\Support\MapData\Crosshair.png");
LogoAdornmentLayer logoAdornmentLayer = new LogoAdornmentLayer(geoImage);
logoAdornmentLayer.Location = AdornmentLocation.Center;
logoAdornmentLayer.XOffsetInPixel = - (geoImage.GetWidth() / 2);
logoAdornmentLayer.YOffsetInPixel = -(geoImage.GetHeight() / 2);
AdornmentOverlay adormentOverlay = new AdornmentOverlay();
adormentOverlay.Layers.Add(logoAdornmentLayer);
wpfMap1.Overlays.Add(adormentOverlay);
Hi Val... Yes, you are on the exact right track. Now, I just need to be able to do it with vectors so that I can dynamically change the size of the circles and lines.
Thanks!
Mike
Michael,
Ok. I created a little sample with the crosshair drawn in vector for you where you can set the size in world unit. For example, here I have the crosshair of the size of 50 miles. That way, you can see the crosshair changing size relative to the screen when you zoom in and out. I think this is a good start for you so that you can adapt for your exact case. Notice that I got inspired by the sample World Sized Text Style in the Code Community wiki.thinkgeo.com/wiki/Map_Suite_De...Text_Style
You can see that I inherited from AdornmentLayer to create a custom CrossHairAdornmentLayer where I overwrote the DrawCore function for the drawing logic. CrossHairAdornmentLayer is already pretty complete as it is and you can use it with the map in decimal degrees, meter or feet.
using System.Collections.ObjectModel;
using ThinkGeo.MapSuite.Core;
class CrosshairAdornmentLayer : AdornmentLayer
{
private GeographyUnit mapUnit;
private double crossHairWorldSize;
private DistanceUnit crossHairUnit;
public GeographyUnit MapUnit
{
get { return mapUnit; }
set { mapUnit = value; }
}
public double CrossHairWorldSize
{
get { return crossHairWorldSize; }
set { crossHairWorldSize = value; }
}
public DistanceUnit CrossHairUnit
{
get { return crossHairUnit; }
set { crossHairUnit = value; }
}
protected override void DrawCore(GeoCanvas canvas, System.Collections.ObjectModel.Collection<SimpleCandidate> labelsInAllLayers)
{
double canvasHeightMeter;
double textSizeMeter = Conversion.ConvertMeasureUnits(crossHairWorldSize, crossHairUnit, DistanceUnit.Meter);
if (canvas.MapUnit == GeographyUnit.DecimalDegree)
{
try
{
canvasHeightMeter = DecimalDegreesHelper.GetDistanceFromDecimalDegrees(canvas.CurrentWorldExtent.UpperLeftPoint.X,
canvas.CurrentWorldExtent.UpperLeftPoint.Y, canvas.CurrentWorldExtent.LowerLeftPoint.X,
canvas.CurrentWorldExtent.LowerLeftPoint.Y, DistanceUnit.Meter);
}
catch { canvasHeightMeter = DecimalDegreesHelper.GetDistanceFromDecimalDegrees(180, 90, 180, -90, DistanceUnit.Meter); }
finally { }
}
else
{
DistanceUnit fromUnit = DistanceUnit.Meter;
if (mapUnit == GeographyUnit.Feet) fromUnit = DistanceUnit.Feet;
canvasHeightMeter = Conversion.ConvertMeasureUnits(canvas.CurrentWorldExtent.Height, fromUnit, DistanceUnit.Meter);
}
float crossHairSize = (float)((textSizeMeter * canvas.Height) / canvasHeightMeter);
PointShape pointShape = ExtentHelper.ToWorldCoordinate(canvas.CurrentWorldExtent, new ScreenPointF(canvas.Width / 2, canvas.Height / 2),
canvas.Width, canvas.Height);
canvas.DrawEllipse(pointShape, crossHairSize, crossHairSize, new GeoPen(GeoColor.StandardColors.Black, 2), DrawingLevel.LabelLevel);
float centerScreenX = canvas.Width / 2;
float centerScreenY = canvas.Height / 2;
canvas.DrawLine(new Collection<ScreenPointF>() { new ScreenPointF(centerScreenX - (crossHairSize /2) - 6, centerScreenY),
new ScreenPointF(centerScreenX + (crossHairSize /2) + 6, centerScreenY) },
new GeoPen(GeoColor.StandardColors.Black, 2), DrawingLevel.LabelLevel, 0, 0);
canvas.DrawLine(new Collection<ScreenPointF>() { new ScreenPointF(centerScreenX , centerScreenY - (crossHairSize /2) - 6),
new ScreenPointF(centerScreenX , centerScreenY + (crossHairSize /2) + 6) },
new GeoPen(GeoColor.StandardColors.Black, 2), DrawingLevel.LabelLevel, 0, 0);
}
CrosshairAdornmentLayer crossHairAdornmentLayer = new CrosshairAdornmentLayer();
crossHairAdornmentLayer.CrossHairUnit = DistanceUnit.Mile;
crossHairAdornmentLayer.CrossHairWorldSize = 50;
adormentOverlay.Layers.Add(crossHairAdornmentLayer);
Val… this is excellent and actually helps with another feature I was working on… you guys have outstanding support… thanks!
Michael,
You are welcome. Let us know if you have any other questions.