1
votes

Using the Arcgis Javascript API, I create a SimpleMarkerSymbol with the JSON constructor.

Documentation : https://developers.arcgis.com/javascript/jsapi/simplemarkersymbol.html#simplemarkersymbol3

The size and color of the symbol are obtained from GUI elements (color from a palette, size from an input text box).

My code is very simple :

var pointColor = ... //no point in writing this part of the code

var pointSize = symbologyTable.getElementsByClassName("inputSize")[0].value;    
console.log("pointSize = ", pointSize);

var pointSymbol = new esri.symbol.SimpleMarkerSymbol(
    {
        "color" : pointColor,
        "size" : pointSize,
        "style" : "esriSMSCircle"
    }
);
console.log("pointSymbol = ", pointSymbol);

The problem : the symbol size displayed with the second console.log is never consistent with the one obtained from the input text box. For exemple, if I create three points, changing the value in the input text box, the console.log looks like this :

pointSize = 15
pointSymbol = Object{ color=..., size=20, ...}

pointSize = 8
pointSymbol = Object{ color=..., size=10.66666666, ...}

pointSize = 4
pointSymbol = Object{ color=..., size=5.333333333, ...}

For debug purpose, I have tried writing a size value directly in the JSON while creating the pointSymbol variable (tried either "size" : 15 or "size" : "15"), but the size is always modified in the console.log.

What does work is the setSize(size) function : If I use pointSymbol.setSize("15") and then print the pointSymbol, its size is 15.

Any clue why the JSON size definition might not work?

Thank you very much for your help!


EDIT (1) : 2016-01-06 : The same problem occurs with the SimpleLineSymbol https://developers.arcgis.com/javascript/jsapi/simplelinesymbol.html


EDIT (2) : 2016-01-06 : The same problem occurs with the Font and TextSymbol https://developers.arcgis.com/javascript/jsapi/font.html https://developers.arcgis.com/javascript/jsapi/textsymbol.html

1

1 Answers

1
votes

This might come in handy

points to pixels chart

Via Reed Design

Because of this well hidden snippet from the Arcgis JSAPI documentation.

JSON object representing the SimpleMarkerSymbol. View the REST API Reference for Symbol Objects for details on creating a JSON symbol. 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.

You'll notice that your values match up quite nicely with the chart above. i.e. 15 points is approximately 20 pixels, 8 points is about 11 pixels etc.

If you want to specify in pixels then use this constructor for SimpleMarkerSymbol