Select to view content in your preferred language

Location of PictureMarkerSymbol vs MarkerSymbol

4176
15
11-02-2010 09:38 AM
KeithNightlinger
Emerging Contributor
As I zoom in and out of my application the PictureMarkerSymbol and the MarkerSymbol with the Image brush don't appear in its true location and as a user zooms out it gets farther and farther away. 

I have set the offsetX and offsetY and when zoomed all the way in it shows where it is supposed to, but when zoomed out it moves it away. 

In contrast the strobe marker symbol (from samples) shows exactly where it is supposed to, no matter the scale.

I have tried setting the ScaleTransform, but that wasn't it.

What am I missing?  The issue is I have emergency vehicles appearing as though they are in completely different city and my users need to have an broad view of where all the vehicles are at.

Thanks in advance,

Keith
0 Kudos
15 Replies
JenniferNery
Esri Regular Contributor
Here's another solution. How about you create your own Renderer by implementing IRenderer?

When you implement GetSymbol(), you can set the MarkerSymbol's offsets before returning the symbol. http://help.arcgis.com/en/webapi/silverlight/apiref/ESRI.ArcGIS.Client~ESRI.ArcGIS.Client.IRenderer~...

You can create the ControlTemplate based on the graphic.Attributes and maybe get the container that holds the arrow and TextBlock, to know its ActualHeight and ActualWidth. You can use these values to calculate the MarkerSymbol's Offsets.

http://msdn.microsoft.com/en-us/library/cc190359(v=VS.95).aspx
http://forums.silverlight.net/forums/t/115213.aspx
0 Kudos
BjørnarSundsbø
Deactivated User
I was thinking of that myself, though I was not sure how to get the ActualHeight and ActualWidth from the ControlTemplate after it's content has been populated from the attributes. I assume the IRenderer will come into effect each time an attribute changes, so the offset can be changed if any changes are made?

I'm looking into the links you sent me. It seems this is a thing more people would be interested in, and perhaps there could be a property on the MarkerSymbol for with an enum with the following values: Manual (uses manual offset values), CenterX (centers on the X axis), CenterY (centers on the Y axis), CenterBoth (center both X and Y). Pretty much like the SizeToContent property of a Window.

If the GraphicElement was not internal, I think I might have been able to bind the offsetX and Y to RelativeSource={RelativeSource AncestorType={x:Type GraphicElement}} and ActualHeight. Sadly, this is one more situation where I feel the API has too many internal members and types (in my humble opinion :))

I have a related question in Which layer do i Choose.
0 Kudos
JenniferNery
Esri Regular Contributor
Thank you for your feedback. I will be sure to share them with our team.

Another solution, which is probably more difficult but elegant, would be to create a custom control for your Arrow and TextBlock and override ArrangeOverride and MeasureOverride accordingly.

I will respond to the other thread 🙂
0 Kudos
BjørnarSundsbø
Deactivated User
The IRenderer was a wash. I was unable to attach the actual object to the ControlTemplate and initialize it with the datacontext. Hence, not able to get the width.

Using the Custom Control approach, Since anything I arrange inside of this control are children of the controltemplate. I tried to get the ancestor from the Custom Control, which naturally is the internal GraphicElement. I then use reflection to get the GraphicElement and it's Symbol property. If it is a MarkerSymbol, set the X and Y offset. It seems to work, though I haven't yet tried to change the text of the label to see if it repositions correctly.

Reflection adds an undesirable overhead, though it can be reduced by reflecting the type in a static constructor, and accessing the propertyInfos and such from ArrangeOverride. Hopefully this will not affect all the symbols on the layer (one long label causes all the other symbols to have the same offset). Will update on progress.
0 Kudos
BjørnarSundsbø
Deactivated User
If I have one graphics visible in the visible extent, it works as it should. If multiple graphics are in the view, the graphics are not offset properly, and I can see them all jump when I change the label on one graphic.

I assume the reason for this is that I use a SimpleRenderer for the layer, and it is the same instance of the MarkerSymbol used for all the Graphics. The offset applied to the Symbol is the last Graphic affected by the ArrangeOverride. I am curious in regards to any solution I apply here where no codebehind to duplicate the symbol or something similar will be affected by the dynamic offsett of the symbol (different offset for all graphics).

I suppose I could create a new IRenderer where I create a new Symbol based on the Symbol property of the renderer, and return it from GetSymbol()
0 Kudos
JenniferNery
Esri Regular Contributor
I have not tried this myself but I think this would work:

When building the Xaml string in GetSymbol(), instead of relying on DataContext Binding, you can get the actual attribute value for the given graphic.

Something like:
StringBuilder sb = new StringBuilder();
//more code here
sb.Append(string.Format("<TextBlock Text=\"{0}\"/>", graphic.Attributes["label"]));
0 Kudos