Class: TemplatePicker

Description

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");
or
dojo.require("esri.dijit.editing.TemplatePicker");

A template picker displays a gallery of templates from one or more feature layers. For each template, a symbol and a label is displayed. Users can select or deselect a symbol by clicking on the item.

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.

Samples

Search for samples that use this class.  

Class hierarchy

esri.dijit.editing.TemplatePicker

Constructor

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.

Properties

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.

Methods

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.

Events

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.
Constructor Detail

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.

Parameters:
<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");
Options:
<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"}
Code snippets:
    widget = new esri.dijit.editing.TemplatePicker({
        featureLayers: layers,
        rows: "auto",
        columns: "auto",
        style: "width: 405px;"
      }, "templatePickerDiv");     
      
Properties Detail

<dojox.grid.DataGrid> grid

Reference to the data grid used to display the templates.

<div> tooltip

If tooltips are enabled the reference to the tooltip div.
Methods Detail

attr(name, value?)

Get or set the properties of the template picker. See the dojo documentation for more details about this method.
Return value: none
Input Parameters:
<String> name Required Name of the attribute of interest.
<Object> value Optional Value for the specified attribute.
Code snippets:
//get
var isTooltipEnabled = templatePicker.attr("showTooltip");

//set
templatePicker.attr("showTooltip", false);
templatePicker.attr("grouping", true);
templatePicker.attr("maxLabelLength", 0);
templatePicker.update();

See also:
update  

clearSelection()

Clears the current selection.
Return value: none

destroy()

Destroys the template picker. Call destroy() when the widget is no longer needed by the application.
Return value: none

getSelected()

Gets the selected item picked by the user. If the widget was initialized with featueLayers the properties of the returned object are in the following format:
{
  featureLayer: <FeatureLayer>,
  type: <FeatureType>,
  template: <FeatureTemplate>
}
If the widget was initialized with items the returned object will have the following properties:
{
  item: <Object>
}
Return value: Object
Code snippets:
 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);
    }
 });

See also:
onSelectionChange  

startup()

Finalizes the creation of the template picker. Call startup() after creating the widget when you are ready for user interaction.
Return value: none
Code snippets:
templatePicker.startup();

update()

Updates the templatePicker after modifying the properties of the widget.
Return value: none
Code snippets:
templatePicker.attr("showTooltip", false);
templatePicker.update();

See also:
attr  

Events Detail

onSelectionChange()

Fires when an item is selected or unselected in the template picker. You can retrieve the selected item using the getSelected() method.
Code snippets:
 dojo.connect(widget, "onSelectionChange", function() {
  var selected = widget.getSelected();
    if (selected) {
      var featureLayer = selected.featureLayer;
      var type = selected.type;
      var template = selected.template;         
    }
 });
See also:
getSelected