A Graphic is a vector representation of real world geographic phenomena. It can contain geometry, a symbol, and attributes. A Graphic is displayed in the GraphicsLayer.
To learn how to work with graphics, see the Intro to graphics tutorial.
let polyline = {
type: "polyline", // autocasts as new Polyline()
paths: [
[-111.30, 52.68],
[-98, 49.5],
[-93.94, 29.89]
]
};
let polylineSymbol = {
type: "simple-line", // autocasts as SimpleLineSymbol()
color: [226, 119, 40],
width: 4
};
let polylineAtt = {
Name: "Keystone Pipeline",
Owner: "TransCanada"
};
let polylineGraphic = new Graphic({
geometry: polyline,
symbol: polylineSymbol,
attributes: polylineAtt
});
view.graphics.add(polylineGraphic);
- See also
Constructors
-
new Graphic(properties)
-
Parameterproperties Objectoptional
See the properties for a list of all the properties that may be passed into the constructor.
Property Overview
Name | Type | Summary | Class |
---|---|---|---|
Object | The aggregateGeometries contains spatial aggregation geometries when statistics query is executed with | Graphic | |
Object | Name-value pairs of fields and field values associated with the graphic. more details | Graphic | |
String | The name of the class. more details | Accessor | |
Geometry | The geometry that defines the graphic's location. more details | Graphic | |
Boolean | Indicates whether the graphic refers to an aggregate, or cluster graphic. more details | Graphic | |
Layer | If applicable, references the layer in which the graphic is stored. more details | Graphic | |
PopupTemplate | The template for displaying content in a Popup when the graphic is selected. more details | Graphic | |
Symbol | The Symbol for the graphic. more details | Graphic | |
Boolean | Indicates the visibility of the graphic. more details | Graphic |
Property Details
-
aggregateGeometries ObjectSince: ArcGIS Maps SDK for JavaScript 4.23
-
The aggregateGeometries contains spatial aggregation geometries when statistics query is executed with
envelope-aggregate
,centroid-aggregate
and/orconvex-hull-aggregate
statistics type. Each property on aggregateGeometries is populated with statistics field containing the aggregate geometry matching the aggregate statistics type.- See also
Example// average of age fields by regions const ageStatsByRegion = new StatisticDefinition({ onStatisticField: field, outStatisticFieldName: "avgAge", statisticType: "avg" }); // extent encompassing all features by region const aggregatedExtent = new StatisticDefinition({ statisticType: "envelope-aggregate", outStatisticFieldName: "aggregateExtent", }); // group the statistics by Region field // get avg age by Regions and extent of each region const query = layer.createQuery(); query.groupByFieldsForStatistics = ["Region"]; query.outStatistics = [consumeStatsByRegion, aggregatedExtent]; layer.queryFeatures(query).then((results) => { results.features.forEach((feature) => { if (feature.attributes.Region === "Midwest") { view.goTo(feature.aggregateGeometries.aggregateExtent); } }); });
-
attributes Object
-
Name-value pairs of fields and field values associated with the graphic.
Examplelet graphic = new Graphic(); graphic.attributes = { "name": "Spruce", "family": "Pinaceae", "count": 126 };
-
Since: ArcGIS Maps SDK for JavaScript 4.7
-
The name of the class. The declared class name is formatted as
esri.folder.className
.
-
The geometry that defines the graphic's location.
Z-values defined in a geographic or metric coordinate system are expressed in meters. However, in local scenes that use a projected coordinate system, vertical units are assumed to be the same as the horizontal units specified by the service.
Example// First create a point geometry let point = { type: "point", // autocasts as new Point() longitude: -71.2643, latitude: 42.0909 }; // Create a symbol for drawing the point let markerSymbol = { type: "simple-marker", // autocasts as new SimpleMarkerSymbol() color: [226, 119, 40] }; // Create a graphic and add the geometry and symbol to it let pointGraphic = new Graphic({ geometry: point, symbol: markerSymbol });
-
isAggregate BooleanreadonlySince: ArcGIS Maps SDK for JavaScript 4.18
-
Indicates whether the graphic refers to an aggregate, or cluster graphic. Aggregate graphics represent clusters of features. If a graphic is an aggregate, you can use its Object ID to query the features comprising the cluster.
- See also
-
layer Layer
-
If applicable, references the layer in which the graphic is stored.
-
popupTemplate PopupTemplateautocast
-
The template for displaying content in a Popup when the graphic is selected. The PopupTemplate may be used to access a graphic's attributes and display their values in the view's default popup. See the documentation for PopupTemplate for details on how to display attribute values in the popup.
As of 4.8 to get the actual
popupTemplate
of the graphic, see the getEffectivePopupTemplate() method that either returns this value or thepopupTemplate
of the graphic's layer.- See also
Example// The following snippet shows how to set a popupTemplate // on the returned results (features) from identify idResult.feature.popupTemplate = { title: "{NAME}", content: [{ // Pass in the fields to display type: "fields", fieldInfos: [{ fieldName: "NAME", label: "Name" }, { fieldName: "REGION", label: "Region" }] }] };
-
The Symbol for the graphic. Choosing a symbol for a graphic depends on the View type (SceneView or MapView), and the geometry type of the graphic.
Each graphic may have its own symbol specified when the parent layer is a GraphicsLayer. For a FeatureLayer the symbol of each graphic should not be set by the developer since the graphics' rendering properties are determined by the layer's renderer.
To change a graphic's symbol in the GraphicsLayer and in the view.graphics at runtime, one of the following can be done:
- Clone the symbol and change its properties.
- Assign a new symbol to the graphic.
Exampleview.on("click", function(event){ let graphic = new Graphic({ geometry: event.mapPoint, symbol: { type: "simple-marker", // autocasts as new SimpleMarkerSymbol() color: "blue", size: 8, outline: { // autocasts as new SimpleLineSymbol() width: 0.5, color: "darkblue" } } }); });
-
visible Boolean
-
Indicates the visibility of the graphic.
- Default Value:true
Method Overview
Name | Return Type | Summary | Class |
---|---|---|---|
Adds one or more handles which are to be tied to the lifecycle of the object. more details | Accessor | ||
this | Creates a deep clone of this object. more details | Graphic | |
* | Creates a new instance of this class and initializes it with values from a JSON object generated from an ArcGIS product. more details | Graphic | |
* | Returns the value of the specified attribute. more details | Graphic | |
PopupTemplate | Returns the popup template applicable for the graphic. more details | Graphic | |
Number | Returns the Object ID of the feature associated with the graphic, if it exists. more details | Graphic | |
Boolean | Returns true if a named group of handles exist. more details | Accessor | |
Removes a group of handles owned by the object. more details | Accessor | ||
Sets a new value to the specified attribute. more details | Graphic | ||
Object | Converts an instance of this class to its ArcGIS portal JSON representation. more details | Graphic |
Method Details
-
addHandles(handleOrHandles, groupKey)inheritedSince: ArcGIS Maps SDK for JavaScript 4.25
-
Adds one or more handles which are to be tied to the lifecycle of the object. The handles will be removed when the object is destroyed.
// Manually manage handles const handle = reactiveUtils.when( () => !view.updating, () => { wkidSelect.disabled = false; }, { once: true } ); this.addHandles(handle); // Destroy the object this.destroy();
ParametershandleOrHandles WatchHandle|WatchHandle[]Handles marked for removal once the object is destroyed.
groupKey *optionalKey identifying the group to which the handles should be added. All the handles in the group can later be removed with Accessor.removeHandles(). If no key is provided the handles are added to a default group.
-
clone(){this}
-
Creates a deep clone of this object. Any properties that store values by reference will be assigned copies of the referenced values on the cloned instance.
ReturnsType Description this A deep clone of the class instance that invoked this method.
-
fromJSON(json){*}static
-
Creates a new instance of this class and initializes it with values from a JSON object generated from an ArcGIS product. The object passed into the input
json
parameter often comes from a response to a query operation in the REST API or a toJSON() method from another ArcGIS product. See the Using fromJSON() topic in the Guide for details and examples of when and how to use this function.Parameterjson ObjectA JSON representation of the instance in the ArcGIS format. See the ArcGIS REST API documentation for examples of the structure of various input JSON objects.
ReturnsType Description * Returns a new instance of this class.
-
getAttribute(name){*}
-
Returns the value of the specified attribute.
Parametername StringThe name of the attribute.
ReturnsType Description * Returns the value of the attribute specified by name
.
-
getEffectivePopupTemplate(defaultPopupTemplateEnabled){PopupTemplate}Since: ArcGIS Maps SDK for JavaScript 4.8
-
Returns the popup template applicable for the graphic. It's either the value of popupTemplate or the
popupTemplate
from the graphic's layer.ParameterdefaultPopupTemplateEnabled BooleanoptionalDefault Value: falseWhether support for default popup templates is enabled. When true, a default popup template may be created automatically if neither the graphic nor its layer have a popup template defined.
ReturnsType Description PopupTemplate Returns the popup template of the graphic.
-
getObjectId(){Number}
-
Returns the Object ID of the feature associated with the graphic, if it exists.
ReturnsType Description Number The ObjectID of the feature associated with the graphic.
-
Since: ArcGIS Maps SDK for JavaScript 4.25
-
Returns true if a named group of handles exist.
ParametergroupKey *optionalA group key.
ReturnsType Description Boolean Returns true
if a named group of handles exist.Example// Remove a named group of handles if they exist. if (obj.hasHandles("watch-view-updates")) { obj.removeHandles("watch-view-updates"); }
-
removeHandles(groupKey)inheritedSince: ArcGIS Maps SDK for JavaScript 4.25
-
Removes a group of handles owned by the object.
ParametergroupKey *optionalA group key or an array or collection of group keys to remove.
Exampleobj.removeHandles(); // removes handles from default group obj.removeHandles("handle-group"); obj.removeHandles("other-handle-group");
-
setAttribute(name, newValue)
-
Sets a new value to the specified attribute.
Parametersname StringThe name of the attribute to set.
newValue *The new value to set on the named attribute.
-
toJSON(){Object}
-
Converts an instance of this class to its ArcGIS portal JSON representation. See the Using fromJSON() guide topic for more information.
ReturnsType Description Object The ArcGIS portal JSON representation of an instance of this class.