Class: GraphicsLayerE-mail This TopicPrintable VersionGive Us Feedback

Description

dojo.require("esri.layers.graphics");

A layer that contains one or more Graphic features. Each map contains a GraphicsLayer by default, accessible using the Map.Graphics property. Beginning with v1.4, you can create your own graphics layers and add them to the map. Graphics layers can be reordered within the group of graphics layers. However, the graphics layer in Map.Graphics is always on top. Also, all graphics layers are always on top of TiledMapServiceLayers and DynamicMapServiceLayers.

Samples

Search for samples that use this class.  

Class hierarchy

esri.layers.Layer
  |_ esri.layers.GraphicsLayer

Constructor

Constructor Description
esri.layers.GraphicsLayer() Creates a new GraphicsLayer object.
esri.layers.GraphicsLayer(options?) Creates a new GraphicsLayer object with parameters.

Properties

Property Type Description
graphics Graphic[] The array of graphics that make up the layer.
renderer Renderer Renderer assigned to the GraphicsLayer.

Methods

Method Return Value Description
add(graphic) Graphic Adds a graphic.
clear() none Clears all graphics.
disableMouseEvents() none Disables all mouse events on the graphics layer.
enableMouseEvents() none Enables all mouse events on the graphics layer.
remove(graphic) Graphic Removes a graphic.
setInfoTemplate(infoTemplate) none Specify or change the info template for a layer.
setOpacity(opacity) none Initial opacity or transparency of layer. Not supported in Internet Explorer.
setRenderer(renderer) none Sets the renderer for the graphics layer.

Events

Event Description
onClick(event) Fires when a graphic has been clicked.
onDblClick(event) Fires when a graphic has been double clicked.
onGraphicAdd(graphic) Fires when a graphic is added to the GraphicsLayer.
onGraphicRemove(graphic) Fires when a graphic is removed from the GraphicsLayer.
onGraphicsClear() Fires when all graphics in the GraphicsLayer are cleared.
onMouseDown(event) Fires when a mouse button is pressed down and the mouse cursor is on a graphic.
onMouseDrag(event) Fires while the mouse is being dragged until the mouse button is released.
onMouseMove(event) Fires as the mouse moves through a graphic on the GraphicsLayer.
onMouseOut(event) Fires as the mouse exits a graphic on the GraphicsLayer.
onMouseOver(event) Fires when the mouse first enters into a graphic on the GraphicsLayer.
onMouseUp(event) Fires when a mouse button is released and the mouse cursor is on a graphic.
Constructor Detail

esri.layers.GraphicsLayer()

Creates a new GraphicsLayer object. (As of v1.4)
Code snippets:
 var countyLayer = new esri.layers.GraphicsLayer();

esri.layers.GraphicsLayer(options?)

Creates a new GraphicsLayer object with parameters. (As of v1.4)
Parameters:
<Object> options Optional See options list for parameters.
Options:
<Boolean> displayOnPan When true, graphics are displayed during panning. When false, the graphics are turned off during pan movement. Setting to false may improve performance in Internet Explorer. The default is true.
<String> id Id to assign to the layer. If not assigned, esri.Map assigns value.
<Number> opacity Initial opacity or transparency of layer. Values range from 0.0 to 1.0, where 0.0 is 100% transparent and 1.0 has no transparency. The default value is 1.0. Not supported in Internet Explorer.
<Boolean> visible Initial visibility of the layer. Default is true.
Code snippets:
var  graphicsLayer = new esri.layers.GraphicsLayer({opacity:0.20});
Properties Detail

<Graphic[]> graphics

The array of graphics that make up the layer.

<Renderer> renderer

Renderer assigned to the GraphicsLayer. (As of v1.4)
Methods Detail

add(graphic)

Adds a graphic.
Return value: Graphic
Input Parameters:
<Graphic> graphic Required The graphic to add.
Code snippets:
function addGraphic(geometry) {
  var symbol = new esri.symbol.SimpleFillSymbol();
  graphicsLayer.add(new esri.Graphic(geometry, symbol));
}

See also:
onGraphicAdd  

clear()

Clears all graphics.
Return value: none
Code snippets:
graphicsLayer.clear();

See also:
onGraphicsClear  

disableMouseEvents()

Disables all mouse events on the graphics layer.
Return value: none

enableMouseEvents()

Enables all mouse events on the graphics layer.
Return value: none

remove(graphic)

Removes a graphic.
Return value: Graphic
Input Parameters:
<Graphic> graphic Required The graphic to remove.
See also:
onGraphicRemove  

setInfoTemplate(infoTemplate)

Specify or change the info template for a layer. (As of v2.2)
Return value: none
Input Parameters:
<InfoTemplate> infoTemplate Required The new info template.
Code snippets:
var cityLayer = new esri.layers.GraphicsLayer();
var infoTemplate = new esri.InfoTemplate("${CITY_NAME}","${*}");
cityLayer.setInfoTemplate(infoTemplate);

setOpacity(opacity)

Initial opacity or transparency of layer. Not supported in Internet Explorer.
Return value: none
Input Parameters:
<Number> opacity Required Value from 0 to 1, where 0 is 100% transparent and 1 has no transparency. The default value is 1.

setRenderer(renderer)

Sets the renderer for the graphics layer.
Return value: none
Input Parameters:
<Renderer> renderer Required The renderer used for the graphic.

Events Detail

onClick(event)

Fires when a graphic has been clicked.
Arguments:
<Object> event The returned object contains screenPoint, mapPoint, and Graphic.

onDblClick(event)

Fires when a graphic has been double clicked. (As of v2.0)
Arguments:
<Object> event The returned object contains screenPoint, mapPoint, and graphic.

onGraphicAdd(graphic)

Fires when a graphic is added to the GraphicsLayer.
Arguments:
<Graphic> graphic The added graphic.
See also:
add  

onGraphicRemove(graphic)

Fires when a graphic is removed from the GraphicsLayer.
Arguments:
<Graphic> graphic The removed graphic.
See also:
remove  

onGraphicsClear()

Fires when all graphics in the GraphicsLayer are cleared.
See also:
clear  

onMouseDown(event)

Fires when a mouse button is pressed down and the mouse cursor is on a graphic.
Arguments:
<Object> event The returned object contains screenPoint, mapPoint, and Graphic.

onMouseDrag(event)

Fires while the mouse is being dragged until the mouse button is released.
Arguments:
<Object> event The result can be any JavaScript MouseEvent, or the x and y coordinates of screenPoint or mapPoint.

onMouseMove(event)

Fires as the mouse moves through a graphic on the GraphicsLayer.
Arguments:
<Object> event The returned object contains screenPoint, mapPoint, and Graphic.

onMouseOut(event)

Fires as the mouse exits a graphic on the GraphicsLayer.
Arguments:
<Object> event The returned object contains screenPoint, mapPoint, and Graphic.

onMouseOver(event)

Fires when the mouse first enters into a graphic on the GraphicsLayer.
Arguments:
<Object> event The returned object contains screenPoint, mapPoint, and Graphic.

onMouseUp(event)

Fires when a mouse button is released and the mouse cursor is on a graphic.
Arguments:
<Object> event The returned object contains screenPoint, mapPoint, and Graphic.