Select to view content in your preferred language

Labelling Feature class on Web Application

720
3
Jump to solution
09-13-2012 08:03 AM
MaziyarBoustani
Emerging Contributor
I made a web application for a campus. Each building has name and what I want to do is to show name of building on each polygon.
I know it is simple by using .mxd file, because .mxd file will contains symbology and labelling. However, feature class doesn't contain label.
Is there any JavaScript code which I can choose a field from building's attribute like "name", and show them on my website?

Thanks
0 Kudos
1 Solution

Accepted Solutions
BenFousek
Deactivated User
I assume the buildings are a feature layer and it's MODE_ONDEMAND. You could:
1) create a graphic layer for the labels
2) connect to the feature layer's onUpdateStart() method to clear any existing labels on the label graphic layer
3) connect to the the feature layer's onUpdateEnd(error, info), iterate through the features, and:
    a) get the center of the feature
    b) create a POINT on the label graphic layer
    c) instead of a point symbol, give it a text symbol using the attribute of your choice for the label text

You'll probably want to set the label graphic layer's display scales. If you haven't worked with text symbols they can be tricky to format properly. The api reference has the basics but I suggest checking out a text symbol in the DOM for unreferenced variables and functionality. The hazard to this approach is the label will be on top of the polygons and will accept a click over the polygon if the user clicks on the label. If there is no info template, onclick etc associated with the polygon it's not a problem.

View solution in original post

0 Kudos
3 Replies
BenFousek
Deactivated User
I assume the buildings are a feature layer and it's MODE_ONDEMAND. You could:
1) create a graphic layer for the labels
2) connect to the feature layer's onUpdateStart() method to clear any existing labels on the label graphic layer
3) connect to the the feature layer's onUpdateEnd(error, info), iterate through the features, and:
    a) get the center of the feature
    b) create a POINT on the label graphic layer
    c) instead of a point symbol, give it a text symbol using the attribute of your choice for the label text

You'll probably want to set the label graphic layer's display scales. If you haven't worked with text symbols they can be tricky to format properly. The api reference has the basics but I suggest checking out a text symbol in the DOM for unreferenced variables and functionality. The hazard to this approach is the label will be on top of the polygons and will accept a click over the polygon if the user clicks on the label. If there is no info template, onclick etc associated with the polygon it's not a problem.
0 Kudos
JianHuang
Deactivated User
That's in the plan that JavaScript API will support labeling on client. But we don't have a specific timeline at this moment.
0 Kudos
MaziyarBoustani
Emerging Contributor
I find GeometryService.labelPoints() method which make a point on each polygon and will label the polygon.
Here is the link:

http://resources.esri.com/help/9.3/arcgisserver/apis/javascript/arcgis/help/jssamples_start.htm#jssa...
0 Kudos