Class added v2.0.
Load the TemplatePicker using one of the dojo.require statements below. See the Coding Guidelines help topic for details.
dojo.require("esri.dijit.editing.TemplatePicker-all");ordojo.require("esri.dijit.editing.TemplatePicker");The following table lists the CSS class names used by the template picker to refer to the DOM nodes it creates. The class names can be used to customize the look and feel of the widget.
CSS Classes| Class Name | Description |
| templatePicker | The node where an instance of the template picker is rendered. |
| grid | The grid node that displays the templates. |
| groupLabel | The node that contains the group label. Only applicable if "grouping" is enabled. |
| item | The node that contains the template label and symbol. |
| itemLabel |
The node that contains a template label.
.itemLabel{color:#266A2E;}
|
| itemSymbol | The node that contains a template symbol. |
| selectedItem | The node that is currently selected. |
| tooltip | The node that holds the tooltip. Only applicable if tooltips are enabled. |
esri.dijit.editing.TemplatePicker
| Constructor | Description |
|---|---|
| esri.dijit.editing.TemplatePicker(params, srcNodeRef) | Creates a new TemplatePicker object that displays a gallery of templates from the input feature layers or items. A symbol and label is displayed for each template. The symbol is defined by the template's feature type. The label is the template's name. |
| Property | Type | Description |
|---|---|---|
| grid | dojox.grid.DataGrid | Reference to the data grid used to display the templates. |
| tooltip | div | If tooltips are enabled the reference to the tooltip div. |
| Method | Return Value | Description |
|---|---|---|
| attr(name, value?) | none | Get or set the properties of the template picker. See the dojo documentation for more details about this method. |
| clearSelection() | none | Clears the current selection. |
| destroy() | none | Destroys the template picker. Call destroy() when the widget is no longer needed by the application. |
| getSelected() | Object | Gets the selected item picked by the user. |
| startup() | none | Finalizes the creation of the template picker. Call startup() after creating the widget when you are ready for user interaction. |
| update() | none | Updates the templatePicker after modifying the properties of the widget. |
| Event | Description |
|---|---|
| onSelectionChange() | Fires when an item is selected or unselected in the template picker. You can retrieve the selected item using the getSelected() method. |
Creates a new TemplatePicker object that displays a gallery of templates from the input feature layers or items. A symbol and label is displayed for each template. The symbol is defined by the template's feature type. The label is the template's name.
| <Object> params | Required | FeatureLayers or items are required all other parameters are optional. See options list. |
| <Object> srcNodeRef | Required |
HTML element where the TemplatePicker will be rendered. Specify the HTML element using the "id" or a reference to the element.
"templatePickerDiv"
or
dojo.byId("templatePickerDiv");
|
| <Number> columns | Number of visible columns. Default is three. Specify "auto" to have the template picker automatically calculate the number of columns based on the number of rows. Note: "auto" has no effect when grouping is enabled. |
| <FeatureLayer[]> featureLayers | Array of input feature layers. The template picker displays the templates from each of the layer's in the array. Required to provide either featureLayers or items. |
| <Boolean> grouping | Templates are grouped based on the containing feature layer. Default is true. Grouping is automatically disabled when items are specified instead of featureLayers. |
| <Object[]> items |
An array of items described using the syntax below. Use this option if you want to display a collection of symbols in the template picker.
[{label:<String>,symbol: <esri.symbol.Symbol>,description: <String>}]
Code snippet:var items = [
{ label: "item 1", symbol: symbol, description: "description 1" },
{ label: "item 2", symbol: symbol, description: "description 2" },
{ label: "item 3", symbol: symbol, description: "description 3" },
{ label: "item 4", symbol: symbol, description: "description 4" }
];
|
| <Number> maxLabelLength | Length of label description. Default is to display the entire label. If the specified maxLabelLength is less than the number of characters in the label description the description is truncated. |
| <Number> rows | Number of visible rows. Default is four. Specify "auto" to have the template picker automatically calculate the number of rows based on the number of columns. Note: "auto" has no effect when grouping is enabled. |
| <Boolean> showTooltip | Tooltip content contains the template name and description. Default is false. |
| <String> style |
HTML style attributes for the widget. Specify as css text or name:value hash. For example:
"width:400px; height:300px;"
or
{width: "400px", height:"300px"}
|
widget = new esri.dijit.editing.TemplatePicker({
featureLayers: layers,
rows: "auto",
columns: "auto",
style: "width: 405px;"
}, "templatePickerDiv");
| <String> name | Required | Name of the attribute of interest. |
| <Object> value | Optional | Value for the specified attribute. |
//get
var isTooltipEnabled = templatePicker.attr("showTooltip");
//set
templatePicker.attr("showTooltip", false);
templatePicker.attr("grouping", true);
templatePicker.attr("maxLabelLength", 0);
templatePicker.update();
{
featureLayer: <FeatureLayer>,
type: <FeatureType>,
template: <FeatureTemplate>
}
If the widget was initialized with items the returned object will have the following properties:
{
item: <Object>
}
dojo.connect(widget, "onSelectionChange", function() {
var selected = widget.getSelected();
if (selected) {
var featureLayer = selected.featureLayer;
var type = selected.type;
var template = selected.template;
//get the selected symbol from the renderer via the template prototype
var templateSymbol = selected.featureLayer.renderer.getSymbol(selected.template.prototype);
console.log("layer = ", featureLayer && featureLayer.name,
", type = ", type && type.name,
", template = ", template && template.name);
}
});
templatePicker.startup();
templatePicker.attr("showTooltip", false);
templatePicker.update();
dojo.connect(widget, "onSelectionChange", function() {
var selected = widget.getSelected();
if (selected) {
var featureLayer = selected.featureLayer;
var type = selected.type;
var template = selected.template;
}
});