ThinkGeo.com    |     Documentation    |     Premium Support

V9 - Get screen bounds of feature label

Hi,

I have a number of Features on an InMemoryFeatureLayer consisting of an image (a custom ValueStyle) and a label (a custom TextStyle).

What I am trying to do is determine whether a point on the screen is within either the image or the label. I have the image detection working by finding its bounds on screen and converting those into a RectangleF which I then compare the point to using its .Contains() function.

I can’t figure out however how to get the screen bounds for the label. How can this be done?

Hi Paul,

For Image, if you render it on map, you need to pass into the bounding box for make sure where it’s located, so you can get the extent and do spatial query. Some image have its world file, you can directly read from it.

For Label, because we have many properties to effect where and how to draw the label, and after drawn on canvas it’s not a feature again, so we cannot do spatial query for it.

Could you please let us know why you need to check the point position and the Image/Label bounding box? We want to discuss about whether we can implement that by other way.

Regards,

Ethan

Hi Ethan,

My customer wants a context menu for the Features shown on the map. I used QueryTools.GetFeaturesNearestTo() to find the nearest feature for any map right click but they insist that it must only be shown when right clicking on the feature itself which consists of the image and the label. Image is no problem because I know where the center point is and the dimensions of the image but as you say the position of the label is not static so I need a solution for that. If it helps here is the style used for the label:

TextStyle textStyle;

textStyle = TextStyles.CreateSimpleTextStyle(“label”, SystemFonts.MessageFontFamily.ToString(), 9, DrawingFontStyles.Regular, GeoColor.SimpleColors.Black);
textStyle.BestPlacement = true;
textStyle.ForceHorizontalLabelForLine = true;
textStyle.XOffsetInPixel = -6;
textStyle.YOffsetInPixel = -15;
textStyle.Mask = labelStyle;
textStyle.MaskMargin = 0;
textStyle.MaskType = MaskType.Default;

Hi Paul,

In our map if you want to shows something like context menu, we suggest to use marker and popup for it. You can view this sample for detail: https://github.com/ThinkGeo/DynamicMarkerOverlaySample-ForWpf

In fact you click on map should related with the shape itself but not the label, so if you still want to do something for the shape, you should want to handle that by different types:

  1. Shape is Polygon, you can find the nearest features, then use spatial query: contains to see which feature is clicked.
  2. Line, you can buffer the line, and find which one contains your point
  3. Point, you can build a rectangle based on it or a circle based on it, then find which one contains your clicked point.

And after that you can shows your context menu.

The label cannot be used to do spatial query, so please try to implement that by shape feature.

Regards,

Ethan

Thanks Ethan,

The customer seems to have accepted that the label cannot be right clicked for the context menu. I already had the icon working so I think it will be ok.

Hi Paul,

Thanks for your update, any question please let us know.

Regards,

Ethan