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?
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.
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.