Select to view content in your preferred language

api 4.x geometry fromJson

764
1
05-28-2018 03:47 AM
HectorSanchez3
New Contributor

Hi, there.

I'm having a problem representing a polygon with a different system spatial reference than the view.

I have a polygon in ESRI JSON format and when I try to paint it on the map I can't get it to appear, I do so:

let laSimbologia = ...;

let migeom = Polygon.fromJSON(esriJSON);

let elGrafico = new Graphic({
geometry: migeom,
symbol: laSimbologia
});
view.graphics.add(elGrafico);


When debugging the polygon looks well created and the spatialReference is the same as the one the ESRI JSON had, the execution ends correctly but does not paint the polygon.

Do I have to convert it to the CRS of the view beforehand? If so, what is fromJSON for?

Thank you very much.

Greetings, Hector.

0 Kudos
1 Reply
RobertScheitlin__GISP
MVP Emeritus

Hector,

Do I have to convert it to the CRS of the view beforehand? If so, what is fromJSON for?

Yes. What it is for is exactly what the method suggests you are creating a Polygon class object directly from a JSON string instead of using the standard constructor method and having to parse the string yourself. The fromJSON does not handle re-projection for you.

0 Kudos