Select to view content in your preferred language

Creating PictureFillSymbol using JSON - use pixels instead of points

1171
3
10-06-2014 01:30 PM
VygintasCesnauskas
New Contributor III

I've noticed that when PictureFillSymbol is created from a JSON object, width and height are defined in points. This is an issue because when I read PictureFillSymbol width and height properties after it has been created, they both return pixels.

Here is an excerpt from the API documentation (http://https://developers.arcgis.com/javascript/jsapi/picturefillsymbol-amd.html) :

Note that when specifying symbol width and height using JSON the values should be entered in points, the JavaScript API then converts the point values to pixels.

Sample code:

var symbol =  new PictureMarkerSymbol({
    "url":"graphics/redArrow2.png",
    "height":20,
    "width":20,
    "type":"esriPMS"
  });

Is there any way to avoid this conversion? Alternatively, is there functionality convert pixels back to points?

0 Kudos
3 Replies
RobertScheitlin__GISP
MVP Emeritus

Vygintas,

   Assuming the screen DPI is 96 this is the simple conversion:

To convert point to pixel:

pixels = point * 96 / 72

0 Kudos
VygintasCesnauskas
New Contributor III

Hi Robert,

Unfortunately we can't assume that user is running 96 DPI.

For now, as a workaround, I took out width and height attributes from PictureMarkerSymbol JSON and instead set them after the object is created using methods setWidth() and setHeight(). Those methods use pixels, so no conversion is necessary.

0 Kudos
RobertScheitlin__GISP
MVP Emeritus

Vygintas,

   True the assumption was just to demonstrate the math for the calculation. There is a lot of results out there on Google for using JS to obtain the devices DPI.

0 Kudos