Select to view content in your preferred language

Dynamically created layers and labels?

3602
6
01-18-2011 09:31 PM
KenAdams
Emerging Contributor
I have a question about labels.

I have a wpf-browser-application where layers are created dynamically/runtime by the user. For example, the user imports a text file with coordinates that is displayed in a new layer. The layers are created in the code/c# (not in the xaml) and should not be saved or anything, they only exists as long as the user runs the program.

My question is: how do I display labels for the objects in these layers?

Currently the layers are graphic layers, but I cannot find any way to show labels for graphiclayers. It feels like I'm using the wrong kind of layer or something... it shouldn't be this hard to display simple labels?

Any suggestions how to solve this? All help appreciated!
0 Kudos
6 Replies
DominiqueBroux
Esri Frequent Contributor
If the Geometry of your objects is 'Points', you can use a TextSymbol or a custom symbol including a TextBlock and bind the text property to an attribute of your graphics.
There is a sample of TextSymbol here : http://help.arcgis.com/en/webapi/silverlight/samples/start.htm#AddGraphicsXAML

If the geometry is Polyline or Polygon, you can create a new graphicslayer for your labels but you will have to define the label position either by a geometry service (such as LabelPoints) or by a calculation at the client side (such as geometry.Extent.GetCenter()).
0 Kudos
KenAdams
Emerging Contributor
If the Geometry of your objects is 'Points', you can use a TextSymbol or a custom symbol including a TextBlock and bind the text property to an attribute of your graphics.
There is a sample of TextSymbol here : http://help.arcgis.com/en/webapi/silverlight/samples/start.htm#AddGraphicsXAML

If the geometry is Polyline or Polygon, you can create a new graphicslayer for your labels but you will have to define the label position either by a geometry service (such as LabelPoints) or by a calculation at the client side (such as geometry.Extent.GetCenter()).


Right now I only have points, so the label position is not the problem.

Is there no better way than to create text objects? I need non overlapping labels or at least being able to set text background color (cannot find a way to do that on text objects). That makes text objects unusable if you have points close to each other.

Is feature layer a better alternative? Is it possible to create feature layers dynamically? And is "real" labelling possible in feature layers? Any other solutions available?

All help is appreciated!
0 Kudos
DominiqueBroux
Esri Frequent Contributor

Is there no better way than to create text objects?
I don't think so.

I need non overlapping labels
There is no built-in methods to avoid overlapping labels -> this would need specific development.


or at least being able to set text background color (cannot find a way to do that on text objects). That makes text objects unusable if you have points close to each other.

A textblock has no background but you can surround it with any panels which has background.


Is feature layer a better alternative?

There is no big difference with graphicslayer because, in your case, you are not requesting a feature service (basically a featurelayer is a graphicslayer which is querying a feature rest end point for you).


Is it possible to create feature layers dynamically?

Sure : you can instantiate a featurelayer, set the url and call initialize or add it to the map.


And is "real" labelling possible in feature layers? Any other solutions available?

At this time, there is nothing more for the labelling in feature layers.
0 Kudos
KenAdams
Emerging Contributor
*sigh*

Pretty annoying that there is no labeling available for wpf solutions. It's not like it's a completely new feature I'm looking for, labeling is a quite basic operation...

Anyway, thanx Dominique for taking your time answering my noob questions!
0 Kudos
dotMorten_esri
Esri Notable Contributor
Pretty annoying that there is no labeling available for wpf solutions. It's not like it's a completely new feature I'm looking for, labeling is a quite basic operation...


This is a client API, which means its primarily a light-weight client to ArcGIS Server, which does full-blown labelling.

The trick I often use to create a label with a background, is two textblocks on top of each other. The top one is black foreground, the back one is white with a blur effect added to it. That way you get a white "halo" around the text.
You can see this in action here: http://help.arcgis.com/en/webapi/silverlight/samples/start.htm#ShowCoordinatesBehavior
The effect is subtle on this basemap, but if you move the mousecursor outside the map area to the green background, you can easier see it.

See my two examples of this in this forum post: http://forums.arcgis.com/threads/22169-Custom-Marker-Symbol-with-Labels?p=73298&posted=1#post73298
0 Kudos
EvanBossett
Emerging Contributor
@kenadams - I found this post when trying to find information on "create map service dynamically".  It looks like you are successfully doing what i need to do (create an SDE table, create map service for that table, add that map service to your Silverlight app).

I have successfully used a Geoprocessing task to create the sde feature layer that i need.  However, I am stuck when it comes to creating a a map service on ArcServer dynamically.

If anyone could lend a hand or some source code, it would be much appreciated.

Thank you
0 Kudos