Hide Table of Contents
esri/dijit/util
esri/layer/pixelFilters
esri/process
esri/support
esri/workers
Object: esri/symbols/jsonUtils

require(["esri/symbols/jsonUtils"], function(symbolJsonUtils) { /* code goes here */ });

Description

(Added at v3.9)
Utility methods for working with symbols.

When coding legacy (non-AMD) style, there is no need to require the module. All methods and properties are available in the namespace. For example, esri.symbol.fromJson().

Samples

Search for samples that use this class.

Methods

NameReturn typeSummary
fromJson(json)SymbolConverts input json into a symbol, returns null if the input json represents an unknown or unsupported symbol type.
getShapeDescriptors(symbol)ObjectReturns the shape description properties for the given symbol as defined by the Dojo GFX API.
Method Details

fromJson(json)

Converts input json into a symbol, returns null if the input json represents an unknown or unsupported symbol type. The input json argument typically comes from one of the following:
  1. Calling the symbol.toJson() method
    var duplicate = esri.symbol.fromJson(simpleMarkerSymbol.toJson());
  2. Symbol object returned from REST.

When you create a MarkerSymbol, SimpleMarkerSymbol or PictureMarkerSymbol from a JSON object, you may specify a property angle to rotate the symbol. Be aware that the angle in the JSON is different from MarkerSymbol.angle. The angle in the JSON follows the traditional ArcGIS specification and is rotated counter-clockwise, whereas the angle in the symbol is rotated clockwise.

For example, the following code with angle=-30 in the JSON will create a symbol rotated -30 degrees counter-clockwise; that is, 30 degrees clockwise, which symbol.angle=30 would also produce.

var symbol = jsonUtils.fromJson({
  "angle": -30,
  "xoffset": 0,
  "yoffset": 0,
  "type": "esriPMS",
  "url": "http://www.esri.com/careers/profiles/~/media/Images/Content/graphics/icons/socialmedia/pinterest1.png",
  "width": 18,
  "height": 18
});
Return type: Symbol
Parameters:
<Object> json Required The input JSON.

getShapeDescriptors(symbol)

Returns the shape description properties for the given symbol as defined by the Dojo GFX API. Using this method, you can apply ArcGIS symbology to shapes or graphics not created within a GraphicsLayer.

Properties of the returned object include:

<Object> fill Defines how to fill a shape. The properties of this object are described in the dojo documentation.
<Object> stroke An object that defines how to draw the outline of a shape. The properties of this object are described in the dojo documentation.
<Object> defaultShape An object that defines a default geometry for the given symbol. It will always have a property named "type" that uniquely identifies the shape. The type property can have one of the following values based on the symbol: circle, path, or image. It is important to note that the geometry defined by this object will always be centered at the top-left corner (x = 0, y = 0) of the surface it is attached to.

You can quickly create a GFX shape with ArcGIS symbology with the help of these descriptors using the createShape method of the surface. Alternatively, you can choose to change the shape description before creating the shape.
Return type: Object
Parameters:
<Symbol> symbol Required The input symbol.
Sample:

[JavaScript]

require([
  "dojox/gfx", "dojo/dom", "esri/symbols/jsonUtils", ... 
], function(gfx, dom, jsonUtils, ... ) {
  var mySurface = gfx.createSurface(dom.byId("surface"), 50, 50);
  var descriptors = jsonUtils.getShapeDescriptors(symbol);
  var shape = mySurface.createShape(descriptors.defaultShape)
                .setFill(descriptors.fill)
                .setStroke(descriptors.stroke);
  shape.applyTransform({ dx: 25, dy: 25 }); // center the shape at coordinates (25, 25)
  ...
});

[HTML]

<div id="surface"></div>
Show Modal