Edit: I solved it using terraformer-wkt-parser
.
import wkt from 'terraformer-wkt-parser';
...
const geom: GeoJSON.Polygon = wkt.parse(geometryString) as GeoJSON.Polygon;
const coordinates = geom.coordinates.flat() as any;
const polygon = new Polygon({
rings: coordinates,
spatialReference: { wkid: 4326 },
});
—
Original post:
I have a geometry object in a database and I would like to render it on the front end using the ArcGIS JavaScript SDK.
var srid = 4326; // or any other spatial reference
var wkt = 'POLYGON (...)'; // or wkb equivalent
var rings = '' // <--- Conversion step I would like to make
const polygon = new Polygon({
rings: rings,
spatialReference: { wkid: srid },
});
Right now, I pass in well-known binary and well-known text. On the plus side, the code doesn’t error out. On the negative side, the polygon doesn’t appear on the map. Instead, I just get a blank map.