This is an archive related to a previous version of Esri Maps for SharePoint. If you need the current version go to http://doc.arcgis.com/en/maps-for-sharepoint/.

Behavior

As a developer, you may want to add functionality to Esri Maps for SharePoint by creating custom behaviors. Behaviors are extensions that execute functionality, but not in response to a particular user interaction (a mouse click, for example). Rather, behaviors are executed in response to some other mechanism; for example, behaviors can be created to respond to events fired by the map, a layer, other tools in the application, or even the hosting system itself.

Behavior OMD

_Behavior

The base class for all behaviors.

define([
   "dojo/_base/declare",
   "dojo/_base/lang",
   "esriMaps/extensions/behaviors/_Behavior"
], function(declare, lang, Behavior) {
 
   // Create a custom behavior by inheriting _Behavior class
   return declare([Behavior], {
       label: "Time Refresh Behavior",
       description: "Time Refresh Behavior",
       initialize: function(app) {
           // Set a timer to call execute every 10 seconds.
          window.setInterval(lang.hitch(this, this.execute), 10000);
       },
       execute: function() {
           // When execute is called, log the current Date and Time to console.
           console.log (new Date());        
       }
   });
});
_Behavior implements the following three dojo mixins:
  • dojo/Stateful
  • dojo/Evented
  • dojo/Deferred

Properties

NameTypeSummary

description

String

Description of the behavior.

label

String

Label for the behavior.

Methods

NameReturn typeSummary

destroy()

Nothing

Destroys the instance of the extension.

execute()

Nothing

Called in response to an event or an action. This function is called in response to an event. Use this function to write any actions that should be performed in response to the occurring event.

initialize(app)

Nothing

Initializes the extension.

toJson

Object

Returns the properties of the Behavior as a JSON string. If there are properties or settings that need to be saved, return them as a JSON. When the App is saved, the App calls each of the object's toJson method to get the properties that need to be saved.

Events

On EventEvent PropertiesDescription

onError

Use to report and log errors encountered in an extension.

_EventBehavior

The following code sample illustrates the implementation of a behavior that shows the mouse pointer when a user clicks on the app window.

require([
   "dojo/_base_declare", 
   "esriMaps/extensions/behaviors/_EventBehavior"
], function(_EventBehavior) {
   return declare(_EventBehavior, {
       target: window,
       eventName: 'click',
 
       execute: function(e) {
           console.log({
               x: e.clientX,
               y: e.clientY
           });
       }
   });
});

Properties

NameTypeSummary

eventName

String

Defines the event that triggers the execution of the behavior.

target

Object

Specifies the object on which to listen for events.

_LayerBehavior

A LayerBehavior executes a function when an event on a specified layer is fired.

The following code illustrates a sample LayerBehavior that logs a message when the opacity of a specific layer changes.

require([
   "dojo/_base/declare", 
   "esriMaps/extensions/behaviors/_LayerBehavior"
], function(declare, _LayerBehavior) {
    return declare(_LayerBehavior, {
        layer: "myLayer",
        eventName: "opacity-change",
 
        execute: function(opacity) {
            console.log("Layer opacity changed", this.layer, opacity);
        }
    });
});

Properties

NameTypeSummary

eventName

String

Defines the event to listen for on the layer and which triggers the execution of the behavior.

layer

String | esri/Layer

The Layer in the Map, which is the source of the specified event.

The layer may be specified as an ID or as an instance of a layer. If an ID is specified, this property will be replaced by an instance when the behavior is initialized. For more information, refer to the ArcGIS API for JavaScript help for Layer.

_MapBehavior

A MapBehavior executes a function when an event on the Map is fired.

The following code illustrates a sample MapBehavior that logs a message when the extent of the map changes.

require([
   "dojo/_base/declare", 
   "esriMaps/extensions/behavior/_MapBehavior"
], function(declare, _MapBehavior) {
   return declare(_MapBehavior, {
       eventName: "extent-change",
 
       execute: function(delta, extent, levelChange, lod) {
           console.log("Extent changed", this.map, extent);
       }
   });
});

Properties

NameTypeSummary

eventName

String

Defines the event to listen for on the map and triggers the execution of the behavior.

map

String | esri/Map

The Map object that is the source of the specified event.

For more information, refer to the ArcGIS API for JavaScript API help for Map.