Select to view content in your preferred language

Cartographic Line Symbols or using StrokeEndLineCap

2466
10
01-19-2011 08:19 PM
JoeHershman
MVP Regular Contributor
I have a simple need. Create a line with a Triangle end point. Was able to do in Flex by inheriting from LineSymbol and overriding the Draw method. Cannot use this approach because the Silverlight LineSymbol does not expose the same methods in this way.

Looked at CartographicLineSymbol and it has an EndLineCap which would seem to offer this behavior based on the Enum values. Set to triangle and it does nothing, in fact I do not see any affect of setting any of the properties on this object.

This basically would just seem the it exposes some of the Attributes on the <Path/> element. If I set them directly in the PAth element of a custom Symbol still no affect.

Any Ideas???

Thanks
-Joe

<esri:LineSymbol x:Class="Kpoint.Jbl.Viewer.Modules.CoaGraphics.Symbols.FollowAndSupportSymbol"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:esri="http://schemas.esri.com/arcgis/client/2009">

<esri:LineSymbol.ControlTemplate>
<ControlTemplate>
<Canvas>
<Path Name="Element" Stroke="Blue" StrokeThickness="3" StrokeDashArray="2 1" StrokeDashCap="Round"StrokeEndLineCap="Triangle" />
</Canvas>
</ControlTemplate>
</esri:LineSymbol.ControlTemplate>
</esri:LineSymbol>
Thanks,
-Joe
0 Kudos
10 Replies
dotMorten_esri
Esri Notable Contributor
You should not have a Canvas around your Path element.
Only the line caps available to Silverlight's Path object is awailable for line symbols.
0 Kudos
JoeHershman
MVP Regular Contributor
I have tried it both ways, that just happens to be where I was at when I copied it.  The best I can see with this setting is that if you make a really, really thick line you can kind of tell there is a triangle at the end when you zoom in.  But on a normal thckness line you cannot see any difference when you change this setting.

What I really want to do is create a line that has an arrow head end point, not just a small triangular end point.  Like I said in my intial post, I did this in Flex, and if I were to just use the core .net shapes I can do it


I have been messing around with the various aspects of the ControlTemplate, it looks to me like somehow there might be a way to use the PathGeometry to get the behavior I want.  I have yet to figure out how you can set a path the starts at the end point of the line (I am no XAML guru).  If you have any insight into how one might go about this I would greatly appreciate it.  It seems a little mysterious how the Path "Element" is being grabbed onto and used

Thanks
-Joe
Thanks,
-Joe
0 Kudos
dotMorten_esri
Esri Notable Contributor
These are the only linecaps Silverlight gives you: http://msdn.microsoft.com/en-us/library/bb979973(v=vs.95).aspx
I don't think there's any way to extend these.
0 Kudos
JoeHershman
MVP Regular Contributor
As you said this seems to be the only thing available using a line cap.  I am not sure I undersatnd why ESRI seems to have gone out of the way to not expose any thing that could allow users to do more than make lines have cool visual affects.  It seems to me that it would make sense to have Symbol be a UI Component so developers could have greater control over the Control Template.  Or some way to have access to the actuall UI Elmenent that is being drawn on, like Flex does.  I think what we are trying to accomplish should be possible in a straight forward way.

If you have any thoughs on making a polyline that is truly an arrow it would be greatly appreciated.
Thanks,
-Joe
0 Kudos
DominiqueBroux
Esri Frequent Contributor
I am going to work on a sample allowing to add arrows (or other patterns) to lines.

Here is a preview.

Note that this sample is also able to transform lines to smooth curves:p

I will post the code as soon as I will have cleaned this sample up.
0 Kudos
JoeHershman
MVP Regular Contributor
This is exactly what we have been trying to do.  So the sooner you can have the code posted the better.  I can clean it up
Thanks,
-Joe
0 Kudos
DominiqueBroux
Esri Frequent Contributor
This is exactly what we have been trying to do. So the sooner you can have the code posted the better. I can clean it up

Send me an email (dbroux@esri.com), I will provide you the code 'as it is'.
0 Kudos
dotMorten_esri
Esri Notable Contributor
I am not sure I undersatnd why ESRI seems to have gone out of the way to not expose any thing that could allow users to do more than make lines have cool visual affects. It seems to me that it would make sense to have Symbol be a UI Component so developers could have greater control over the Control Template. Or some way to have access to the actuall UI Elmenent that is being drawn on, like Flex does.


This is done for performance reasons. Creating UI Elements is expensive. This is not really different from what you will see in for instance a ListBox. The ListBox applies a template to each row. The ListBox will never render more than the rows you can see in the view. When you scroll, the row that goes out of view is moved to the new row that comes into view, and it's datacontext is simply updated (this is what is called UI Virtualization). This makes it possible to render millions of rows without having to create millions of UI Elements, and thus the listbox scrolls smoothly.
The Map uses a similar approach, and reuses UI Elements. In other words: There's no guarantee that the UIElement that belonged to one graphic, belongs to the same graphic a moment later. There's also other reasons we keep these not exposed - for instance some are due to limitations in Silverlight and WPF where we need to do some work-arounds to get features rendering correctly at all times. Direct access to the UI Element could seriously mess up that step.

Having said all that, even if you did have access to the UI Element, you would still be bound by what Silverlight gives you. I can't really see how access to that would allow you to override how a Path is rendered. Access to the template should give you equal power to access the UI Element instance.

Don't underestimate the power of templates. Dominique just demonstrated how much you can actually accomplish with them 🙂
0 Kudos
JoeHershman
MVP Regular Contributor
Thanks for the help, this was exactly the solution I needed.
Thanks,
-Joe
0 Kudos