Hi,
There’s no AdornmentOverlay in AndroidEdition, so how does one create a cross hair that targets the center of the MapView ?
I want to use this to have the user register map positions, which I then “just” retrieve using the map center.
Cheers
Lars
Crosshairs on map - AdornmentOverlay?
Hi Lars,
AdornmentOverlay is added to the latest build few days ago. We will send you the new trail later.
I’m not quite understand the “Crosshair” requirement. Usually, we use it like a button, when click on it, it centers the map to the GPS location where I am. If this is what you want, maybe MapTool is better. Like the attached sample indicated. If you want to show a crosshair in the center of the map without any user interaction, please use AdornmentOverlay. Here is a relate post that adding a scale bar on AdornmentOverlay.
thinkgeo.com/forums/MapSuite…fault.aspx
Thanks,
Howard
CrossHairSample.zip (13.9 KB)
Hi Howard,
Thanks for the link to the example. Unfortunately it isn’t quite useful.
I need to add a custom object to the AdornmentOverlay.
The example shows a "ScaleBarAdornmentLayer, and as far as I can see, there’s only 4-5 specialized XxxAdornmentLayer available.
I’ve never used AdornmentLayer before, but assumed that it was used to add cosmetic features in screen coordinates onto the map. Apparently this was a wrong assumption.
–
So I’m back to my original question: How can I implement adding a crosshair that targets the map center to my MapView ?
The reason for using this method is that we feel that the best user interface experience will be to fix the crosshair and let the user move the map, instead of vice versa, as this makes more sense in a touch based environment.
Using map tools is not touch based look-and-feel. Just like zooming in and out should be done by “pinching” the map.
Cheers
Lars
Hi Lars,
I’m a little confuse for your “crosshair”. Please allow me clear the requirement here. I have two assumptions; hope one of those are what you are seeking for.
- The following screenshot contains a “crosshair” in the red circle; we allow to center the map to where the GPS locates when tap on it. It needs to support “Tap” gesture; so I recommend MapTool in the previous reply.
- The following screenshot contains a static image that will be always on the center of map. We don’t need to move it around nor any user interaction. We could use AdornmentLayer. Sorry that I didn’t make myself clear on this part. I meant that we could create a CustomAdornementLayer like this post indicates. Please feel free to download the attached file for detail.
thinkgeo.com/forums/MapSuite/tabid/143/aft/12280/Default.aspx
Please feel free to correct me if I misunderstand your requirement.
Thanks,
Howard
CrossHairSample_12279.zip (14.1 KB)
Thank you Howard.
The second assumption was the right one, a static marker over a movable map.
I do want a somewhat larger cross hair (that doesn’t obscure the target as much), but that’s hopefully easily adapted from your fine example.
What I failed to appreciate was that I needed to make a derivate custom AdornmentLayer class. I’ve made such derivate classes in abundance concerning styles, but didn’t realize that this was a similar setup.
Thanks again :-)
Cheers
Lars
Alas, still pending.
What I want is to draw a cross hair of two lines .
Your example uses the function DrawWorldImage…() using world coordinates, whereas there’s only a DrawLine() that uses screen coordinates.
I’ve tried to utilize ExtentHelper.ToScreenCoordinate(), but nothing shows.
Here’s my code sofar:
//private readonly CultureInfo US_NUMBERS = new CultureInfo(“en-US”);
protected
override
void
DrawCore(GeoCanvas canvas, System.Collections.ObjectModel.Collection<SimpleCandidate> labelsInAllLayers)
{
base
.DrawCore(canvas, labelsInAllLayers);
RectangleShape extent = canvas.CurrentWorldExtent;
// world coordinates
PointShape mapCenter = extent.GetCenterPoint();
PointShape mapMin = extent.LowerLeftPoint;
PointShape mapMax = extent.UpperRightPoint;
ScreenPointF ctr = ExtentHelper.ToScreenCoordinate(canvas.CurrentWorldExtent, mapCenter, canvas.Width, canvas.Height);
ScreenPointF LL = ExtentHelper.ToScreenCoordinate(canvas.CurrentWorldExtent, mapMin, canvas.Width, canvas.Height);
ScreenPointF UR = ExtentHelper.ToScreenCoordinate(canvas.CurrentWorldExtent, mapMax, canvas.Width, canvas.Height);
// Nb! screen coordinates have (0,0) in UpperLeft
string
ctrx = ctr.X.ToString(US_NUMBERS);
string
ctry = ctr.Y.ToString(US_NUMBERS);
string
minx = LL.X.ToString(US_NUMBERS);
string
miny = LL.Y.ToString(US_NUMBERS);
string
maxx = UR.X.ToString(US_NUMBERS);
string
maxy = UR.Y.ToString(US_NUMBERS);
LineShape h =
new
LineShape(
“LINESTRING(”
+ minx +
" "
+ ctry +
‘,’
+ maxx +
’ ’
+ ctry +
“)”
);
LineShape v =
new
LineShape(
“LINESTRING(”
+ ctrx +
" "
+ miny +
‘,’
+ ctrx +
’ ’
+ maxy +
“)”
);
GeoColor clr =
new
GeoColor(0, 0, 0);
canvas.DrawLine(h,
new
GeoPen(clr, 3), DrawingLevel.LevelOne);
canvas.DrawLine(v,
new
GeoPen(clr, 3), DrawingLevel.LevelOne);
}
What am I missing here ?
Lars
Ps! You might want to consider adding DrawWorldLine() etc. for all types to the AdornmentLayer base class.
Hi Lars,
Thanks for your feedback. This issue is caused by drawing an invalid coordinate shape. The GeoCanvas.DrawLine accepts both world coordinate and screen coordinate. If we pass a Shape like in your attached code: LineShape, GeoCanvas assumes the shape is in world coordinate. So it will convert to screen coordinate again during the drawing process.
In the attached sample, we showed two ways of drawing crosshair, please check it out.
Thanks,
Howard
001_CrossHairSample.zip (14.5 KB)
Thank you Howard.
It now works like a charm :-)
I did originally use world coordinates, but nothing showed, so there was another error too.
Good to know that the Draw functions handle both screen and world coordinates, and from your response I assume that using a collection of ScreenPointF is necessary to tell GeoCanvas that it’s being provided with screen coordinates ?
Cheers
Lars
Hi Lars,
Correct.
Thanks Howard’s sample and please let us know if you have any questions.
Thanks,
Troy