Select to view content in your preferred language

How to combine two ESRI.ArcGIS.Client.Graphic objects?

2315
4
06-24-2011 09:47 AM
GalTalmor
Emerging Contributor
Hello
I created a map and when the user clicks inside, the code creates a red point at the location, and sets a text above this point.
Something like that :


This is the code :
var redPointSymbol = new SimpleMarkerSymbol { Color = new SolidColorBrush { Color = Colors.Red } };
var textSymbol  = new TextSymbol { Text = "Point A", FontSize = 15 };
var textPoint = new MapPoint(mapPoint.X, mapPoint.Y + textDistance);
myGraphicsLayer.Graphics.Add(new Graphic { Symbol = redPointSymbol, Geometry = mapPoint});
myGraphicsLayer.Graphics.Add(new Graphic { Symbol = textSymbol , Geometry = textPoint  });

The problem is when I zoom the map.. I want that the distance between the red point and the text will be final. In every zoom level. I created the graphic objects by map coordinates, and therefore when I'm zoom in/out, the distance between them grows up.

The only solution I can think about, is to set the text Graphic on the original map point, and use OffsetX & OffsetY (for the TextSymbol). It's might be good becaute the offsets work by screen coordinates, but I want to add after that a line that connecting between the point and the text. And for that I must create a polyline by map coordinates.
There is a way to combine those Graphics together? Anyone have an idea to do that? 😞
Thank you guys!
0 Kudos
4 Replies
dotMorten_esri
Esri Notable Contributor
The trick is to only use one graphic, and have both the point and the text in the same symbol.
See this sample: http://help.arcgis.com/en/webapi/silverlight/samples/start.htm#CustomSymbols
If you hover on the dot at Los Angeles, notice the text that pops up. This is part of the symbol. You can tweak the symbol (MapTipLabelMarkerRendderer) so that the label is always showing on by removing the visual state defined in the symbol template, and set the "labelOnHover" object to Visible instead of collapsed.
0 Kudos
GalTalmor
Emerging Contributor
The trick is to only use one graphic, and have both the point and the text in the same symbol.
See this sample: http://help.arcgis.com/en/webapi/silverlight/samples/start.htm#CustomSymbols
If you hover on the dot at Los Angeles, notice the text that pops up. This is part of the symbol. You can tweak the symbol (MapTipLabelMarkerRendderer) so that the label is always showing on by removing the visual state defined in the symbol template, and set the "labelOnHover" object to Visible instead of collapsed.


Thank you for your reply 🙂
Maybe control-template is actually the best solution.. I thought to register to ExtentChanging event and repaint the graphic text again over and over.. How much do you think that's may slow my app?
0 Kudos
dotMorten_esri
Esri Notable Contributor
As long as you only have a very limited set of features, that shouldn't be a problem. You don't need to repaint. Make sure you only reposition, since this is a lot cheaper than recreating/placing a textbox.
If you listen to the ExtentChanging event and reposition your elements on top of/outside the map, that would be (fairly) cheap (ie don't use Graphics, but use for instance an ItemsControl overlaying the map). This is similar to how the InfoWindow control does it. You can see the sourcecode for that here: http://esrisilverlight.codeplex.com/SourceControl/changeset/view/68177#1327535
0 Kudos
GalTalmor
Emerging Contributor
As long as you only have a very limited set of features, that shouldn't be a problem. You don't need to repaint. Make sure you only reposition, since this is a lot cheaper than recreating/placing a textbox.
If you listen to the ExtentChanging event and reposition your elements on top of/outside the map, that would be (fairly) cheap (ie don't use Graphics, but use for instance an ItemsControl overlaying the map). This is similar to how the InfoWindow control does it. You can see the sourcecode for that here: http://esrisilverlight.codeplex.com/SourceControl/changeset/view/68177#1327535


Thank you very much!! 🙂
0 Kudos